From 3d39f10565217e7450ff8595013ac55714750781 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 4 Mar 2013 20:38:09 -0500 Subject: [PATCH] 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 +++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 10ef7805..0029849e 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 0165d77b..eef2deb5 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': [