Check the validation of 'delay' and 'timeout'
In health monitor, the 'delay' should be greater or equal than 'timeout'. Change-Id: I64972881676f2a1269aad8f9cdc77ae957c088d9 Closes-bug: #1320111
This commit is contained in:
parent
4e84a2da94
commit
fe8c2b4816
@ -29,6 +29,10 @@ from neutron.services import service_base
|
|||||||
|
|
||||||
|
|
||||||
# Loadbalancer Exceptions
|
# Loadbalancer Exceptions
|
||||||
|
class DelayOrTimeoutInvalid(qexception.BadRequest):
|
||||||
|
message = _("Delay must be greater than or equal to timeout")
|
||||||
|
|
||||||
|
|
||||||
class NoEligibleBackend(qexception.NotFound):
|
class NoEligibleBackend(qexception.NotFound):
|
||||||
message = _("No eligible backend for pool %(pool_id)s")
|
message = _("No eligible backend for pool %(pool_id)s")
|
||||||
|
|
||||||
|
@ -230,7 +230,14 @@ class LoadBalancerPlugin(ldb.LoadBalancerPluginDb,
|
|||||||
driver = self._get_driver_for_pool(context, m['pool_id'])
|
driver = self._get_driver_for_pool(context, m['pool_id'])
|
||||||
driver.delete_member(context, m)
|
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):
|
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(
|
hm = super(LoadBalancerPlugin, self).create_health_monitor(
|
||||||
context,
|
context,
|
||||||
health_monitor
|
health_monitor
|
||||||
@ -238,7 +245,12 @@ class LoadBalancerPlugin(ldb.LoadBalancerPluginDb,
|
|||||||
return hm
|
return hm
|
||||||
|
|
||||||
def update_health_monitor(self, context, id, health_monitor):
|
def update_health_monitor(self, context, id, health_monitor):
|
||||||
|
new_hm = health_monitor['health_monitor']
|
||||||
old_hm = self.get_health_monitor(context, id)
|
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(
|
hm = super(LoadBalancerPlugin, self).update_health_monitor(
|
||||||
context,
|
context,
|
||||||
id,
|
id,
|
||||||
|
@ -965,6 +965,29 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
|
|||||||
for k, v in keys:
|
for k, v in keys:
|
||||||
self.assertEqual(monitor['health_monitor'][k], v)
|
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):
|
def test_update_healthmonitor(self):
|
||||||
keys = [('type', "TCP"),
|
keys = [('type', "TCP"),
|
||||||
('tenant_id', self._tenant_id),
|
('tenant_id', self._tenant_id),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user