]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix service alive information in os-services extension
authorQiu Yu <unicell@gmail.com>
Wed, 26 Jun 2013 07:52:09 +0000 (15:52 +0800)
committerQiu Yu <unicell@gmail.com>
Wed, 26 Jun 2013 08:57:29 +0000 (16:57 +0800)
Service alive information need to be compared with service_down_time
value and updated accordingly.

Change-Id: I9b9798c108a2da07ab78d5d05cbb51a73b14363e

cinder/api/contrib/services.py
cinder/tests/api/contrib/test_services.py

index 3efac96f6398f99873b61a29914924329bb0e883..400d24893722a06ed700ce8a00da2e90c19c752c 100644 (file)
@@ -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']:
index 4e7493a46ad1b591f827fbca94c62b68c82976a3..5a8a4e55f31eefa6c350dd6824211a0f1238ef05 100644 (file)
@@ -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)