LBaaS: add delete_health_monitor() to driver API

Currently there is create_health_monitor() in the driver API so
a driver may create an object on device but there is no delete_health_monitor()
and monitor objects will remain on device forever.
Driver should at least call plugin to delete a db object.

Fixes bug 1198996

Change-Id: Idcdaea0636e01381064983d8de5bfe3936357fb9
This commit is contained in:
Oleg Bondarev 2013-07-19 17:00:13 +04:00 committed by Gerrit Code Review
parent 97215aa783
commit 8d60c2716a
5 changed files with 26 additions and 0 deletions

View File

@ -120,6 +120,13 @@ class LoadBalancerAbstractDriver(object):
pool_id): pool_id):
pass 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 @abc.abstractmethod
def create_pool_health_monitor(self, context, def create_pool_health_monitor(self, context,
health_monitor, health_monitor,

View File

@ -357,5 +357,8 @@ class HaproxyOnHostPluginDriver(abstract_driver.LoadBalancerAbstractDriver):
def create_health_monitor(self, context, health_monitor): def create_health_monitor(self, context, health_monitor):
pass 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): def stats(self, context, pool_id):
pass pass

View File

@ -89,6 +89,10 @@ class NoopLbaaSDriver(abstract_driver.LoadBalancerAbstractDriver):
pool_association): pool_association):
pass pass
@log.log
def delete_health_monitor(self, context, health_monitor):
self.plugin._delete_db_health_monitor(context, health_monitor["id"])
@log.log @log.log
def create_pool_health_monitor(self, context, def create_pool_health_monitor(self, context,
health_monitor, pool_id): health_monitor, pool_id):

View File

@ -185,6 +185,9 @@ class LoadBalancerPlugin(loadbalancer_db.LoadBalancerPluginDb,
hm_id, hm_id,
pool_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): def delete_health_monitor(self, context, id):
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
hm = self.get_health_monitor(context, id) hm = self.get_health_monitor(context, id)
@ -195,6 +198,7 @@ class LoadBalancerPlugin(loadbalancer_db.LoadBalancerPluginDb,
self.driver.delete_pool_health_monitor(context, self.driver.delete_pool_health_monitor(context,
hm, hm,
assoc['pool_id']) assoc['pool_id'])
self.driver.delete_health_monitor(context, hm)
def create_pool_health_monitor(self, context, health_monitor, pool_id): def create_pool_health_monitor(self, context, health_monitor, pool_id):
retval = super(LoadBalancerPlugin, self).create_pool_health_monitor( retval = super(LoadBalancerPlugin, self).create_pool_health_monitor(

View File

@ -859,10 +859,18 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
def test_delete_healthmonitor(self): def test_delete_healthmonitor(self):
with self.health_monitor(no_delete=True) as monitor: 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', req = self.new_delete_request('health_monitors',
monitor['health_monitor']['id']) monitor['health_monitor']['id'])
res = req.get_response(self.ext_api) res = req.get_response(self.ext_api)
self.assertEqual(res.status_int, 204) 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): def test_delete_healthmonitor_cascade_deletion_of_associations(self):
with self.health_monitor(type='HTTP', no_delete=True) as monitor: with self.health_monitor(type='HTTP', no_delete=True) as monitor: