]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Make sure report_interval is less than service_down_time
authorliyingjun <liyingjun1988@gmail.com>
Sat, 23 Nov 2013 14:06:19 +0000 (22:06 +0800)
committerliyingjun <liyingjun1988@gmail.com>
Sun, 24 Nov 2013 16:15:36 +0000 (00:15 +0800)
If service_down_time is less than report_interval, services will
routinely be considered down, because they report in too rarely.
Add check for service_down_time vs report_interval, if report_interval
is larger than service_down_time, automatically change
service_down_time to be report_interval * 2.5

DocImpact

Closes bug #1255685

Change-Id: I9b291669ea201321b03a48d2a132810f3bace2dc

cinder/service.py
cinder/tests/test_service.py

index 40a51b395ce58d4ccab5601cf3c4d9b7c076936a..5bf5e76e169dd21d6b54137c7c8ca8e8e0a0994b 100644 (file)
@@ -540,11 +540,28 @@ class WSGIService(object):
         self.app = self.loader.load_app(name)
         self.host = getattr(CONF, '%s_listen' % name, "0.0.0.0")
         self.port = getattr(CONF, '%s_listen_port' % name, 0)
+        self.basic_config_check()
         self.server = wsgi.Server(name,
                                   self.app,
                                   host=self.host,
                                   port=self.port)
 
+    def basic_config_check(self):
+        """Perform basic config checks before starting service."""
+        # Make sure report interval is less than service down time
+        report_interval = CONF.report_interval
+        if CONF.service_down_time <= report_interval:
+            new_service_down_time = int(report_interval * 2.5)
+            LOG.warn(_("Report interval must be less than service down "
+                       "time. Current config: <service_down_time: "
+                       "%(service_down_time)s, report_interval: "
+                       "%(report_interval)s>. Setting service_down_time to: "
+                       "%(new_service_down_time)s") %
+                     {'service_down_time': CONF.service_down_time,
+                      'report_interval': report_interval,
+                      'new_service_down_time': new_service_down_time})
+            CONF.set_override('service_down_time', new_service_down_time)
+
     def _get_manager(self):
         """Initialize a Manager object appropriate for this service.
 
index 9b4b7d51fdf4c1f61122db3e3382c6e9fb2e8e13..c385f90d08e0cec25e6528c3773bf3b2e572433c 100644 (file)
@@ -210,6 +210,12 @@ class TestWSGIService(test.TestCase):
         self.assertNotEqual(0, test_service.port)
         test_service.stop()
 
+    def test_service_with_min_down_time(self):
+        CONF.set_override('service_down_time', 10)
+        CONF.set_override('report_interval', 10)
+        service.WSGIService("test_service")
+        self.assertEqual(CONF.service_down_time, 25)
+
 
 class TestLauncher(test.TestCase):