Merge "Check the validation of 'delay' and 'timeout'"

This commit is contained in:
Jenkins 2014-06-10 13:01:08 +00:00 committed by Gerrit Code Review
commit e7b2a61c54
3 changed files with 39 additions and 0 deletions

View 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")

View 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,

View 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),