Skip to content

Commit 07295b0

Browse files
committed
[libvirt]Support hw_vif_model = igb
Makes igb vif model supported for hosts with libvirt 9.3.0 and qemu 8.0.0 or higher. Implements: blueprint igb-vif-model Depends-On: https://review.opendev.org/c/openstack/os-traits/+/928582 (merged, released as 3.2.0) Change-Id: I6a1d8058c640e5dc015889610c4ae864ed9a5ccb
1 parent 638efe3 commit 07295b0

File tree

6 files changed

+140
-2
lines changed

6 files changed

+140
-2
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
import datetime
16+
17+
from oslo_config import cfg
18+
from oslo_utils.fixture import uuidsentinel as uuids
19+
20+
import nova
21+
from nova.tests.functional.libvirt import base
22+
23+
CONF = cfg.CONF
24+
25+
26+
class LibvirtVifModelTest(base.ServersTestBase):
27+
ADMIN_API = True
28+
29+
def setUp(self):
30+
CONF.set_default("image_metadata_prefilter", True, group='scheduler')
31+
super().setUp()
32+
33+
self.glance.create(
34+
None,
35+
{
36+
'id': uuids.image_vif_model_igb,
37+
'name': 'image-with-igb',
38+
'created_at': datetime.datetime(2011, 1, 1, 1, 2, 3),
39+
'updated_at': datetime.datetime(2011, 1, 1, 1, 2, 3),
40+
'deleted_at': None,
41+
'deleted': False,
42+
'status': 'active',
43+
'is_public': False,
44+
'container_format': 'bare',
45+
'disk_format': 'qcow2',
46+
'size': '74185822',
47+
'min_ram': 0,
48+
'min_disk': 0,
49+
'protected': False,
50+
'visibility': 'public',
51+
'tags': [],
52+
'properties': {
53+
'hw_vif_model': 'igb',
54+
},
55+
}
56+
)
57+
58+
def test_boot_with_vif_model_igb(self):
59+
orig_create = nova.virt.libvirt.guest.Guest.create
60+
self.xml = ""
61+
62+
def fake_create(cls, xml, host):
63+
self.xml = xml
64+
return orig_create(xml, host)
65+
66+
self.stub_out('nova.virt.libvirt.guest.Guest.create', fake_create)
67+
68+
self.start_compute(
69+
hostname='compute1',
70+
libvirt_version=9003000,
71+
qemu_version=8000000,
72+
)
73+
74+
self._create_server(image_uuid=uuids.image_vif_model_igb)
75+
self.assertIn('<model type="igb"/>', self.xml)
76+
77+
def _test_boot_with_vif_model_igb_old_hypervisor(
78+
self, libvirt_version, qemu_version
79+
):
80+
self.start_compute(
81+
hostname='compute1',
82+
libvirt_version=libvirt_version,
83+
qemu_version=qemu_version,
84+
)
85+
86+
server = self._create_server(
87+
image_uuid=uuids.image_vif_model_igb, expected_state='ERROR')
88+
self.assertEqual(
89+
"No valid host was found. ", server['fault']['message'])
90+
91+
def test_boot_with_vif_model_igb_old_qemu(self):
92+
self._test_boot_with_vif_model_igb_old_hypervisor(
93+
libvirt_version=9003000, qemu_version=7000000)
94+
95+
def test_boot_with_vif_model_igb_old_libvirt(self):
96+
self._test_boot_with_vif_model_igb_old_hypervisor(
97+
libvirt_version=9002000, qemu_version=8000000)

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28186,7 +28186,9 @@ def test_storage_bus_traits__non_qemu_kvm(self):
2818628186
bus_from_trait = trait.rsplit('_', 1)[1].lower()
2818728187
self.assertEqual(bus_from_trait in buses, bus_traits[trait])
2818828188

28189-
def test_vif_model_traits(self):
28189+
@mock.patch.object(
28190+
host.Host, 'has_min_version', return_value=True)
28191+
def test_vif_model_traits(self, mock_has_min_version):
2819028192
"""Test getting vif model traits per virt type."""
2819128193
for virt_type, models in libvirt_vif.SUPPORTED_VIF_MODELS.items():
2819228194
self.flags(virt_type=virt_type, group='libvirt')
@@ -28200,6 +28202,24 @@ def test_vif_model_traits(self):
2820028202
vif_models.pop(trait)
2820128203
self.assertTrue(all(not model for model in vif_models.values()))
2820228204

28205+
mock_has_min_version.assert_called_with((9, 3, 0), (8, 0, 0))
28206+
28207+
@mock.patch.object(
28208+
host.Host, 'has_min_version', return_value=False)
28209+
def test_vif_model_traits_old_version_no_igb_support(
28210+
self, mock_has_min_version
28211+
):
28212+
"""Test getting vif model traits per virt type from old system not
28213+
supporting igb.
28214+
"""
28215+
for virt_type in ('qemu', 'kvm'):
28216+
models = libvirt_vif.SUPPORTED_VIF_MODELS[virt_type]
28217+
self.assertIn(network_model.VIF_MODEL_IGB, models)
28218+
vif_models = self.drvr._get_vif_model_traits()
28219+
self.assertFalse(vif_models['COMPUTE_NET_VIF_MODEL_IGB'])
28220+
28221+
mock_has_min_version.assert_called_with((9, 3, 0), (8, 0, 0))
28222+
2820328223
def test_video_model_traits(self):
2820428224
"""Test getting video model traits per virt type."""
2820528225
# NOTE(sean-k-mooney): we do not have a static tables of which video

nova/virt/libvirt/driver.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ def repr_method(self):
260260
# stateless firmware support
261261
MIN_LIBVIRT_STATELESS_FIRMWARE = (8, 6, 0)
262262

263+
# Minimum versions supporting igb hw_vif_model
264+
MIN_IGB_LIBVIRT_VERSION = (9, 3, 0)
265+
MIN_IGB_QEMU_VERSION = (8, 0, 0)
266+
263267
REGISTER_IMAGE_PROPERTY_DEFAULTS = [
264268
'hw_machine_type',
265269
'hw_cdrom_bus',
@@ -12990,6 +12994,15 @@ def _get_vif_model_traits(self) -> ty.Dict[str, bool]:
1299012994
supported_models = libvirt_vif.SUPPORTED_VIF_MODELS.get(
1299112995
CONF.libvirt.virt_type, []
1299212996
)
12997+
12998+
# remove version dependent vif models if we are on older libvirt/qemu
12999+
igb_supported = self._host.has_min_version(
13000+
MIN_IGB_LIBVIRT_VERSION, MIN_IGB_QEMU_VERSION)
13001+
if not igb_supported:
13002+
supported_models = [
13003+
model for model in supported_models
13004+
if model != network_model.VIF_MODEL_IGB]
13005+
1299313006
# construct the corresponding standard trait from the VIF model name
1299413007
return {
1299513008
f'COMPUTE_NET_VIF_MODEL_{model.replace("-", "_").upper()}': model

nova/virt/libvirt/vif.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
network_model.VIF_MODEL_LAN9118,
6262
network_model.VIF_MODEL_SPAPR_VLAN,
6363
network_model.VIF_MODEL_VMXNET3,
64+
network_model.VIF_MODEL_IGB,
6465
],
6566
'kvm': [
6667
network_model.VIF_MODEL_VIRTIO,
@@ -71,6 +72,7 @@
7172
network_model.VIF_MODEL_E1000E,
7273
network_model.VIF_MODEL_SPAPR_VLAN,
7374
network_model.VIF_MODEL_VMXNET3,
75+
network_model.VIF_MODEL_IGB,
7476
],
7577
'lxc': [],
7678
'parallels': [
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
The libvirt driver now supports hw_vif_model=igb image property
5+
if the hypervisor has libvirt version 9.3.0 and qemu version 8.0.0
6+
or higher.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ psutil>=3.2.2 # BSD
5252
oslo.versionedobjects>=1.35.0 # Apache-2.0
5353
os-brick>=6.0 # Apache-2.0
5454
os-resource-classes>=1.1.0 # Apache-2.0
55-
os-traits>=3.1.0 # Apache-2.0
55+
os-traits>=3.2.0 # Apache-2.0
5656
os-vif>=3.1.0 # Apache-2.0
5757
castellan>=0.16.0 # Apache-2.0
5858
microversion-parse>=0.2.1 # Apache-2.0

0 commit comments

Comments
 (0)