summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-03-30 14:37:14 +0000
committerGerrit Code Review <review@openstack.org>2016-03-30 14:37:15 +0000
commitac5a670fa0a3de3c9ade4b1bd29e3a2db9a05599 (patch)
tree84a0fd1438c056759febd83543de1b5955ce194b
parent5de98cb2de2eca3d061488c55f96e6f7c9bc56a8 (diff)
parenta9d55427b6e8d2472088e3d40a8a5151ce408283 (diff)
downloadnova-ac5a670fa0a3de3c9ade4b1bd29e3a2db9a05599.tar.gz
Merge "Fix detach SR-IOV when using LibvirtConfigGuestHostdevPCI" into stable/mitaka
-rw-r--r--nova/tests/unit/virt/libvirt/test_driver.py38
-rw-r--r--nova/virt/libvirt/driver.py13
2 files changed, 27 insertions, 24 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py
index 2857264170..0dc459190b 100644
--- a/nova/tests/unit/virt/libvirt/test_driver.py
+++ b/nova/tests/unit/virt/libvirt/test_driver.py
@@ -10357,15 +10357,11 @@ class LibvirtConnTestCase(test.NoDBTestCase):
@mock.patch.object(host.Host,
'has_min_version', return_value=True)
- @mock.patch.object(FakeVirtDomain, 'detachDeviceFlags')
- @mock.patch.object(utils, 'get_image_from_system_metadata',
- return_value=None)
- def test_detach_sriov_ports(self,
- mock_get_image_metadata,
- mock_detachDeviceFlags,
- mock_has_min_version):
+ def _test_detach_sriov_ports(self,
+ mock_has_min_version, vif_type):
instance = objects.Instance(**self.test_instance)
+ expeted_pci_slot = "0000:00:00.0"
network_info = _fake_network_info(self, 1)
network_info[0]['vnic_type'] = network_model.VNIC_TYPE_DIRECT
# some more adjustments for the fake network_info so that
@@ -10374,27 +10370,37 @@ class LibvirtConnTestCase(test.NoDBTestCase):
# and most importantly the pci_slot which is translated to
# cfg.source_dev, then to PciDevice.address and sent to
# _detach_pci_devices
- network_info[0]['profile'] = dict(pci_slot="0000:00:00.0")
- network_info[0]['type'] = "hw_veb"
+ network_info[0]['profile'] = dict(pci_slot=expeted_pci_slot)
+ network_info[0]['type'] = vif_type
network_info[0]['details'] = dict(vlan="2145")
instance.info_cache = objects.InstanceInfoCache(
network_info=network_info)
# fill the pci_devices of the instance so that
# pci_manager.get_instance_pci_devs will not return an empty list
# which will eventually fail the assertion for detachDeviceFlags
+ expected_pci_device_obj = (
+ objects.PciDevice(address=expeted_pci_slot, request_id=None))
instance.pci_devices = objects.PciDeviceList()
- instance.pci_devices.objects = [
- objects.PciDevice(address='0000:00:00.0', request_id=None)
- ]
+ instance.pci_devices.objects = [expected_pci_device_obj]
domain = FakeVirtDomain()
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
guest = libvirt_guest.Guest(domain)
- drvr._detach_sriov_ports(self.context, instance, guest)
- mock_get_image_metadata.assert_called_once_with(
- instance.system_metadata)
- self.assertTrue(mock_detachDeviceFlags.called)
+ with mock.patch.object(drvr, '_detach_pci_devices') as mock_detach_pci:
+ drvr._detach_sriov_ports(self.context, instance, guest)
+ mock_detach_pci.assert_called_once_with(
+ guest, [expected_pci_device_obj])
+
+ def test_detach_sriov_ports_interface_interface_hostdev(self):
+ # Note: test detach_sriov_ports method for vif with config
+ # LibvirtConfigGuestInterface
+ self._test_detach_sriov_ports(vif_type="hw_veb")
+
+ def test_detach_sriov_ports_interface_pci_hostdev(self):
+ # Note: test detach_sriov_ports method for vif with config
+ # LibvirtConfigGuestHostdevPCI
+ self._test_detach_sriov_ports(vif_type="ib_hostdev")
@mock.patch.object(host.Host, 'has_min_version', return_value=True)
@mock.patch.object(FakeVirtDomain, 'detachDeviceFlags')
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index f48184a26d..3dce6593f2 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -3413,16 +3413,13 @@ class LibvirtDriver(driver.ComputeDriver):
raise exception.PciDeviceDetachFailed(reason=reason,
dev=network_info)
- image_meta = objects.ImageMeta.from_instance(instance)
+ # In case of SR-IOV vif types we create pci request per SR-IOV port
+ # Therefore we can trust that pci_slot value in the vif is correct.
sriov_pci_addresses = [
- self.vif_driver.get_config(instance,
- vif,
- image_meta,
- instance.flavor,
- CONF.libvirt.virt_type,
- self._host).source_dev
+ vif['profile']['pci_slot']
for vif in network_info
- if vif['vnic_type'] in network_model.VNIC_TYPES_SRIOV
+ if vif['vnic_type'] in network_model.VNIC_TYPES_SRIOV and
+ vif['profile'].get('pci_slot') is not None
]
# use detach_pci_devices to avoid failure in case of