diff --git a/neutron/services/loadbalancer/drivers/abstract_driver.py b/neutron/services/loadbalancer/drivers/abstract_driver.py index eaec09ac26..1be9f934fa 100644 --- a/neutron/services/loadbalancer/drivers/abstract_driver.py +++ b/neutron/services/loadbalancer/drivers/abstract_driver.py @@ -120,6 +120,13 @@ class LoadBalancerAbstractDriver(object): pool_id): pass + @abc.abstractmethod + def delete_health_monitor(self, context, health_monitor): + """Driver may call the code below in order to delete the monitor. + self.plugin._delete_db_health_monitor(context, health_monitor["id"]) + """ + pass + @abc.abstractmethod def create_pool_health_monitor(self, context, health_monitor, diff --git a/neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py b/neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py index 85fb9de05e..d50c6e28b6 100644 --- a/neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py +++ b/neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py @@ -357,5 +357,8 @@ class HaproxyOnHostPluginDriver(abstract_driver.LoadBalancerAbstractDriver): def create_health_monitor(self, context, health_monitor): pass + def delete_health_monitor(self, context, health_monitor): + self.plugin._delete_db_health_monitor(context, health_monitor["id"]) + def stats(self, context, pool_id): pass diff --git a/neutron/services/loadbalancer/drivers/noop/noop_driver.py b/neutron/services/loadbalancer/drivers/noop/noop_driver.py index 3183c448a9..01b65b6575 100644 --- a/neutron/services/loadbalancer/drivers/noop/noop_driver.py +++ b/neutron/services/loadbalancer/drivers/noop/noop_driver.py @@ -89,6 +89,10 @@ class NoopLbaaSDriver(abstract_driver.LoadBalancerAbstractDriver): pool_association): pass + @log.log + def delete_health_monitor(self, context, health_monitor): + self.plugin._delete_db_health_monitor(context, health_monitor["id"]) + @log.log def create_pool_health_monitor(self, context, health_monitor, pool_id): diff --git a/neutron/services/loadbalancer/plugin.py b/neutron/services/loadbalancer/plugin.py index 9457ac3c1d..11b9c4df39 100644 --- a/neutron/services/loadbalancer/plugin.py +++ b/neutron/services/loadbalancer/plugin.py @@ -185,6 +185,9 @@ class LoadBalancerPlugin(loadbalancer_db.LoadBalancerPluginDb, hm_id, pool_id) + def _delete_db_health_monitor(self, context, id): + super(LoadBalancerPlugin, self).delete_health_monitor(context, id) + def delete_health_monitor(self, context, id): with context.session.begin(subtransactions=True): hm = self.get_health_monitor(context, id) @@ -195,6 +198,7 @@ class LoadBalancerPlugin(loadbalancer_db.LoadBalancerPluginDb, self.driver.delete_pool_health_monitor(context, hm, assoc['pool_id']) + self.driver.delete_health_monitor(context, hm) def create_pool_health_monitor(self, context, health_monitor, pool_id): retval = super(LoadBalancerPlugin, self).create_pool_health_monitor( diff --git a/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py b/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py index 5845697415..61a03c1339 100644 --- a/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py +++ b/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py @@ -859,10 +859,18 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase): def test_delete_healthmonitor(self): with self.health_monitor(no_delete=True) as monitor: + ctx = context.get_admin_context() + qry = ctx.session.query(ldb.HealthMonitor) + qry = qry.filter_by(id=monitor['health_monitor']['id']) + self.assertIsNotNone(qry.first()) + req = self.new_delete_request('health_monitors', monitor['health_monitor']['id']) res = req.get_response(self.ext_api) self.assertEqual(res.status_int, 204) + qry = ctx.session.query(ldb.HealthMonitor) + qry = qry.filter_by(id=monitor['health_monitor']['id']) + self.assertIsNone(qry.first()) def test_delete_healthmonitor_cascade_deletion_of_associations(self): with self.health_monitor(type='HTTP', no_delete=True) as monitor: