From 5fdcf190aa79eaa04b20cc6acf63dd99bce5e106 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 4 Mar 2013 20:38:09 -0500 Subject: Remove uses of instance['instance_type'] from libvirt driver. Note that this includes a few tweaks to the libvirt tests where the instance type in use was expected to have no swap, but the actual id-matching fake did. This integration makes it a little harder for the tests to be out of whack like that, which is good. This is one change in a series aimed at removing the use of instance-linked instance_type objects, in favor of the decoupled type data in system_metadata. See bug 1140119 for more details. Change-Id: I190258bd0947944d9bcdf49956eed40d402606f5 --- nova/tests/test_libvirt.py | 19 +++++++++++++++---- nova/tests/test_libvirt_blockinfo.py | 10 +++++++--- nova/virt/libvirt/blockinfo.py | 3 ++- nova/virt/libvirt/driver.py | 3 ++- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 10ef7805d..0029849e5 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -303,6 +303,9 @@ class LibvirtConnTestCase(test.TestCase): self.stubs.Set(libvirt_driver.disk, 'extend', fake_extend) + instance_type = db.instance_type_get(self.context, 5) + sys_meta = instance_types.save_instance_type_info({}, instance_type) + nova.tests.image.fake.stub_out_image_service(self.stubs) self.test_instance = { 'uuid': '32dfcb37-5af1-552b-357c-be8c3aa38310', @@ -316,7 +319,8 @@ class LibvirtConnTestCase(test.TestCase): 'root_gb': 10, 'ephemeral_gb': 20, 'instance_type_id': '5', # m1.small - 'extra_specs': {}} + 'extra_specs': {}, + 'system_metadata': sys_meta} def tearDown(self): nova.tests.image.fake.FakeImageService_reset() @@ -2517,6 +2521,10 @@ class LibvirtConnTestCase(test.TestCase): instance_ref = self.test_instance instance_ref['image_ref'] = 123456 # we send an int to test sha1 call + instance_type = db.instance_type_get(self.context, + instance_ref['instance_type_id']) + sys_meta = instance_types.save_instance_type_info({}, instance_type) + instance_ref['system_metadata'] = sys_meta instance = db.instance_create(self.context, instance_ref) # Mock out the get_info method of the LibvirtDriver so that the polling @@ -2675,10 +2683,9 @@ class LibvirtConnTestCase(test.TestCase): instance_ref = self.test_instance instance_ref['image_ref'] = 1 - instance = db.instance_create(self.context, instance_ref) - # Turn on some swap to exercise that codepath in _create_image - instance['instance_type']['swap'] = 500 + instance_ref['system_metadata']['instance_type_swap'] = 500 + instance = db.instance_create(self.context, instance_ref) conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) self.stubs.Set(conn, 'to_xml', fake_none) @@ -4598,6 +4605,9 @@ class LibvirtDriverTestCase(test.TestCase): if not params: params = {} + sys_meta = instance_types.save_instance_type_info( + {}, instance_types.get_instance_type_by_name('m1.tiny')) + inst = {} inst['image_ref'] = '1' inst['reservation_id'] = 'r-fakeres' @@ -4615,6 +4625,7 @@ class LibvirtDriverTestCase(test.TestCase): inst['ramdisk_id'] = 3 inst['config_drive_id'] = 1 inst['key_data'] = 'ABCDEFG' + inst['system_metadata'] = sys_meta inst.update(params) return db.instance_create(context.get_admin_context(), inst) diff --git a/nova/tests/test_libvirt_blockinfo.py b/nova/tests/test_libvirt_blockinfo.py index 0165d77b6..eef2deb50 100644 --- a/nova/tests/test_libvirt_blockinfo.py +++ b/nova/tests/test_libvirt_blockinfo.py @@ -16,6 +16,7 @@ # under the License. from nova import block_device +from nova.compute import instance_types from nova import context from nova import db from nova import exception @@ -32,6 +33,8 @@ class LibvirtBlockInfoTest(test.TestCase): self.user_id = 'fake' self.project_id = 'fake' self.context = context.get_admin_context() + instance_type = db.instance_type_get(self.context, 2) + sys_meta = instance_types.save_instance_type_info({}, instance_type) nova.tests.image.fake.stub_out_image_service(self.stubs) self.test_instance = { 'uuid': '32dfcb37-5af1-552b-357c-be8c3aa38310', @@ -44,7 +47,8 @@ class LibvirtBlockInfoTest(test.TestCase): 'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6', 'root_gb': 10, 'ephemeral_gb': 20, - 'instance_type_id': '5'} # m1.small + 'instance_type_id': 2, # m1.tiny + 'system_metadata': sys_meta} def test_volume_in_mapping(self): swap = {'device_name': '/dev/sdb', @@ -216,8 +220,8 @@ class LibvirtBlockInfoTest(test.TestCase): # A simple disk mapping setup, but with a swap device added user_context = context.RequestContext(self.user_id, self.project_id) + self.test_instance['system_metadata']['instance_type_swap'] = 5 instance_ref = db.instance_create(user_context, self.test_instance) - instance_ref['instance_type']['swap'] = 5 mapping = blockinfo.get_disk_mapping("kvm", instance_ref, "virtio", "ide") @@ -252,8 +256,8 @@ class LibvirtBlockInfoTest(test.TestCase): def test_get_disk_mapping_ephemeral(self): # A disk mapping with ephemeral devices user_context = context.RequestContext(self.user_id, self.project_id) + self.test_instance['system_metadata']['instance_type_swap'] = 5 instance_ref = db.instance_create(user_context, self.test_instance) - instance_ref['instance_type']['swap'] = 5 block_device_info = { 'ephemerals': [ diff --git a/nova/virt/libvirt/blockinfo.py b/nova/virt/libvirt/blockinfo.py index 3e4b3995c..88f97a271 100644 --- a/nova/virt/libvirt/blockinfo.py +++ b/nova/virt/libvirt/blockinfo.py @@ -66,6 +66,7 @@ variables / types used """ from nova import block_device +from nova.compute import instance_types from nova import exception from nova.openstack.common import log as logging from nova.virt import configdrive @@ -296,7 +297,7 @@ def get_disk_mapping(virt_type, instance, Returns the guest disk mapping for the devices.""" - inst_type = instance['instance_type'] + inst_type = instance_types.extract_instance_type(instance) mapping = {} diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 9858e0af2..625560773 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -63,6 +63,7 @@ from xml.dom import minidom from nova.api.metadata import base as instance_metadata from nova import block_device +from nova.compute import instance_types from nova.compute import power_state from nova.compute import task_states from nova.compute import vm_mode @@ -1773,7 +1774,7 @@ class LibvirtDriver(driver.ComputeDriver): root_fname = imagecache.get_cache_fname(disk_images, 'image_id') size = instance['root_gb'] * 1024 * 1024 * 1024 - inst_type = instance['instance_type'] + inst_type = instance_types.extract_instance_type(instance) if size == 0 or suffix == '.rescue': size = None -- cgit