Preventing listener deletion if it has l7 policy
If L7 policy is associated to listener, the policy should be deleted
prior to listener deletion.
Trying to delete the listener with L7 policy will fail
with EntityInUse exception.
This is to preserve common neutron's API concept
to delete cascade resources' subresources only.
Change-Id: I575f898f74576613cb55d4dbba5b1b0f524dd35f
Closes-Bug: 1588372
(cherry picked from commit 58fe3494ef
This commit is contained in:
parent
5bcc99dd69
commit
94b030955a
|
@ -803,6 +803,12 @@ class LoadBalancerPluginv2(loadbalancerv2.LoadBalancerPluginBaseV2):
|
||||||
return self.db.get_listener(context, id).to_api_dict()
|
return self.db.get_listener(context, id).to_api_dict()
|
||||||
|
|
||||||
def delete_listener(self, context, id):
|
def delete_listener(self, context, id):
|
||||||
|
old_listener = self.db.get_listener(context, id)
|
||||||
|
if old_listener.l7_policies:
|
||||||
|
raise loadbalancerv2.EntityInUse(
|
||||||
|
entity_using=models.L7Policy.NAME,
|
||||||
|
id=old_listener.l7_policies[0].id,
|
||||||
|
entity_in_use=models.Listener.NAME)
|
||||||
self.db.test_and_set_status(context, models.Listener, id,
|
self.db.test_and_set_status(context, models.Listener, id,
|
||||||
constants.PENDING_DELETE)
|
constants.PENDING_DELETE)
|
||||||
listener_db = self.db.get_listener(context, id)
|
listener_db = self.db.get_listener(context, id)
|
||||||
|
|
|
@ -1374,6 +1374,16 @@ class LbaasListenerTests(ListenerTestBase):
|
||||||
resp, body = self._get_loadbalancer_api(self.lb_id)
|
resp, body = self._get_loadbalancer_api(self.lb_id)
|
||||||
self.assertEqual(0, len(body['loadbalancer']['listeners']))
|
self.assertEqual(0, len(body['loadbalancer']['listeners']))
|
||||||
|
|
||||||
|
def test_delete_listener_with_l7policy(self):
|
||||||
|
with self.listener(loadbalancer_id=self.lb_id,
|
||||||
|
no_delete=True) as listener:
|
||||||
|
with self.l7policy(listener['listener']['id'], no_delete=True):
|
||||||
|
ctx = context.get_admin_context()
|
||||||
|
self.assertRaises(
|
||||||
|
loadbalancerv2.EntityInUse,
|
||||||
|
self.plugin.delete_listener,
|
||||||
|
ctx, listener['listener']['id'])
|
||||||
|
|
||||||
def test_show_listener(self):
|
def test_show_listener(self):
|
||||||
name = 'show_listener'
|
name = 'show_listener'
|
||||||
expected_values = {'name': name,
|
expected_values = {'name': name,
|
||||||
|
|
Loading…
Reference in New Issue