From 276ccf1e81cf8f10f6ea27cb2af4d566a9479df0 Mon Sep 17 00:00:00 2001 From: Qiu Yu Date: Wed, 26 Jun 2013 15:52:09 +0800 Subject: [PATCH] Fix service alive information in os-services extension Service alive information need to be compared with service_down_time value and updated accordingly. Change-Id: I9b9798c108a2da07ab78d5d05cbb51a73b14363e --- cinder/api/contrib/services.py | 5 ++++- cinder/tests/api/contrib/test_services.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cinder/api/contrib/services.py b/cinder/api/contrib/services.py index 3efac96f6..400d24893 100644 --- a/cinder/api/contrib/services.py +++ b/cinder/api/contrib/services.py @@ -16,6 +16,7 @@ # under the License. +from oslo.config import cfg import webob.exc from cinder.api import extensions @@ -28,6 +29,8 @@ from cinder.openstack.common import timeutils from cinder import utils +CONF = cfg.CONF + LOG = logging.getLogger(__name__) authorize = extensions.extension_authorizer('volume', 'services') @@ -81,7 +84,7 @@ class ServiceController(object): svcs = [] for svc in services: delta = now - (svc['updated_at'] or svc['created_at']) - alive = abs(utils.total_seconds(delta)) + alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time art = (alive and "up") or "down" active = 'enabled' if svc['disabled']: diff --git a/cinder/tests/api/contrib/test_services.py b/cinder/tests/api/contrib/test_services.py index 4e7493a46..5a8a4e55f 100644 --- a/cinder/tests/api/contrib/test_services.py +++ b/cinder/tests/api/contrib/test_services.py @@ -143,11 +143,11 @@ class ServicesTest(test.TestCase): 'updated_at': datetime(2012, 10, 29, 13, 42, 5)}, {'binary': 'cinder-scheduler', 'host': 'host2', 'zone': 'cinder', - 'status': 'enabled', 'state': 'up', + 'status': 'enabled', 'state': 'down', 'updated_at': datetime(2012, 9, 19, 6, 55, 34)}, {'binary': 'cinder-volume', 'host': 'host2', 'zone': 'cinder', - 'status': 'disabled', 'state': 'up', + 'status': 'disabled', 'state': 'down', 'updated_at': datetime(2012, 9, 18, 8, 3, 38)}]} self.assertEqual(res_dict, response) @@ -183,7 +183,7 @@ class ServicesTest(test.TestCase): 'host': 'host2', 'zone': 'cinder', 'status': 'disabled', - 'state': 'up', + 'state': 'down', 'updated_at': datetime(2012, 9, 18, 8, 3, 38)}]} self.assertEqual(res_dict, response) -- 2.45.2