diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-07-27 12:21:08 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-07-30 20:18:38 -0400 |
| commit | 73af6fa9722b720923002f62e115d84b74c9fe33 (patch) | |
| tree | 6707baabf79a2c5f5fb980ce84c47db52e44f65e | |
| parent | 100528f3a0df724c5a9611f0e7a0cce41ca5e12e (diff) | |
Send a full instance in remove_volume_connection.
Change the remove_volume_connection method of the compute
rpc API to take a full instance over rpc instead of just
the instance ID. This cuts down on database access needed
by nova-compute.
Part of blueprint no-db-messaging.
Change-Id: I1bd47b161acd7b6dfb03adb77d00a861f754e188
| -rw-r--r-- | nova/compute/manager.py | 14 | ||||
| -rw-r--r-- | nova/compute/rpcapi.py | 8 | ||||
| -rw-r--r-- | nova/tests/compute/test_compute.py | 6 | ||||
| -rw-r--r-- | nova/tests/compute/test_rpcapi.py | 8 |
4 files changed, 22 insertions, 14 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 688b2317c..e23db6812 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -272,7 +272,7 @@ def _get_image_meta(context, image_ref): class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" - RPC_API_VERSION = '1.25' + RPC_API_VERSION = '1.26' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -2047,19 +2047,21 @@ class ComputeManager(manager.SchedulerDependentManager): context, instance_uuid, volume_id) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) - def remove_volume_connection(self, context, instance_id, volume_id): + def remove_volume_connection(self, context, volume_id, instance=None, + instance_id=None): """Remove a volume connection using the volume api""" # NOTE(vish): We don't want to actually mark the volume # detached, or delete the bdm, just remove the # connection from this host. try: - instance_ref = self.db.instance_get(context, instance_id) + if not instance: + instance = self.db.instance_get(context, instance_id) bdm = self._get_instance_volume_bdm(context, - instance_ref['uuid'], + instance['uuid'], volume_id) - self._detach_volume(context, instance_ref, bdm) + self._detach_volume(context, instance, bdm) volume = self.volume_api.get(context, volume_id) - connector = self.driver.get_volume_connector(instance_ref) + connector = self.driver.get_volume_connector(instance) self.volume_api.terminate_connection(context, volume, connector) except exception.NotFound: pass diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index 70f3da64c..d7cc3e2b9 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -94,6 +94,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): rebuild_instance() 1.25 - Remove instance_uuid, add instance argument to remove_fixed_ip_from_instance() + 1.26 - Remove instance_id, add instance argument to + remove_volume_connection() ''' BASE_RPC_API_VERSION = '1.0' @@ -335,9 +337,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): version='1.25') def remove_volume_connection(self, ctxt, instance, volume_id, host): + instance_p = jsonutils.to_primitive(instance) return self.call(ctxt, self.make_msg('remove_volume_connection', - instance_id=instance['id'], volume_id=volume_id), - topic=_compute_topic(self.topic, ctxt, host, None)) + instance=instance_p, volume_id=volume_id), + topic=_compute_topic(self.topic, ctxt, host, None), + version='1.26') def rescue_instance(self, ctxt, instance, rescue_password): self.cast(ctxt, self.make_msg('rescue_instance', diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index fc2b183d9..27f0eb565 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -1612,11 +1612,13 @@ class ComputeTestCase(BaseTestCase): 'args': {'instance_id': inst_id, 'host': self.compute.host, 'teardown': False}}) + rpcinst = jsonutils.to_primitive( + db.instance_get_by_uuid(self.context, instance['uuid'])) rpc.call(c, topic, {"method": "remove_volume_connection", - "args": {'instance_id': inst_id, + "args": {'instance': rpcinst, 'volume_id': volume_id}, - "version": "1.0"}, None) + "version": "1.26"}, None) rpc.cast(c, topic, {"method": "rollback_live_migration_at_destination", "args": {'instance_id': inst_id}, diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py index e081c1455..edfbc309b 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -58,7 +58,7 @@ class ComputeRpcAPITestCase(test.TestCase): 'post_live_migration_at_destination', 'power_off_instance', 'power_on_instance', 'pre_live_migration', 'reboot_instance', 'rebuild_instance', 'remove_fixed_ip_from_instance', - 'start_instance', 'stop_instance', + 'remove_volume_connection', 'start_instance', 'stop_instance', 'suspend_instance', 'unpause_instance' ] @@ -84,8 +84,7 @@ class ComputeRpcAPITestCase(test.TestCase): methods_with_instance): instance = expected_msg['args']['instance'] del expected_msg['args']['instance'] - if method in ['rollback_live_migration_at_destination', - 'remove_volume_connection']: + if method in ['rollback_live_migration_at_destination']: expected_msg['args']['instance_id'] = instance['id'] else: expected_msg['args']['instance_uuid'] = instance['uuid'] @@ -262,7 +261,8 @@ class ComputeRpcAPITestCase(test.TestCase): def test_remove_volume_connection(self): self._test_compute_api('remove_volume_connection', 'call', - instance=self.fake_instance, volume_id='id', host='host') + instance=self.fake_instance, volume_id='id', host='host', + version='1.26') def test_rescue_instance(self): self._test_compute_api('rescue_instance', 'cast', |
