From 5ee157c428b09b102906a7ec6834985557369b20 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 4 Jan 2013 12:47:45 -0800 Subject: Add ping to conductor This adds a ping() method to conductor, which takes a single argument and returns it back to the caller. It also returns the name of the current service, which is always 'conductor' in this case. I did this because I think that a generic ping method should do this in order to facilitate blind or broadcast pings. Related to bp/no-db-compute-manager Change-Id: I83105060945fa6a793d884c9e06ff154bc98e715 --- nova/conductor/api.py | 6 ++++++ nova/conductor/manager.py | 5 ++++- nova/conductor/rpcapi.py | 6 ++++++ nova/tests/conductor/test_conductor.py | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/nova/conductor/api.py b/nova/conductor/api.py index 0f622ec9b..66badb756 100644 --- a/nova/conductor/api.py +++ b/nova/conductor/api.py @@ -68,6 +68,9 @@ class LocalAPI(object): # other/future users of this sort of functionality. self._manager = ExceptionHelper(manager.ConductorManager()) + def ping(self, context, arg, timeout=None): + return self._manager.ping(context, arg) + def instance_update(self, context, instance_uuid, **updates): """Perform an instance update in the database""" return self._manager.instance_update(context, instance_uuid, updates) @@ -238,6 +241,9 @@ class API(object): def __init__(self): self.conductor_rpcapi = rpcapi.ConductorAPI() + def ping(self, context, arg, timeout=None): + return self.conductor_rpcapi.ping(context, arg, timeout) + def instance_update(self, context, instance_uuid, **updates): """Perform an instance update in the database""" return self.conductor_rpcapi.instance_update(context, instance_uuid, diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index 392ef6b4d..123e7e13f 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -43,12 +43,15 @@ datetime_fields = ['launched_at', 'terminated_at'] class ConductorManager(manager.SchedulerDependentManager): """Mission: TBD""" - RPC_API_VERSION = '1.21' + RPC_API_VERSION = '1.22' def __init__(self, *args, **kwargs): super(ConductorManager, self).__init__(service_name='conductor', *args, **kwargs) + def ping(self, context, arg): + return jsonutils.to_primitive({'service': 'conductor', 'arg': arg}) + @rpc_common.client_exceptions(KeyError, ValueError, exception.InvalidUUID, exception.InstanceNotFound, diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py index ab8aaa318..0f2fe1f0c 100644 --- a/nova/conductor/rpcapi.py +++ b/nova/conductor/rpcapi.py @@ -53,6 +53,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.19 - Added vol_get_usage_by_time and vol_usage_update 1.20 - Added migration_get_unconfirmed_by_dest_compute 1.21 - Added service_get_all_by + 1.22 - Added ping """ BASE_RPC_API_VERSION = '1.0' @@ -62,6 +63,11 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): topic=CONF.conductor.topic, default_version=self.BASE_RPC_API_VERSION) + def ping(self, context, arg, timeout=None): + arg_p = jsonutils.to_primitive(arg) + msg = self.make_msg('ping', arg=arg_p) + return self.call(context, msg, version='1.22', timeout=timeout) + def instance_update(self, context, instance_uuid, updates): updates_p = jsonutils.to_primitive(updates) return self.call(context, diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index f919b0465..86f47a79c 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -339,6 +339,10 @@ class _BaseTestCase(object): {'uuid': 'fake-id'}, 'fake-refr', 'fake-bool') + def test_ping(self): + result = self.conductor.ping(self.context, 'foo') + self.assertEqual(result, {'service': 'conductor', 'arg': 'foo'}) + class ConductorTestCase(_BaseTestCase, test.TestCase): """Conductor Manager Tests""" -- cgit