summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkira Yoshiyama <a-yoshiyama@bu.jp.nec.com>2013-04-14 11:39:55 +0000
committerAkira Yoshiyama <a-yoshiyama@bu.jp.nec.com>2013-05-19 00:31:53 +0000
commit616e5d965bd8a2923f00ba4ff194e6a6ee2468cd (patch)
treee9026cfd86deafc709adaf69dff4cb2d9dd03a6a
parente4f05bada6bba3dfab936bb0e77a673b640b6f9e (diff)
downloadnova-616e5d965bd8a2923f00ba4ff194e6a6ee2468cd.tar.gz
nova-616e5d965bd8a2923f00ba4ff194e6a6ee2468cd.tar.xz
nova-616e5d965bd8a2923f00ba4ff194e6a6ee2468cd.zip
Make nova-api use servicegroup.API.service_is_up().
Fix bug 1168861 Change-Id: I1e7e8f7519ec627b96736f74ee7123d101973544
-rw-r--r--nova/api/openstack/compute/contrib/services.py8
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_services.py11
2 files changed, 14 insertions, 5 deletions
diff --git a/nova/api/openstack/compute/contrib/services.py b/nova/api/openstack/compute/contrib/services.py
index 9952484f7..bc5f60b64 100644
--- a/nova/api/openstack/compute/contrib/services.py
+++ b/nova/api/openstack/compute/contrib/services.py
@@ -22,8 +22,7 @@ from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import compute
from nova import exception
-from nova.openstack.common import timeutils
-from nova import utils
+from nova import servicegroup
authorize = extensions.extension_authorizer('compute', 'services')
CONF = cfg.CONF
@@ -71,6 +70,7 @@ class ServiceController(object):
def __init__(self):
self.host_api = compute.HostAPI()
+ self.servicegroup_api = servicegroup.API()
@wsgi.serializers(xml=ServicesIndexTemplate)
def index(self, req):
@@ -79,7 +79,6 @@ class ServiceController(object):
"""
context = req.environ['nova.context']
authorize(context)
- now = timeutils.utcnow()
services = self.host_api.service_get_all(
context, set_zones=True)
@@ -96,8 +95,7 @@ class ServiceController(object):
svcs = []
for svc in services:
- delta = now - (svc['updated_at'] or svc['created_at'])
- alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
+ alive = self.servicegroup_api.service_is_up(svc)
art = (alive and "up") or "down"
active = 'enabled'
if svc['disabled']:
diff --git a/nova/tests/api/openstack/compute/contrib/test_services.py b/nova/tests/api/openstack/compute/contrib/test_services.py
index 57dd056ee..387a5eb21 100644
--- a/nova/tests/api/openstack/compute/contrib/test_services.py
+++ b/nova/tests/api/openstack/compute/contrib/test_services.py
@@ -21,6 +21,7 @@ from nova import context
from nova import db
from nova import exception
from nova.openstack.common import timeutils
+from nova.servicegroup.drivers import db as db_driver
from nova import test
from nova.tests.api.openstack import fakes
@@ -202,3 +203,13 @@ class ServicesTest(test.TestCase):
res_dict = self.controller.update(req, "disable", body)
self.assertEqual(res_dict['service']['status'], 'disabled')
+
+ # This test is just to verify that the servicegroup API gets used when
+ # calling this API.
+ def test_services_with_exception(self):
+ def dummy_is_up(self, dummy):
+ raise KeyError()
+
+ self.stubs.Set(db_driver.DbDriver, 'is_up', dummy_is_up)
+ req = FakeRequestWithHostService()
+ self.assertRaises(KeyError, self.controller.index, req)