# 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")
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
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,
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),