From 0e16133db77b434f8dc5b298ef8166aa05013630 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 27 Jul 2012 11:05:46 -0400 Subject: Send a full instance in rebuild_instance. Change the rebuild_instance method of the compute rpc API to take a full instance over rpc instead of just the instance UUID. This cuts down on database access needed by nova-compute. This patch also includes fixes for a couple of places that were getting the instance name using the old instance.name syntax. It must be instance['name']. These no-db-messaging patches are making it so more code paths have an instance as a dict (received over rpc) instead of the SQLAlchemy model (looked up from the db on the compute node). Part of blueprint no-db-messaging. Change-Id: I21647a5a5cbf71a2c498f6fee2e4adbe30b8f2ea --- nova/tests/compute/test_compute.py | 17 ++++++++++------- nova/tests/compute/test_rpcapi.py | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 848376da1..8ce9212d7 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -526,13 +526,13 @@ class ComputeTestCase(BaseTestCase): def test_rebuild(self): """Ensure instance can be rebuilt""" - instance = self._create_fake_instance() + instance = jsonutils.to_primitive(self._create_fake_instance()) instance_uuid = instance['uuid'] image_ref = instance['image_ref'] self.compute.run_instance(self.context, instance_uuid) - self.compute.rebuild_instance(self.context, instance_uuid, - image_ref, image_ref) + self.compute.rebuild_instance(self.context, image_ref, image_ref, + instance=instance) self.compute.terminate_instance(self.context, instance_uuid) def test_rebuild_launch_time(self): @@ -540,14 +540,14 @@ class ComputeTestCase(BaseTestCase): old_time = datetime.datetime(2012, 4, 1) cur_time = datetime.datetime(2012, 12, 21, 12, 21) timeutils.set_time_override(old_time) - instance = self._create_fake_instance() + instance = jsonutils.to_primitive(self._create_fake_instance()) instance_uuid = instance['uuid'] image_ref = instance['image_ref'] self.compute.run_instance(self.context, instance_uuid) timeutils.set_time_override(cur_time) - self.compute.rebuild_instance(self.context, instance_uuid, - image_ref, image_ref) + self.compute.rebuild_instance(self.context, image_ref, image_ref, + instance=instance) instance = db.instance_get_by_uuid(self.context, instance_uuid) self.assertEquals(cur_time, instance['launched_at']) self.compute.terminate_instance(self.context, instance_uuid) @@ -1143,7 +1143,10 @@ class ComputeTestCase(BaseTestCase): password = "new_password" - self.compute._rebuild_instance(self.context, inst_ref['uuid'], + instance = db.instance_get_by_uuid(self.context, inst_ref['uuid']) + + self.compute._rebuild_instance(self.context.elevated(), + jsonutils.to_primitive(instance), image_ref, new_image_ref, dict(new_pass=password)) instance = db.instance_get_by_uuid(self.context, inst_ref['uuid']) diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py index 8620f81be..79b33f25d 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -57,8 +57,8 @@ class ComputeRpcAPITestCase(test.TestCase): 'inject_file', 'inject_network_info', 'pause_instance', 'post_live_migration_at_destination', 'power_off_instance', 'power_on_instance', 'pre_live_migration', 'reboot_instance', - 'start_instance', 'stop_instance', 'suspend_instance', - 'unpause_instance' + 'rebuild_instance', 'start_instance', 'stop_instance', + 'suspend_instance', 'unpause_instance' ] if 'rpcapi_class' in kwargs: @@ -235,7 +235,7 @@ class ComputeRpcAPITestCase(test.TestCase): self._test_compute_api('rebuild_instance', 'cast', instance=self.fake_instance, new_pass='pass', injected_files='files', image_ref='ref', - orig_image_ref='orig_ref') + orig_image_ref='orig_ref', version='1.24') def refresh_provider_fw_rules(self): self._test_compute_api('refresh_provider_fw_rules', 'cast', -- cgit