Fix SG callbacks notification
Fix a regression from the recent change. [1] [1] I6f49f25eb2ad16221357024f45a6bb6175d5cd55 Closes-Bug: #1698812 Change-Id: Ifef2561ef4ff2a44068fc008475b216fdabe7095
This commit is contained in:
parent
7cb56a1628
commit
05293965f1
|
@ -117,6 +117,11 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||||
sg.obj_reset_changes(['rules'])
|
sg.obj_reset_changes(['rules'])
|
||||||
|
|
||||||
# fetch sg from db to load the sg rules with sg model.
|
# fetch sg from db to load the sg rules with sg model.
|
||||||
|
# NOTE(yamamoto): Adding rules above bumps the revision
|
||||||
|
# of the SG. It would add SG object to the session.
|
||||||
|
# Expunge it to ensure the following get_object doesn't
|
||||||
|
# use the instance.
|
||||||
|
context.session.expunge_all()
|
||||||
sg = sg_obj.SecurityGroup.get_object(context, id=sg.id)
|
sg = sg_obj.SecurityGroup.get_object(context, id=sg.id)
|
||||||
secgroup_dict = self._make_security_group_dict(sg)
|
secgroup_dict = self._make_security_group_dict(sg)
|
||||||
kwargs['security_group'] = secgroup_dict
|
kwargs['security_group'] = secgroup_dict
|
||||||
|
|
|
@ -24,6 +24,7 @@ import testtools
|
||||||
from neutron.db import common_db_mixin
|
from neutron.db import common_db_mixin
|
||||||
from neutron.db import securitygroups_db
|
from neutron.db import securitygroups_db
|
||||||
from neutron.extensions import securitygroup
|
from neutron.extensions import securitygroup
|
||||||
|
from neutron.services.revisions import revision_plugin
|
||||||
from neutron.tests.unit import testlib_api
|
from neutron.tests.unit import testlib_api
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,7 +254,8 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase):
|
||||||
self.ctx, sg_dict['id'])
|
self.ctx, sg_dict['id'])
|
||||||
self.assertTrue(mock_rollback.called)
|
self.assertTrue(mock_rollback.called)
|
||||||
|
|
||||||
def test_security_group_precommit_create_event(self):
|
def _test_security_group_precommit_create_event(self,
|
||||||
|
with_revisions=False):
|
||||||
DEFAULT_SECGROUP = {
|
DEFAULT_SECGROUP = {
|
||||||
'tenant_id': FAKE_SECGROUP['security_group']['tenant_id'],
|
'tenant_id': FAKE_SECGROUP['security_group']['tenant_id'],
|
||||||
'name': 'default',
|
'name': 'default',
|
||||||
|
@ -265,8 +267,15 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase):
|
||||||
'project_id': FAKE_SECGROUP['security_group']['tenant_id'],
|
'project_id': FAKE_SECGROUP['security_group']['tenant_id'],
|
||||||
'name': 'default',
|
'name': 'default',
|
||||||
'description': 'Default security group',
|
'description': 'Default security group',
|
||||||
'security_group_rules': mock.ANY,
|
'security_group_rules': [
|
||||||
|
# Four rules for egress/ingress and ipv4/ipv6
|
||||||
|
mock.ANY, mock.ANY, mock.ANY, mock.ANY,
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
if with_revisions:
|
||||||
|
DEFAULT_SECGROUP_DICT.update({
|
||||||
|
'revision_number': mock.ANY,
|
||||||
|
})
|
||||||
with mock.patch.object(registry, "notify") as mock_notify:
|
with mock.patch.object(registry, "notify") as mock_notify:
|
||||||
sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
|
sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
|
||||||
mock_notify.assert_has_calls([
|
mock_notify.assert_has_calls([
|
||||||
|
@ -291,6 +300,14 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase):
|
||||||
context=mock.ANY, is_default=False,
|
context=mock.ANY, is_default=False,
|
||||||
security_group=sg_dict)])
|
security_group=sg_dict)])
|
||||||
|
|
||||||
|
def test_security_group_precommit_create_event_with_revisions(self):
|
||||||
|
revision = revision_plugin.RevisionPlugin()
|
||||||
|
self._test_security_group_precommit_create_event(True)
|
||||||
|
del revision # appease pep8
|
||||||
|
|
||||||
|
def test_security_group_precommit_create_event(self):
|
||||||
|
self._test_security_group_precommit_create_event()
|
||||||
|
|
||||||
def test_security_group_precommit_update_event(self):
|
def test_security_group_precommit_update_event(self):
|
||||||
sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
|
sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
|
||||||
with mock.patch.object(registry, "notify") as mock_notify:
|
with mock.patch.object(registry, "notify") as mock_notify:
|
||||||
|
|
Loading…
Reference in New Issue