From fd78129b9fa76c008756f60412b1d066d1c21caf Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 11 Jan 2013 14:32:41 -0500 Subject: Add service_create to conductor. This patch adds the service_create method to the conductor service. It also updates nova.service to use it. When a service has been marked as not using the db, it will invoke a remote conductor method to create the service record. Part of bp no-db-compute. Change-Id: Ie1f2db96d3134b0e30230565e5c000c416ea73d5 --- nova/conductor/api.py | 6 ++++++ nova/conductor/manager.py | 6 +++++- nova/conductor/rpcapi.py | 5 +++++ nova/service.py | 14 ++++++++------ nova/tests/conductor/test_conductor.py | 3 +++ nova/tests/test_service.py | 4 +++- 6 files changed, 30 insertions(+), 8 deletions(-) (limited to 'nova') diff --git a/nova/conductor/api.py b/nova/conductor/api.py index 228876682..099f9a61d 100644 --- a/nova/conductor/api.py +++ b/nova/conductor/api.py @@ -255,6 +255,9 @@ class LocalAPI(object): def action_event_finish(self, context, values): return self._manager.action_event_finish(context, values) + def service_create(self, context, values): + return self._manager.service_create(context, values) + class API(object): """Conductor API that does updates via RPC to the ConductorManager.""" @@ -485,3 +488,6 @@ class API(object): def action_event_finish(self, context, values): return self.conductor_rpcapi.action_event_finish(context, values) + + def service_create(self, context, values): + return self.conductor_rpcapi.service_create(context, values) diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index a7bc08420..95831043a 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -43,7 +43,7 @@ datetime_fields = ['launched_at', 'terminated_at'] class ConductorManager(manager.SchedulerDependentManager): """Mission: TBD.""" - RPC_API_VERSION = '1.26' + RPC_API_VERSION = '1.27' def __init__(self, *args, **kwargs): super(ConductorManager, self).__init__(service_name='conductor', @@ -272,3 +272,7 @@ class ConductorManager(manager.SchedulerDependentManager): def action_event_finish(self, context, values): evt = self.db.action_event_finish(context, values) return jsonutils.to_primitive(evt) + + def service_create(self, context, values): + svc = self.db.service_create(context, values) + return jsonutils.to_primitive(svc) diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py index 8850bca01..de368418e 100644 --- a/nova/conductor/rpcapi.py +++ b/nova/conductor/rpcapi.py @@ -59,6 +59,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.24 - Added instance_get 1.25 - Added action_event_start and action_event_finish 1.26 - Added instance_info_cache_update + 1.27 - Added service_create """ BASE_RPC_API_VERSION = '1.0' @@ -278,3 +279,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): instance=instance_p, values=values) return self.call(context, msg, version='1.26') + + def service_create(self, context, values): + msg = self.make_msg('service_create', values=values) + return self.call(context, msg, version='1.27') diff --git a/nova/service.py b/nova/service.py index 05049d464..12c1725c3 100644 --- a/nova/service.py +++ b/nova/service.py @@ -472,12 +472,14 @@ class Service(object): self.timers.append(periodic) def _create_service_ref(self, context): - service_ref = db.service_create(context, - {'host': self.host, - 'binary': self.binary, - 'topic': self.topic, - 'report_count': 0}) - self.service_id = service_ref['id'] + svc_values = { + 'host': self.host, + 'binary': self.binary, + 'topic': self.topic, + 'report_count': 0 + } + service = self.conductor_api.service_create(context, svc_values) + self.service_id = service['id'] def __getattr__(self, key): manager = self.__dict__.get('manager', None) diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index 909174fa9..885788187 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -650,6 +650,9 @@ class ConductorAPITestCase(_BaseTestCase, test.TestCase): def test_service_get_all_compute_by_host(self): self._test_stubbed('service_get_all_compute_by_host', 'host') + def test_service_create(self): + self._test_stubbed('service_create', {}) + def test_ping(self): timeouts = [] calls = dict(count=0) diff --git a/nova/tests/test_service.py b/nova/tests/test_service.py index 0bb57d542..8cc24cb1c 100644 --- a/nova/tests/test_service.py +++ b/nova/tests/test_service.py @@ -113,6 +113,8 @@ class ServiceTestCase(test.TestCase): self.binary = 'nova-fake' self.topic = 'fake' self.mox.StubOutWithMock(service, 'db') + self.mox.StubOutWithMock(db, 'service_create') + self.flags(use_local=True, group='conductor') def test_create(self): @@ -136,7 +138,7 @@ class ServiceTestCase(test.TestCase): service.db.service_get_by_args(mox.IgnoreArg(), self.host, self.binary).AndRaise(exception.NotFound()) - service.db.service_create(mox.IgnoreArg(), + db.service_create(mox.IgnoreArg(), service_create).AndReturn(service_ref) return service_ref -- cgit