Skip to content

Commit 4a8faa7

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Only unplug vif after the device is detached from libvirt"
2 parents 8c12eae + 7e8a978 commit 4a8faa7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23596,11 +23596,12 @@ def _test_detach_interface(self, power_state, expected_flags,
2359623596
mock.patch.object(guest, 'get_interface_by_cfg',
2359723597
side_effect=get_interface_calls),
2359823598
mock.patch.object(domain, 'detachDeviceFlags'),
23599-
mock.patch('nova.virt.libvirt.driver.LOG.warning')
23599+
mock.patch('nova.virt.libvirt.driver.LOG.warning'),
23600+
mock.patch.object(self.drvr.vif_driver, 'unplug')
2360023601
) as (
2360123602
mock_get_guest, mock_get_config,
2360223603
mock_get_interface, mock_detach_device_flags,
23603-
mock_warning
23604+
mock_warning, mock_unplug
2360423605
):
2360523606
# run the detach method
2360623607
self.drvr.detach_interface(self.context, instance, network_info[0])
@@ -23621,6 +23622,8 @@ def _test_detach_interface(self, power_state, expected_flags,
2362123622
expected_cfg.to_xml(), flags=expected_flags)
2362223623
mock_warning.assert_not_called()
2362323624

23625+
mock_unplug.assert_called_once_with(instance, network_info[0])
23626+
2362423627
def test_detach_interface_with_running_instance(self):
2362523628
self._test_detach_interface(
2362623629
power_state.RUNNING,

nova/virt/libvirt/driver.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,6 @@ def detach_interface(self, context, instance, vif):
22772277
CONF.libvirt.virt_type)
22782278
interface = guest.get_interface_by_cfg(cfg)
22792279
try:
2280-
self.vif_driver.unplug(instance, vif)
22812280
# NOTE(mriedem): When deleting an instance and using Neutron,
22822281
# we can be racing against Neutron deleting the port and
22832282
# sending the vif-deleted event which then triggers a call to
@@ -2357,6 +2356,14 @@ def detach_interface(self, context, instance, vif):
23572356
LOG.warning('Detaching interface %(mac)s failed because '
23582357
'the device is no longer found on the guest.',
23592358
{'mac': mac}, instance=instance)
2359+
finally:
2360+
# NOTE(gibi): we need to unplug the vif _after_ the detach is done
2361+
# on the libvirt side as otherwise libvirt will still manage the
2362+
# device that our unplug code trying to reset. This can cause a
2363+
# race and leave the detached device configured. Also even if we
2364+
# are failed to detach due to race conditions the unplug is
2365+
# necessary for the same reason
2366+
self.vif_driver.unplug(instance, vif)
23602367

23612368
def _create_snapshot_metadata(self, image_meta, instance,
23622369
img_fmt, snp_name):

0 commit comments

Comments
 (0)