security group: pass update value to precommit_update

This patch is follow up for [1].
When updating security group, pass updated value to precommit.
old value is passed as original_security_group and new value
is passed as security_group.
[1] https://review.openstack.org/#/c/448420/

Although argument to callbacks will be unified by EventPayload
eventually, it's necessary to unbreak decomposed modules.

Change-Id: I5a27d1d218a0be4fae6f9740559bbbf773518821
Related-bug: #1546910
This commit is contained in:
Isaku Yamahata 2017-06-19 12:31:00 -07:00
parent ff56e45406
commit 154b8750bc
2 changed files with 17 additions and 10 deletions

View File

@ -251,17 +251,17 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
sg = self._get_security_group(context, id)
if sg.name == 'default' and 'name' in s:
raise ext_sg.SecurityGroupCannotUpdateDefault()
kwargs['security_group'] = self._make_security_group_dict(sg)
sg_dict = self._make_security_group_dict(sg)
kwargs['original_security_group'] = sg_dict
sg.update_fields(s)
sg.update()
sg_dict = self._make_security_group_dict(sg)
kwargs['security_group'] = sg_dict
self._registry_notify(
resources.SECURITY_GROUP,
events.PRECOMMIT_UPDATE,
exc_cls=ext_sg.SecurityGroupConflict, **kwargs)
sg.update_fields(s)
sg.update()
sg_dict = self._make_security_group_dict(sg)
kwargs['security_group'] = sg_dict
registry.notify(resources.SECURITY_GROUP, events.AFTER_UPDATE, self,
**kwargs)
return sg_dict

View File

@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import mock
from neutron_lib.callbacks import events
from neutron_lib.callbacks import exceptions
@ -309,13 +310,19 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase):
self._test_security_group_precommit_create_event()
def test_security_group_precommit_update_event(self):
sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)
original_sg_dict = self.mixin.create_security_group(self.ctx,
FAKE_SECGROUP)
sg_id = original_sg_dict['id']
with mock.patch.object(registry, "notify") as mock_notify:
fake_secgroup = copy.deepcopy(FAKE_SECGROUP)
fake_secgroup['security_group']['name'] = 'updated_fake'
sg_dict = self.mixin.update_security_group(
self.ctx, sg_id, fake_secgroup)
mock_notify.assert_has_calls([mock.call('security_group',
'precommit_update', mock.ANY, context=mock.ANY,
security_group=self.mixin.update_security_group(
self.ctx, sg_dict['id'], FAKE_SECGROUP),
security_group_id=sg_dict['id'])])
original_security_group=original_sg_dict,
security_group=sg_dict,
security_group_id=sg_id)])
def test_security_group_precommit_and_after_delete_event(self):
sg_dict = self.mixin.create_security_group(self.ctx, FAKE_SECGROUP)