Merge "libvirt: Re-initialise volumes, encryptors, and vifs on hard reboot"

This commit is contained in:
Zuul 2017-12-07 16:52:37 +00:00 committed by Gerrit Code Review
commit 81544829d1
2 changed files with 16 additions and 16 deletions

View File

@ -12103,16 +12103,15 @@ class LibvirtConnTestCase(test.NoDBTestCase,
mock_hard_reboot.assert_called_once_with(self.context, mock_hard_reboot.assert_called_once_with(self.context,
instance, [], None) instance, [], None)
@mock.patch('nova.virt.libvirt.LibvirtDriver._undefine_domain')
@mock.patch('nova.virt.libvirt.LibvirtDriver.get_info') @mock.patch('nova.virt.libvirt.LibvirtDriver.get_info')
@mock.patch('nova.virt.libvirt.LibvirtDriver._create_domain_and_network') @mock.patch('nova.virt.libvirt.LibvirtDriver._create_domain_and_network')
@mock.patch('nova.virt.libvirt.LibvirtDriver._get_guest_xml') @mock.patch('nova.virt.libvirt.LibvirtDriver._get_guest_xml')
@mock.patch('nova.virt.libvirt.LibvirtDriver.' @mock.patch('nova.virt.libvirt.LibvirtDriver.'
'_get_instance_disk_info_from_config') '_get_instance_disk_info_from_config')
@mock.patch('nova.virt.libvirt.LibvirtDriver._destroy') @mock.patch('nova.virt.libvirt.LibvirtDriver.destroy')
def test_hard_reboot(self, mock_destroy, mock_get_disk_info, def test_hard_reboot(self, mock_destroy, mock_get_disk_info,
mock_get_guest_xml, mock_create_domain_and_network, mock_get_guest_xml, mock_create_domain_and_network,
mock_get_info, mock_undefine): mock_get_info):
self.context.auth_token = True # any non-None value will suffice self.context.auth_token = True # any non-None value will suffice
instance = objects.Instance(**self.test_instance) instance = objects.Instance(**self.test_instance)
network_info = _fake_network_info(self, 1) network_info = _fake_network_info(self, 1)
@ -12160,13 +12159,13 @@ class LibvirtConnTestCase(test.NoDBTestCase,
for name in ('disk', 'disk.local'): for name in ('disk', 'disk.local'):
self.assertTrue(disks[name].cache.called) self.assertTrue(disks[name].cache.called)
mock_destroy.assert_called_once_with(instance) mock_destroy.assert_called_once_with(self.context, instance,
mock_undefine.assert_called_once_with(instance) network_info, destroy_disks=False,
block_device_info=block_device_info)
mock_create_domain_and_network.assert_called_once_with(self.context, mock_create_domain_and_network.assert_called_once_with(self.context,
dummyxml, instance, network_info, dummyxml, instance, network_info,
block_device_info=block_device_info, block_device_info=block_device_info)
reboot=True, vifs_already_plugged=True)
@mock.patch('oslo_utils.fileutils.ensure_tree') @mock.patch('oslo_utils.fileutils.ensure_tree')
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall') @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall')

View File

@ -2501,12 +2501,15 @@ class LibvirtDriver(driver.ComputeDriver):
re-creates the domain to ensure the reboot happens, as the guest re-creates the domain to ensure the reboot happens, as the guest
OS cannot ignore this action. OS cannot ignore this action.
""" """
# NOTE(mdbooth): In addition to performing a hard reboot of the domain,
self._destroy(instance) # the hard reboot operation is relied upon by operators to be an
# Domain XML will be redefined so we can safely undefine it # automated attempt to fix as many things as possible about a
# from libvirt. This ensure that such process as create serial # non-functioning instance before resorting to manual intervention.
# console for guest will run smoothly. # With this goal in mind, we tear down all the aspects of an instance
self._undefine_domain(instance) # we can here without losing data. This allows us to re-initialise from
# scratch, and hopefully fix, most aspects of a non-functioning guest.
self.destroy(context, instance, network_info, destroy_disks=False,
block_device_info=block_device_info)
# Convert the system metadata to image metadata # Convert the system metadata to image metadata
# NOTE(mdbooth): This is a workaround for stateless Nova compute # NOTE(mdbooth): This is a workaround for stateless Nova compute
@ -2542,9 +2545,7 @@ class LibvirtDriver(driver.ComputeDriver):
# Initialize all the necessary networking, block devices and # Initialize all the necessary networking, block devices and
# start the instance. # start the instance.
self._create_domain_and_network(context, xml, instance, network_info, self._create_domain_and_network(context, xml, instance, network_info,
block_device_info=block_device_info, block_device_info=block_device_info)
reboot=True,
vifs_already_plugged=True)
self._prepare_pci_devices_for_use( self._prepare_pci_devices_for_use(
pci_manager.get_instance_pci_devs(instance, 'all')) pci_manager.get_instance_pci_devs(instance, 'all'))