]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Check the validation of 'delay' and 'timeout'
authorshihanzhang <shihanzhang@huawei.com>
Fri, 16 May 2014 07:26:57 +0000 (15:26 +0800)
committershihanzhang <shihanzhang@huawei.com>
Tue, 10 Jun 2014 02:07:06 +0000 (10:07 +0800)
In health monitor, the 'delay' should be greater or equal than 'timeout'.

Change-Id: I64972881676f2a1269aad8f9cdc77ae957c088d9
Closes-bug: #1320111

neutron/extensions/loadbalancer.py
neutron/services/loadbalancer/plugin.py
neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py

index bbeae035b1ca6b031860d760e2e1e8eb80b8f470..ae91b6515e260e748fe921d01ff06fe3be5c4b25 100644 (file)
@@ -29,6 +29,10 @@ from neutron.services import service_base
 
 
 # Loadbalancer Exceptions
+class DelayOrTimeoutInvalid(qexception.BadRequest):
+    message = _("Delay must be greater than or equal to timeout")
+
+
 class NoEligibleBackend(qexception.NotFound):
     message = _("No eligible backend for pool %(pool_id)s")
 
index 51e0e3f39be9cb994e1b14421d68a44d6e4a0d09..4e992e0851903a4c13e8153bd519fb8b0ceb2740 100644 (file)
@@ -230,7 +230,14 @@ class LoadBalancerPlugin(ldb.LoadBalancerPluginDb,
         driver = self._get_driver_for_pool(context, m['pool_id'])
         driver.delete_member(context, m)
 
+    def _validate_hm_parameters(self, delay, timeout):
+        if delay < timeout:
+            raise loadbalancer.DelayOrTimeoutInvalid()
+
     def create_health_monitor(self, context, health_monitor):
+        new_hm = health_monitor['health_monitor']
+        self._validate_hm_parameters(new_hm['delay'], new_hm['timeout'])
+
         hm = super(LoadBalancerPlugin, self).create_health_monitor(
             context,
             health_monitor
@@ -238,7 +245,12 @@ class LoadBalancerPlugin(ldb.LoadBalancerPluginDb,
         return hm
 
     def update_health_monitor(self, context, id, health_monitor):
+        new_hm = health_monitor['health_monitor']
         old_hm = self.get_health_monitor(context, id)
+        delay = new_hm.get('delay', old_hm.get('delay'))
+        timeout = new_hm.get('timeout', old_hm.get('timeout'))
+        self._validate_hm_parameters(delay, timeout)
+
         hm = super(LoadBalancerPlugin, self).update_health_monitor(
             context,
             id,
index 0dec61cf6dfda0c18318538212230e492f63b5dd..bc541c7c84f1c2b020fd1d6ab7359b7483cbf764 100644 (file)
@@ -965,6 +965,29 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
             for k, v in keys:
                 self.assertEqual(monitor['health_monitor'][k], v)
 
+    def test_create_health_monitor_with_timeout_delay_invalid(self):
+        data = {'health_monitor': {'type': type,
+                                   'delay': 3,
+                                   'timeout': 6,
+                                   'max_retries': 2,
+                                   'admin_state_up': True,
+                                   'tenant_id': self._tenant_id}}
+        req = self.new_create_request('health_monitors', data, self.fmt)
+        res = req.get_response(self.ext_api)
+        self.assertEqual(webob.exc.HTTPBadRequest.code, res.status_int)
+
+    def test_update_health_monitor_with_timeout_delay_invalid(self):
+        with self.health_monitor() as monitor:
+            data = {'health_monitor': {'delay': 10,
+                                       'timeout': 20,
+                                       'max_retries': 2,
+                                       'admin_state_up': False}}
+            req = self.new_update_request("health_monitors",
+                                          data,
+                                          monitor['health_monitor']['id'])
+            res = req.get_response(self.ext_api)
+            self.assertEqual(webob.exc.HTTPBadRequest.code, res.status_int)
+
     def test_update_healthmonitor(self):
         keys = [('type', "TCP"),
                 ('tenant_id', self._tenant_id),