Preventing pool deletion if pool has healthmonitor

If HM is associated to pool, HM should be deleted prior
to pool deletion.
Trying to delete pool with HM will fail with EntityInUse exception.
This is to preserve common neutron's API concept to delete cascade
resources' subresources only.

Change-Id: I1bfc4d8d8ec7e83b1de11c8fb3e66282bfd06806
Closes-Bug: 1571097
(cherry picked from commit 4effc9b96e)
This commit is contained in:
Evgeny Fedoruk 2016-06-02 01:29:42 -07:00
parent 5bcc99dd69
commit db3b921a17
2 changed files with 19 additions and 0 deletions

View File

@ -893,6 +893,12 @@ class LoadBalancerPluginv2(loadbalancerv2.LoadBalancerPluginBaseV2):
return self.db.get_pool(context, id).to_api_dict()
def delete_pool(self, context, id):
old_lb = self.db.get_pool(context, id)
if old_lb.healthmonitor:
raise loadbalancerv2.EntityInUse(
entity_using=models.HealthMonitorV2.NAME,
id=old_lb.healthmonitor.id,
entity_in_use=models.PoolV2.NAME)
self.db.test_and_set_status(context, models.PoolV2, id,
constants.PENDING_DELETE)
db_pool = self.db.get_pool(context, id)

View File

@ -2531,6 +2531,17 @@ class LbaasPoolTests(PoolTestBase):
self.plugin.db.get_pool_member,
ctx, member_id)
def test_delete_pool_and_hm(self):
with self.pool(listener_id=self.listener_id) as pool:
pool_id = pool['pool']['id']
with self.healthmonitor(pool_id=pool_id):
# verify pool deletion is prevented if HM is associated
ctx = context.get_admin_context()
self.assertRaises(
loadbalancerv2.EntityInUse,
self.plugin.delete_pool,
ctx, pool_id)
def test_cannot_add_multiple_pools_to_listener(self):
with self.pool(listener_id=self.listener_id):
data = {'pool': {'name': '',
@ -3374,6 +3385,7 @@ class LbaasHealthMonitorTests(HealthMonitorTestBase):
'pool_id': self.pool_id}}
resp, body = self._create_healthmonitor_api(data)
self.assertEqual(201, resp.status_int)
self._delete('healthmonitors', body['healthmonitor']['id'])
def test_create_health_monitor_with_http_method_invalid(self):
data = {'healthmonitor': {'type': 'HTTP',
@ -3409,6 +3421,7 @@ class LbaasHealthMonitorTests(HealthMonitorTestBase):
'pool_id': self.pool_id}}
resp, body = self._create_healthmonitor_api(data)
self.assertEqual(201, resp.status_int)
self._delete('healthmonitors', body['healthmonitor']['id'])
def test_create_health_monitor_with_url_path_invalid(self):
data = {'healthmonitor': {'type': 'HTTP',