xenapi: handle InstanceNotFound in detach_interface()
CI tests frequently teardown by rolling back interface attachments and then deleting the server, both of which are asynchronous. If we're trying to detach an interface on a guest that is gone, we don't need to log a traceback exception in the logs, just let the InstanceNotFound raise up to the ComputeManager which will handle the error and log it appropriately. Change-Id: I9428be0e6e5b640fdda00410817925001361fd2c Closes-Bug: #1759979
This commit is contained in:
parent
5cba8063c2
commit
5a42701f89
@ -2175,8 +2175,10 @@ class AttachInterfaceTestCase(VMOpsTestBase):
|
||||
self.vmops.vif_driver.unplug.assert_called_once_with(
|
||||
self.fake_instance, self.fake_vif, 'fake_vm_ref')
|
||||
|
||||
@mock.patch('nova.virt.xenapi.vmops.LOG.exception')
|
||||
@mock.patch.object(vmops.VMOps, '_get_vm_opaque_ref')
|
||||
def test_detach_interface_exception(self, mock_get_vm_opaque_ref):
|
||||
def test_detach_interface_exception(self, mock_get_vm_opaque_ref,
|
||||
mock_log_exception):
|
||||
mock_get_vm_opaque_ref.return_value = 'fake_vm_ref'
|
||||
self.vmops.vif_driver.unplug.side_effect =\
|
||||
exception.VirtualInterfaceUnplugException('Failed to unplug VIF')
|
||||
@ -2184,3 +2186,15 @@ class AttachInterfaceTestCase(VMOpsTestBase):
|
||||
self.assertRaises(exception.VirtualInterfaceUnplugException,
|
||||
self.vmops.detach_interface,
|
||||
self.fake_instance, self.fake_vif)
|
||||
mock_log_exception.assert_called()
|
||||
|
||||
@mock.patch('nova.virt.xenapi.vmops.LOG.exception',
|
||||
new_callable=mock.NonCallableMock)
|
||||
@mock.patch.object(vmops.VMOps, '_get_vm_opaque_ref',
|
||||
side_effect=exception.InstanceNotFound(
|
||||
instance_id='fake_vm_ref'))
|
||||
def test_detach_interface_instance_not_found(
|
||||
self, mock_get_vm_opaque_ref, mock_log_exception):
|
||||
self.assertRaises(exception.InstanceNotFound,
|
||||
self.vmops.detach_interface,
|
||||
self.fake_instance, self.fake_vif)
|
||||
|
@ -2729,6 +2729,10 @@ class VMOps(object):
|
||||
try:
|
||||
vm_ref = self._get_vm_opaque_ref(instance)
|
||||
self.vif_driver.unplug(instance, vif, vm_ref)
|
||||
except exception.InstanceNotFound:
|
||||
# Let this go up to the compute manager which will log a message
|
||||
# for it.
|
||||
raise
|
||||
except exception.NovaException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception(_('detach network interface %s failed.'),
|
||||
|
Loading…
Reference in New Issue
Block a user