From e02846cff4748f7df4d73fb0833fa3dbad1ccf9b Mon Sep 17 00:00:00 2001 From: shihanzhang Date: Fri, 16 May 2014 12:02:40 +0800 Subject: [PATCH] Disallow 'timeout' in health_monitor to be negative 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 | 1 + .../loadbalancer/test_loadbalancer_plugin.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/neutron/extensions/loadbalancer.py b/neutron/extensions/loadbalancer.py index 841e3f094..bbeae035b 100644 --- a/neutron/extensions/loadbalancer.py +++ b/neutron/extensions/loadbalancer.py @@ -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, diff --git a/neutron/tests/unit/services/loadbalancer/test_loadbalancer_plugin.py b/neutron/tests/unit/services/loadbalancer/test_loadbalancer_plugin.py index a28124374..95fef74dd 100644 --- a/neutron/tests/unit/services/loadbalancer/test_loadbalancer_plugin.py +++ b/neutron/tests/unit/services/loadbalancer/test_loadbalancer_plugin.py @@ -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', -- 2.45.2