Merge "libvirt: Limit destroying disks during cleanup to spawn"
This commit is contained in:
commit
417dac5036
|
@ -10259,7 +10259,8 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
def fake_create_domain_and_network(
|
||||
context, xml, instance, network_info, disk_info,
|
||||
block_device_info=None, power_on=True, reboot=False,
|
||||
vifs_already_plugged=False, post_xml_callback=None):
|
||||
vifs_already_plugged=False, post_xml_callback=None,
|
||||
destroy_disks_on_failure=False):
|
||||
# The config disk should be created by this callback, so we need
|
||||
# to execute it.
|
||||
post_xml_callback()
|
||||
|
@ -14448,14 +14449,22 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
drvr._create_domain_and_network,
|
||||
self.context, 'xml', instance, [], None)
|
||||
mock_cleanup.assert_called_once_with(self.context, instance,
|
||||
[], None, None)
|
||||
[], None, None, False)
|
||||
# destroy_disks_on_failure=True, used only by spawn()
|
||||
mock_cleanup.reset_mock()
|
||||
self.assertRaises(test.TestingException,
|
||||
drvr._create_domain_and_network,
|
||||
self.context, 'xml', instance, [], None,
|
||||
destroy_disks_on_failure=True)
|
||||
mock_cleanup.assert_called_once_with(self.context, instance,
|
||||
[], None, None, True)
|
||||
|
||||
the_test()
|
||||
|
||||
def test_cleanup_failed_start_no_guest(self):
|
||||
drvr = libvirt_driver.LibvirtDriver(mock.MagicMock(), False)
|
||||
with mock.patch.object(drvr, 'cleanup') as mock_cleanup:
|
||||
drvr._cleanup_failed_start(None, None, None, None, None)
|
||||
drvr._cleanup_failed_start(None, None, None, None, None, False)
|
||||
self.assertTrue(mock_cleanup.called)
|
||||
|
||||
def test_cleanup_failed_start_inactive_guest(self):
|
||||
|
@ -14463,7 +14472,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
guest = mock.MagicMock()
|
||||
guest.is_active.return_value = False
|
||||
with mock.patch.object(drvr, 'cleanup') as mock_cleanup:
|
||||
drvr._cleanup_failed_start(None, None, None, None, guest)
|
||||
drvr._cleanup_failed_start(None, None, None, None, guest, False)
|
||||
self.assertTrue(mock_cleanup.called)
|
||||
self.assertFalse(guest.poweroff.called)
|
||||
|
||||
|
@ -14472,7 +14481,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
guest = mock.MagicMock()
|
||||
guest.is_active.return_value = True
|
||||
with mock.patch.object(drvr, 'cleanup') as mock_cleanup:
|
||||
drvr._cleanup_failed_start(None, None, None, None, guest)
|
||||
drvr._cleanup_failed_start(None, None, None, None, guest, False)
|
||||
self.assertTrue(mock_cleanup.called)
|
||||
self.assertTrue(guest.poweroff.called)
|
||||
|
||||
|
@ -14484,10 +14493,23 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
with mock.patch.object(drvr, 'cleanup') as mock_cleanup:
|
||||
self.assertRaises(test.TestingException,
|
||||
drvr._cleanup_failed_start,
|
||||
None, None, None, None, guest)
|
||||
None, None, None, None, guest, False)
|
||||
self.assertTrue(mock_cleanup.called)
|
||||
self.assertTrue(guest.poweroff.called)
|
||||
|
||||
def test_cleanup_failed_start_failed_poweroff_destroy_disks(self):
|
||||
drvr = libvirt_driver.LibvirtDriver(mock.MagicMock(), False)
|
||||
guest = mock.MagicMock()
|
||||
guest.is_active.return_value = True
|
||||
guest.poweroff.side_effect = test.TestingException
|
||||
with mock.patch.object(drvr, 'cleanup') as mock_cleanup:
|
||||
self.assertRaises(test.TestingException,
|
||||
drvr._cleanup_failed_start,
|
||||
None, None, None, None, guest, True)
|
||||
mock_cleanup.called_once_with(None, None, network_info=None,
|
||||
block_device_info=None, destroy_disks=True)
|
||||
self.assertTrue(guest.poweroff.called)
|
||||
|
||||
@mock.patch('nova.volume.encryptors.get_encryption_metadata')
|
||||
@mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm')
|
||||
def test_create_with_bdm(self, get_info_from_bdm, get_encryption_metadata):
|
||||
|
|
|
@ -2684,7 +2684,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
self._create_domain_and_network(
|
||||
context, xml, instance, network_info, disk_info,
|
||||
block_device_info=block_device_info,
|
||||
post_xml_callback=gen_confdrive)
|
||||
post_xml_callback=gen_confdrive,
|
||||
destroy_disks_on_failure=True)
|
||||
LOG.debug("Instance is running", instance=instance)
|
||||
|
||||
def _wait_for_boot():
|
||||
|
@ -5010,19 +5011,21 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
for vif in network_info if vif.get('active', True) is False]
|
||||
|
||||
def _cleanup_failed_start(self, context, instance, network_info,
|
||||
block_device_info, guest):
|
||||
block_device_info, guest, destroy_disks):
|
||||
try:
|
||||
if guest and guest.is_active():
|
||||
guest.poweroff()
|
||||
finally:
|
||||
self.cleanup(context, instance, network_info=network_info,
|
||||
block_device_info=block_device_info)
|
||||
block_device_info=block_device_info,
|
||||
destroy_disks=destroy_disks)
|
||||
|
||||
def _create_domain_and_network(self, context, xml, instance, network_info,
|
||||
disk_info, block_device_info=None,
|
||||
power_on=True, reboot=False,
|
||||
vifs_already_plugged=False,
|
||||
post_xml_callback=None):
|
||||
post_xml_callback=None,
|
||||
destroy_disks_on_failure=False):
|
||||
|
||||
"""Do required network setup and create domain."""
|
||||
block_device_mapping = driver.block_device_info_get_mapping(
|
||||
|
@ -5074,7 +5077,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
# bail here
|
||||
with excutils.save_and_reraise_exception():
|
||||
self._cleanup_failed_start(context, instance, network_info,
|
||||
block_device_info, guest)
|
||||
block_device_info, guest,
|
||||
destroy_disks_on_failure)
|
||||
except eventlet.timeout.Timeout:
|
||||
# We never heard from Neutron
|
||||
LOG.warning(_LW('Timeout waiting for vif plugging callback for '
|
||||
|
@ -5082,7 +5086,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
instance=instance)
|
||||
if CONF.vif_plugging_is_fatal:
|
||||
self._cleanup_failed_start(context, instance, network_info,
|
||||
block_device_info, guest)
|
||||
block_device_info, guest,
|
||||
destroy_disks_on_failure)
|
||||
raise exception.VirtualInterfaceCreateException()
|
||||
except Exception:
|
||||
# Any other error, be sure to clean up
|
||||
|
@ -5090,7 +5095,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
instance=instance)
|
||||
with excutils.save_and_reraise_exception():
|
||||
self._cleanup_failed_start(context, instance, network_info,
|
||||
block_device_info, guest)
|
||||
block_device_info, guest,
|
||||
destroy_disks_on_failure)
|
||||
|
||||
# Resume only if domain has been paused
|
||||
if pause:
|
||||
|
|
Loading…
Reference in New Issue