Merge "libvirt: only get instance.flavor if needed in get_disk_mapping"
This commit is contained in:
commit
98d0969254
@ -181,9 +181,14 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
|
|||||||
instance_ref = objects.Instance(**self.test_instance)
|
instance_ref = objects.Instance(**self.test_instance)
|
||||||
image_meta = objects.ImageMeta.from_dict(self.test_image_meta)
|
image_meta = objects.ImageMeta.from_dict(self.test_image_meta)
|
||||||
|
|
||||||
mapping = blockinfo.get_disk_mapping("kvm", instance_ref,
|
with mock.patch.object(instance_ref, 'get_flavor',
|
||||||
"virtio", "ide",
|
return_value=instance_ref.flavor) as get_flavor:
|
||||||
image_meta)
|
mapping = blockinfo.get_disk_mapping("kvm", instance_ref,
|
||||||
|
"virtio", "ide",
|
||||||
|
image_meta)
|
||||||
|
# Since there was no block_device_info passed to get_disk_mapping we
|
||||||
|
# expect to get the swap info from the flavor in the instance.
|
||||||
|
get_flavor.assert_called_once_with()
|
||||||
|
|
||||||
expect = {
|
expect = {
|
||||||
'disk': {'bus': 'virtio', 'dev': 'vda',
|
'disk': {'bus': 'virtio', 'dev': 'vda',
|
||||||
@ -673,10 +678,14 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
|
|||||||
'disk_bus': 'virtio',
|
'disk_bus': 'virtio',
|
||||||
'delete_on_termination': True}
|
'delete_on_termination': True}
|
||||||
|
|
||||||
blockinfo.get_disk_mapping("kvm", instance_ref,
|
with mock.patch.object(instance_ref, 'get_flavor') as get_flavor_mock:
|
||||||
"virtio", "ide",
|
blockinfo.get_disk_mapping("kvm", instance_ref,
|
||||||
image_meta,
|
"virtio", "ide",
|
||||||
block_device_info)
|
image_meta,
|
||||||
|
block_device_info)
|
||||||
|
# we should have gotten the swap info from block_device_info rather
|
||||||
|
# than the flavor information on the instance
|
||||||
|
self.assertFalse(get_flavor_mock.called)
|
||||||
|
|
||||||
self.assertEqual(expected_swap, block_device_info['swap'])
|
self.assertEqual(expected_swap, block_device_info['swap'])
|
||||||
self.assertEqual(expected_ephemeral,
|
self.assertEqual(expected_ephemeral,
|
||||||
|
@ -520,8 +520,6 @@ def get_disk_mapping(virt_type, instance,
|
|||||||
|
|
||||||
return mapping
|
return mapping
|
||||||
|
|
||||||
inst_type = instance.get_flavor()
|
|
||||||
|
|
||||||
pre_assigned_device_names = \
|
pre_assigned_device_names = \
|
||||||
[block_device.strip_dev(get_device_name(bdm)) for bdm in itertools.chain(
|
[block_device.strip_dev(get_device_name(bdm)) for bdm in itertools.chain(
|
||||||
driver.block_device_info_get_ephemerals(block_device_info),
|
driver.block_device_info_get_ephemerals(block_device_info),
|
||||||
@ -577,7 +575,7 @@ def get_disk_mapping(virt_type, instance,
|
|||||||
swap, mapping, disk_bus)
|
swap, mapping, disk_bus)
|
||||||
mapping['disk.swap'] = swap_info
|
mapping['disk.swap'] = swap_info
|
||||||
update_bdm(swap, swap_info)
|
update_bdm(swap, swap_info)
|
||||||
elif inst_type['swap'] > 0:
|
elif instance.get_flavor()['swap'] > 0:
|
||||||
swap_info = get_next_disk_info(mapping, disk_bus,
|
swap_info = get_next_disk_info(mapping, disk_bus,
|
||||||
assigned_devices=pre_assigned_device_names)
|
assigned_devices=pre_assigned_device_names)
|
||||||
if not block_device.volume_in_mapping(swap_info['dev'],
|
if not block_device.volume_in_mapping(swap_info['dev'],
|
||||||
|
Loading…
Reference in New Issue
Block a user