diff options
author | Dan Smith <danms@us.ibm.com> | 2013-01-04 10:12:52 -0800 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-01-05 05:18:08 +0000 |
commit | f47c997242f591ca45945f86c00b584217a9b75b (patch) | |
tree | 9677809e5b21c6dad5006f7e08e725fbdd98fc18 | |
parent | 8be47738aedb809b9d64559aeba821e17796a6a8 (diff) | |
download | nova-f47c997242f591ca45945f86c00b584217a9b75b.tar.gz nova-f47c997242f591ca45945f86c00b584217a9b75b.tar.xz nova-f47c997242f591ca45945f86c00b584217a9b75b.zip |
Move service_get_all operations to conductor
This patch adds a single service_get_all_by() method to the
conductor, which services the following database calls:
- service_get_all()
- service_get_all_by_topic()
- service_get_all_by_host()
- service_get_by_host_and_topic()
- service_get_all_compute_by_host()
It also makes compute/manager use conductor for this case.
The special case for the service_get_all_compute_by_host() call
is rather unfortunate, and I wonder if it might be okay to (later)
make the generic function automatically joinedload in the compute
case.
Related to blueprint no-db-compute-manager
Change-Id: Ib4aa10a3196a4b9aa779f57f4e5d6b136676f3bd
-rw-r--r-- | nova/compute/manager.py | 4 | ||||
-rw-r--r-- | nova/conductor/api.py | 31 | ||||
-rw-r--r-- | nova/conductor/manager.py | 19 | ||||
-rw-r--r-- | nova/conductor/rpcapi.py | 5 | ||||
-rw-r--r-- | nova/tests/conductor/test_conductor.py | 82 |
5 files changed, 138 insertions, 3 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index f8b8d08e3..66bc787a8 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2460,8 +2460,8 @@ class ComputeManager(manager.SchedulerDependentManager): pass def _get_compute_info(self, context, host): - compute_node_ref = self.db.service_get_all_compute_by_host(context, - host) + compute_node_ref = self.conductor_api.service_get_all_compute_by_host( + context, host) try: return compute_node_ref[0]['compute_node'][0] except IndexError: diff --git a/nova/conductor/api.py b/nova/conductor/api.py index ffcf5c8eb..0f622ec9b 100644 --- a/nova/conductor/api.py +++ b/nova/conductor/api.py @@ -216,6 +216,21 @@ class LocalAPI(object): instance, last_refreshed, update_totals) + def service_get_all(self, context): + return self._manager.service_get_all_by(context) + + def service_get_all_by_topic(self, context, topic): + return self._manager.service_get_all_by(context, topic=topic) + + def service_get_all_by_host(self, context, host): + return self._manager.service_get_all_by(context, host=host) + + def service_get_by_host_and_topic(self, context, host, topic): + return self._manager.service_get_all_by(context, topic, host) + + def service_get_all_compute_by_host(self, context, host): + return self._manager.service_get_all_by(context, 'compute', host) + class API(object): """Conductor API that does updates via RPC to the ConductorManager""" @@ -385,3 +400,19 @@ class API(object): wr_req, wr_bytes, instance, last_refreshed, update_totals) + + def service_get_all(self, context): + return self.conductor_rpcapi.service_get_all_by(context) + + def service_get_all_by_topic(self, context, topic): + return self.conductor_rpcapi.service_get_all_by(context, topic=topic) + + def service_get_all_by_host(self, context, host): + return self.conductor_rpcapi.service_get_all_by(context, host=host) + + def service_get_by_host_and_topic(self, context, host, topic): + return self.conductor_rpcapi.service_get_all_by(context, topic, host) + + def service_get_all_compute_by_host(self, context, host): + return self.conductor_rpcapi.service_get_all_by(context, 'compute', + host) diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index e2e2cfc77..392ef6b4d 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.20' + RPC_API_VERSION = '1.21' def __init__(self, *args, **kwargs): super(ConductorManager, self).__init__(service_name='conductor', @@ -233,3 +233,20 @@ class ConductorManager(manager.SchedulerDependentManager): self.db.vol_usage_update(context, vol_id, rd_req, rd_bytes, wr_req, wr_bytes, instance['uuid'], last_refreshed, update_totals) + + def service_get_all_by(self, context, topic=None, host=None): + if not any((topic, host)): + result = self.db.service_get_all(context) + elif all((topic, host)): + if topic == 'compute': + result = self.db.service_get_all_compute_by_host(context, + host) + else: + result = self.db.service_get_by_host_and_topic(context, + host, topic) + elif topic: + result = self.db.service_get_all_by_topic(context, topic) + elif host: + result = self.db.service_get_all_by_host(context, host) + + return jsonutils.to_primitive(result) diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py index 9b3a802ea..ab8aaa318 100644 --- a/nova/conductor/rpcapi.py +++ b/nova/conductor/rpcapi.py @@ -52,6 +52,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.18 - Added instance_type_get 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 """ BASE_RPC_API_VERSION = '1.0' @@ -234,3 +235,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): instance=instance_p, last_refreshed=last_refreshed, update_totals=update_totals) return self.call(context, msg, version='1.19') + + def service_get_all_by(self, context, topic=None, host=None): + msg = self.make_msg('service_get_all_by', topic=topic, host=host) + return self.call(context, msg, version='1.21') diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index b2342f5b4..f919b0465 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -402,6 +402,36 @@ class ConductorTestCase(_BaseTestCase, test.TestCase): self.conductor.instance_get_all_by_filters(self.context, filters, 'fake-key', 'fake-sort') + def _test_stubbed(self, name, dbargs, condargs): + self.mox.StubOutWithMock(db, name) + getattr(db, name)(self.context, *dbargs).AndReturn('fake-result') + self.mox.ReplayAll() + result = self.conductor.service_get_all_by(self.context, **condargs) + self.assertEqual(result, 'fake-result') + + def test_service_get_all(self): + self._test_stubbed('service_get_all', (), {}) + + def test_service_get_by_host_and_topic(self): + self._test_stubbed('service_get_by_host_and_topic', + ('host', 'topic'), + dict(topic='topic', host='host')) + + def test_service_get_all_by_topic(self): + self._test_stubbed('service_get_all_by_topic', + ('topic',), + dict(topic='topic')) + + def test_service_get_all_by_host(self): + self._test_stubbed('service_get_all_by_host', + ('host',), + dict(host='host')) + + def test_service_get_all_compute_by_host(self): + self._test_stubbed('service_get_all_compute_by_host', + ('host',), + dict(topic='compute', host='host')) + class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase): """Conductor RPC API Tests""" @@ -463,6 +493,36 @@ class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase): self.conductor.instance_get_all_by_filters(self.context, filters, 'fake-key', 'fake-sort') + def _test_stubbed(self, name, dbargs, condargs): + self.mox.StubOutWithMock(db, name) + getattr(db, name)(self.context, *dbargs).AndReturn('fake-result') + self.mox.ReplayAll() + result = self.conductor.service_get_all_by(self.context, **condargs) + self.assertEqual(result, 'fake-result') + + def test_service_get_all(self): + self._test_stubbed('service_get_all', (), {}) + + def test_service_get_by_host_and_topic(self): + self._test_stubbed('service_get_by_host_and_topic', + ('host', 'topic'), + dict(topic='topic', host='host')) + + def test_service_get_all_by_topic(self): + self._test_stubbed('service_get_all_by_topic', + ('topic',), + dict(topic='topic')) + + def test_service_get_all_by_host(self): + self._test_stubbed('service_get_all_by_host', + ('host',), + dict(host='host')) + + def test_service_get_all_compute_by_host(self): + self._test_stubbed('service_get_all_compute_by_host', + ('host',), + dict(topic='compute', host='host')) + class ConductorAPITestCase(_BaseTestCase, test.TestCase): """Conductor API Tests""" @@ -542,6 +602,28 @@ class ConductorAPITestCase(_BaseTestCase, test.TestCase): {'name': 'fake-inst'}, 'updated_at', 'asc') + def _test_stubbed(self, name, *args): + self.mox.StubOutWithMock(db, name) + getattr(db, name)(self.context, *args).AndReturn('fake-result') + self.mox.ReplayAll() + result = getattr(self.conductor, name)(self.context, *args) + self.assertEqual(result, 'fake-result') + + def test_service_get_all(self): + self._test_stubbed('service_get_all') + + def test_service_get_by_host_and_topic(self): + self._test_stubbed('service_get_by_host_and_topic', 'host', 'topic') + + def test_service_get_all_by_topic(self): + self._test_stubbed('service_get_all_by_topic', 'topic') + + def test_service_get_all_by_host(self): + self._test_stubbed('service_get_all_by_host', 'host') + + def test_service_get_all_compute_by_host(self): + self._test_stubbed('service_get_all_compute_by_host', 'host') + class ConductorLocalAPITestCase(ConductorAPITestCase): """Conductor LocalAPI Tests""" |