Merge "libvirt: Test disk creation in test_hard_reboot"
This commit is contained in:
@@ -11406,19 +11406,14 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||||||
@mock.patch('nova.virt.libvirt.LibvirtDriver._undefine_domain')
|
@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._create_images_and_backing')
|
|
||||||
@mock.patch('nova.virt.libvirt.LibvirtDriver._get_guest_xml')
|
@mock.patch('nova.virt.libvirt.LibvirtDriver._get_guest_xml')
|
||||||
@mock.patch('nova.virt.libvirt.LibvirtDriver._get_instance_disk_info')
|
@mock.patch('nova.virt.libvirt.LibvirtDriver._get_instance_disk_info')
|
||||||
@mock.patch('nova.virt.libvirt.blockinfo.get_disk_info')
|
|
||||||
@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_instance_disk_info, mock_get_guest_xml,
|
mock_get_guest_xml, mock_create_domain_and_network,
|
||||||
mock_create_images_and_backing,
|
mock_get_info, mock_undefine):
|
||||||
mock_create_domain_and_network, mock_get_info,
|
|
||||||
mock_undefine):
|
|
||||||
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)
|
||||||
instance_path = libvirt_utils.get_instance_path(instance)
|
|
||||||
network_info = _fake_network_info(self, 1)
|
network_info = _fake_network_info(self, 1)
|
||||||
block_device_info = None
|
block_device_info = None
|
||||||
|
|
||||||
@@ -11438,29 +11433,48 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||||||
hardware.InstanceInfo(state=power_state.RUNNING)]
|
hardware.InstanceInfo(state=power_state.RUNNING)]
|
||||||
mock_get_info.side_effect = return_values
|
mock_get_info.side_effect = return_values
|
||||||
|
|
||||||
backing_disk_info = [{"virt_disk_size": 2}]
|
|
||||||
|
|
||||||
mock_get_disk_info.return_value = mock.sentinel.disk_info
|
|
||||||
mock_get_guest_xml.return_value = dummyxml
|
mock_get_guest_xml.return_value = dummyxml
|
||||||
mock_get_instance_disk_info.return_value = backing_disk_info
|
mock_get_disk_info.return_value = \
|
||||||
|
fake_disk_info_byname(instance).values()
|
||||||
|
|
||||||
drvr._hard_reboot(self.context, instance, network_info,
|
backend = self.useFixture(fake_imagebackend.ImageBackendFixture())
|
||||||
block_device_info)
|
|
||||||
|
with mock.patch('os.path.exists', return_value=True):
|
||||||
|
drvr._hard_reboot(self.context, instance, network_info,
|
||||||
|
block_device_info)
|
||||||
|
|
||||||
|
disks = backend.disks
|
||||||
|
|
||||||
|
# NOTE(mdbooth): _create_images_and_backing() passes a full path in
|
||||||
|
# 'disk_name' when creating a disk. This is wrong, but happens to
|
||||||
|
# work due to handling by each individual backend. This will be
|
||||||
|
# fixed in a subsequent commit.
|
||||||
|
#
|
||||||
|
# We translate all the full paths into disk names here to make the
|
||||||
|
# test readable
|
||||||
|
disks = {os.path.basename(name): value
|
||||||
|
for name, value in six.iteritems(disks)}
|
||||||
|
|
||||||
|
# We should have called cache() on the root and ephemeral disks
|
||||||
|
for name in ('disk', 'disk.local'):
|
||||||
|
self.assertTrue(disks[name].cache.called)
|
||||||
|
|
||||||
mock_destroy.assert_called_once_with(instance)
|
mock_destroy.assert_called_once_with(instance)
|
||||||
mock_undefine.assert_called_once_with(instance)
|
mock_undefine.assert_called_once_with(instance)
|
||||||
|
|
||||||
# make sure that _create_images_and_backing is passed the disk_info
|
# Check the structure of disk_info passed to
|
||||||
# returned from _get_instance_disk_info and not the one that is in
|
# _create_domain_and_network, but we don't care about any of the values
|
||||||
# scope from blockinfo.get_disk_info
|
mock_disk_info = {
|
||||||
mock_create_images_and_backing.assert_called_once_with(self.context,
|
'disk_bus': mock.ANY,
|
||||||
instance, instance_path, backing_disk_info)
|
'cdrom_bus': mock.ANY,
|
||||||
|
'mapping': {
|
||||||
# make sure that _create_domain_and_network is passed the disk_info
|
'root': mock.ANY,
|
||||||
# returned from blockinfo.get_disk_info and not the one that's
|
'disk': mock.ANY,
|
||||||
# returned from _get_instance_disk_info
|
'disk.local': mock.ANY
|
||||||
|
}
|
||||||
|
}
|
||||||
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, mock.sentinel.disk_info,
|
dummyxml, instance, network_info, mock_disk_info,
|
||||||
block_device_info=block_device_info,
|
block_device_info=block_device_info,
|
||||||
reboot=True, vifs_already_plugged=True)
|
reboot=True, vifs_already_plugged=True)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user