Security group call back need cascading delete the related rules

Currently we only pass the group id to event callback when deleting, but
this is not sufficient for ODL which don't maintain the relationship
between sg and its rules.
Because some rules added into SG still exists and need be cascading
deleted, like what did in DB.  Both AFTER_DELETE and PRECOMMIT_DELETE
events in SG deleting have the similar problem.
This patch adds the rules into SG when send delete event for SG.

Co-Authored-By: Manjeet Singh Bhatia <manjeet.s.bhatia@intel.com>
Change-Id: If66b78243c55aefa57cc4975a6f8ea4d05dc6afa
Close-Bug: #1557976
This commit is contained in:
Yalei Wang 2016-03-18 06:40:51 +00:00 committed by Manjeet Singh Bhatia
parent 6087f1d121
commit 178bff23f1
2 changed files with 13 additions and 4 deletions

View File

@ -274,6 +274,9 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
**kwargs)
with context.session.begin(subtransactions=True):
# pass security_group_rule_ids to ensure
# consistency with deleted rules
kwargs['security_group_rule_ids'] = [r['id'] for r in sg.rules]
self._registry_notify(resources.SECURITY_GROUP,
events.PRECOMMIT_DELETE,
exc_cls=ext_sg.SecurityGroupInUse, id=id,

View File

@ -214,13 +214,19 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase):
'precommit_update', mock.ANY, context=mock.ANY,
security_group=mock.ANY, security_group_id=sg_dict['id'])])
def test_security_group_precommit_delete_event(self):
def test_security_group_precommit_and_after_delete_event(self):
sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
with mock.patch.object(registry, "notify") as mock_notify:
self.mixin.delete_security_group(self.ctx, sg_dict['id'])
mock_notify.assert_has_calls([mock.call('security_group',
'precommit_delete', mock.ANY, context=mock.ANY,
security_group=mock.ANY, security_group_id=sg_dict['id'])])
mock_notify.assert_has_calls(
[mock.call('security_group', 'precommit_delete',
mock.ANY, context=mock.ANY, security_group=mock.ANY,
security_group_id=sg_dict['id'],
security_group_rule_ids=[mock.ANY, mock.ANY]),
mock.call('security_group', 'after_delete',
mock.ANY, context=mock.ANY,
security_group_id=sg_dict['id'],
security_group_rule_ids=[mock.ANY, mock.ANY])])
def test_security_group_rule_precommit_create_event_fail(self):
registry.subscribe(fake_callback, resources.SECURITY_GROUP_RULE,