Merge "Add sg_id in the AFTER_DELETE event of sg_rule delete"

This commit is contained in:
Jenkins
2016-11-17 11:19:09 +00:00
committed by Gerrit Code Review
2 changed files with 13 additions and 3 deletions

View File

@@ -624,12 +624,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)

View File

@@ -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),