diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index a40184644f6..ea7be357862 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -606,12 +606,15 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): **kwargs) try: + sg_rule = query.one() # As there is a filter on a primary key it is not possible for # MultipleResultsFound to be raised - context.session.delete(query.one()) + context.session.delete(sg_rule) except exc.NoResultFound: raise ext_sg.SecurityGroupRuleNotFound(id=id) + kwargs['security_group_id'] = sg_rule['security_group_id'] + registry.notify( resources.SECURITY_GROUP_RULE, events.AFTER_DELETE, self, **kwargs) diff --git a/neutron/tests/unit/db/test_securitygroups_db.py b/neutron/tests/unit/db/test_securitygroups_db.py index 0f11ae0a981..466a99261d2 100644 --- a/neutron/tests/unit/db/test_securitygroups_db.py +++ b/neutron/tests/unit/db/test_securitygroups_db.py @@ -270,7 +270,7 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase): 'precommit_create', mock.ANY, context=mock.ANY, security_group_rule=mock.ANY)]) - def test_security_group_rule_precommit_delete_event(self): + def test_sg_rule_before_precommit_and_after_delete_event(self): sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP) fake_rule = FAKE_SECGROUP_RULE fake_rule['security_group_rule']['security_group_id'] = sg_dict['id'] @@ -280,9 +280,16 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase): fake_rule) self.mixin.delete_security_group_rule(self.ctx, sg_rule_dict['id']) + mock_notify.assert_has_calls([mock.call('security_group_rule', + 'before_delete', mock.ANY, context=mock.ANY, + security_group_rule_id=sg_rule_dict['id'])]) mock_notify.assert_has_calls([mock.call('security_group_rule', 'precommit_delete', mock.ANY, context=mock.ANY, - security_group_rule_id=mock.ANY)]) + security_group_rule_id=sg_rule_dict['id'])]) + mock_notify.assert_has_calls([mock.call('security_group_rule', + 'after_delete', mock.ANY, context=mock.ANY, + security_group_rule_id=sg_rule_dict['id'], + security_group_id=sg_dict['id'])]) def test_get_ip_proto_name_and_num(self): protocols = [constants.PROTO_NAME_UDP, str(constants.PROTO_NUM_TCP),