From 782dd69de4c6661eeb889b4e5b3b1b8df9d228b6 Mon Sep 17 00:00:00 2001 From: Matthew Sherborne Date: Thu, 7 Mar 2013 08:06:21 +1000 Subject: Prepare services index method for use with cells Move the api.openstack.compute.contrib.services' index method's logic out of the openstack api layer and into the compute api layer. The addition of the availability_zone information is already done by the host api. For this reason it was removed from the openstack api layer. The behaviour of the call remains the same, only the functionality has been moved. This patch makes the functionality automatically work in cells. Work towards: bug #1150499 Change-Id: Ia9489f11608167aed5168ccb3b670f395f7de5f7 --- nova/api/openstack/compute/contrib/services.py | 10 +++++++--- .../api/openstack/compute/contrib/test_services.py | 18 +++++++++++++----- nova/tests/integrated/test_api_samples.py | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/nova/api/openstack/compute/contrib/services.py b/nova/api/openstack/compute/contrib/services.py index 3afd5ff45..fb7b9d591 100644 --- a/nova/api/openstack/compute/contrib/services.py +++ b/nova/api/openstack/compute/contrib/services.py @@ -20,7 +20,7 @@ import webob.exc from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil -from nova import availability_zones +from nova import compute from nova import db from nova import exception from nova.openstack.common import log as logging @@ -58,6 +58,10 @@ class ServicesUpdateTemplate(xmlutil.TemplateBuilder): class ServiceController(object): + + def __init__(self): + self.host_api = compute.HostAPI() + @wsgi.serializers(xml=ServicesIndexTemplate) def index(self, req): """ @@ -66,8 +70,8 @@ class ServiceController(object): context = req.environ['nova.context'] authorize(context) now = timeutils.utcnow() - services = db.service_get_all(context) - services = availability_zones.set_availability_zones(context, services) + services = self.host_api.service_get_all( + context, set_zones=True) host = '' if 'host' in req.GET: diff --git a/nova/tests/api/openstack/compute/contrib/test_services.py b/nova/tests/api/openstack/compute/contrib/test_services.py index d4bf62d19..cb7ce67cb 100644 --- a/nova/tests/api/openstack/compute/contrib/test_services.py +++ b/nova/tests/api/openstack/compute/contrib/test_services.py @@ -16,6 +16,7 @@ import datetime from nova.api.openstack.compute.contrib import services +from nova import availability_zones from nova import context from nova import db from nova import exception @@ -76,7 +77,13 @@ class FakeRequestWithHostService(object): GET = {"host": "host1", "service": "nova-compute"} -def fake_service_get_all(context): +def fake_host_api_service_get_all(context, filters=None, set_zones=False): + if set_zones or 'availability_zone' in filters: + return availability_zones.set_availability_zones(context, + fake_services_list) + + +def fake_db_api_service_get_all(context, disabled=None): return fake_services_list @@ -112,15 +119,16 @@ class ServicesTest(test.TestCase): def setUp(self): super(ServicesTest, self).setUp() - self.stubs.Set(db, "service_get_all", fake_service_get_all) + self.context = context.get_admin_context() + self.controller = services.ServiceController() + + self.stubs.Set(self.controller.host_api, "service_get_all", + fake_host_api_service_get_all) self.stubs.Set(timeutils, "utcnow", fake_utcnow) self.stubs.Set(db, "service_get_by_args", fake_service_get_by_host_binary) self.stubs.Set(db, "service_update", fake_service_update) - self.context = context.get_admin_context() - self.controller = services.ServiceController() - def test_services_list(self): req = FakeRequest() res_dict = self.controller.index(req) diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index 9fe2c6566..fe155655b 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -1956,7 +1956,7 @@ class ServicesJsonTest(ApiSampleTestBase): def setUp(self): super(ServicesJsonTest, self).setUp() self.stubs.Set(db, "service_get_all", - test_services.fake_service_get_all) + test_services.fake_db_api_service_get_all) self.stubs.Set(timeutils, "utcnow", test_services.fake_utcnow) self.stubs.Set(db, "service_get_by_args", test_services.fake_service_get_by_host_binary) -- cgit