Allow libvirt cleanup completion when serial ports already released

Libvirt driver cleanup changed with try-except to be tolerant of
InstanceNotFound exceptions when attempting to fetch missing ports
(possibly removed on a previous cleanup).

Change-Id: I804c8821e797596f60a4ec911fdd423d3f7ad653
Closes-Bug: 1450594
(cherry picked from commit 2e72e8f374)
This commit is contained in:
David Bingham 2015-05-04 17:13:06 -07:00 committed by Matt Riedemann
parent b8c4f1bce3
commit 124b501b1f
2 changed files with 36 additions and 1 deletions

View File

@ -10777,6 +10777,37 @@ Active: 8381604 kB
instance, network_info=network_info)
block_device_info_get_mapping.assert_called_once_with(bdm_info)
@mock.patch('nova.virt.driver.block_device_info_get_mapping')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
'_get_serial_ports_from_instance')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._undefine_domain')
def test_cleanup_serial_console_domain_gone(
self, undefine, get_ports, block_device_info_get_mapping):
self.flags(enabled="True", group='serial_console')
instance = {'name': 'i1'}
network_info = {}
bdm_info = {}
firewall_driver = mock.MagicMock()
block_device_info_get_mapping.return_value = ()
# Ensure _get_serial_ports_from_instance raises same exception
# that would have occurred if domain was gone.
get_ports.side_effect = exception.InstanceNotFound("domain undefined")
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI())
drvr.firewall_driver = firewall_driver
drvr.cleanup(
'ctx', instance, network_info,
block_device_info=bdm_info,
destroy_disks=False, destroy_vifs=False)
get_ports.assert_called_once_with(instance)
undefine.assert_called_once_with(instance)
firewall_driver.unfilter_instance.assert_called_once_with(
instance, network_info=network_info)
block_device_info_get_mapping.assert_called_once_with(bdm_info)
def test_swap_volume(self):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI())

View File

@ -874,7 +874,11 @@ class LibvirtDriver(driver.ComputeDriver):
instance.save()
if CONF.serial_console.enabled:
serials = self._get_serial_ports_from_instance(instance)
try:
serials = self._get_serial_ports_from_instance(instance)
except exception.InstanceNotFound:
# Serial ports already gone. Nothing to release.
serials = ()
for hostname, port in serials:
serial_console.release_port(host=hostname, port=port)