]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Disallow 'timeout' in health_monitor to be negative
authorshihanzhang <shihanzhang@huawei.com>
Fri, 16 May 2014 04:02:40 +0000 (12:02 +0800)
committershihanzhang <shihanzhang@huawei.com>
Mon, 26 May 2014 01:20:57 +0000 (09:20 +0800)
It should limit the value of 'timeout' in 'health_monitor', the 'timeout'
shouldn't to be negative.

Change-Id: I26ae1995c9cc362df7c7dda4c53fb8adda298d13
Closes-bug: #1320062

neutron/extensions/loadbalancer.py
neutron/tests/unit/services/loadbalancer/test_loadbalancer_plugin.py

index 841e3f094eb99ffe388062fc7ff06a52c74324ca..bbeae035b1ca6b031860d760e2e1e8eb80b8f470 100644 (file)
@@ -250,6 +250,7 @@ RESOURCE_ATTRIBUTE_MAP = {
                   'convert_to': attr.convert_to_int,
                   'is_visible': True},
         'timeout': {'allow_post': True, 'allow_put': True,
+                    'validate': {'type:non_negative': None},
                     'convert_to': attr.convert_to_int,
                     'is_visible': True},
         'max_retries': {'allow_post': True, 'allow_put': True,
index a28124374012f65d43cddb9c65cd69ac13aeafa1..95fef74ddf2e343644573b2d9b24ac7a2c286e9a 100644 (file)
@@ -348,6 +348,23 @@ class LoadBalancerExtensionTestCase(test_api_v2_extension.ExtensionTestCase):
         self.assertIn('health_monitor', res)
         self.assertEqual(res['health_monitor'], return_value)
 
+    def test_health_monitor_create_with_timeout_negative(self):
+        data = {'health_monitor': {'type': 'HTTP',
+                                   'delay': 2,
+                                   'timeout': -1,
+                                   'max_retries': 3,
+                                   'http_method': 'GET',
+                                   'url_path': '/path',
+                                   'expected_codes': '200-300',
+                                   'admin_state_up': True,
+                                   'tenant_id': _uuid()}}
+        res = self.api.post(_get_path('lb/health_monitors',
+                                      fmt=self.fmt),
+                            self.serialize(data),
+                            content_type='application/%s' % self.fmt,
+                            expect_errors=True)
+        self.assertEqual(400, res.status_int)
+
     def test_health_monitor_list(self):
         health_monitor_id = _uuid()
         return_value = [{'type': 'HTTP',