Merge "libvirt: only get instance.flavor if needed in get_disk_mapping"

This commit is contained in:
Jenkins 2016-01-16 14:17:39 +00:00 committed by Gerrit Code Review
commit 98d0969254
2 changed files with 17 additions and 10 deletions

View File

@ -181,9 +181,14 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
instance_ref = objects.Instance(**self.test_instance)
image_meta = objects.ImageMeta.from_dict(self.test_image_meta)
mapping = blockinfo.get_disk_mapping("kvm", instance_ref,
"virtio", "ide",
image_meta)
with mock.patch.object(instance_ref, 'get_flavor',
return_value=instance_ref.flavor) as get_flavor:
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 = {
'disk': {'bus': 'virtio', 'dev': 'vda',
@ -673,10 +678,14 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
'disk_bus': 'virtio',
'delete_on_termination': True}
blockinfo.get_disk_mapping("kvm", instance_ref,
"virtio", "ide",
image_meta,
block_device_info)
with mock.patch.object(instance_ref, 'get_flavor') as get_flavor_mock:
blockinfo.get_disk_mapping("kvm", instance_ref,
"virtio", "ide",
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_ephemeral,

View File

@ -520,8 +520,6 @@ def get_disk_mapping(virt_type, instance,
return mapping
inst_type = instance.get_flavor()
pre_assigned_device_names = \
[block_device.strip_dev(get_device_name(bdm)) for bdm in itertools.chain(
driver.block_device_info_get_ephemerals(block_device_info),
@ -577,7 +575,7 @@ def get_disk_mapping(virt_type, instance,
swap, mapping, disk_bus)
mapping['disk.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,
assigned_devices=pre_assigned_device_names)
if not block_device.volume_in_mapping(swap_info['dev'],