diff --git a/neutron/db/address_group_db.py b/neutron/db/address_group_db.py index 738a219ec01..112cd97dd02 100644 --- a/neutron/db/address_group_db.py +++ b/neutron/db/address_group_db.py @@ -96,6 +96,7 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): def add_addresses(self, context, address_group_id, addresses): ag = self._get_address_group(context, address_group_id) + kwargs = {'original_address_group': self._make_address_group_dict(ag)} addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses( ag, addresses['addresses']) if addrs_in_ag: @@ -108,16 +109,19 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): addr_assoc = ag_obj.AddressAssociation(context, **args) addr_assoc.create() ag.update() # reload synthetic fields + ag_dict = {'address_group': self._make_address_group_dict(ag)} + kwargs.update(ag_dict) # TODO(hangyang) this notification should be updated to publish when # the callback handler handle_event, class _ObjectChangeHandler in # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # new style payload objects as argument. registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self, - context=context, address_group_id=ag.id) - return {'address_group': self._make_address_group_dict(ag)} + context=context, **kwargs) + return ag_dict def remove_addresses(self, context, address_group_id, addresses): ag = self._get_address_group(context, address_group_id) + kwargs = {'original_address_group': self._make_address_group_dict(ag)} addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses( ag, addresses['addresses']) if addrs_not_in_ag: @@ -127,13 +131,15 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): ag_obj.AddressAssociation.delete_objects( context, address_group_id=address_group_id, address=addr) ag.update() # reload synthetic fields + ag_dict = {'address_group': self._make_address_group_dict(ag)} + kwargs.update(ag_dict) # TODO(hangyang) this notification should be updated to publish when # the callback handler handle_event, class _ObjectChangeHandler in # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # new style payload objects as argument. registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self, - context=context, address_group_id=ag.id) - return {'address_group': self._make_address_group_dict(ag)} + context=context, **kwargs) + return ag_dict def create_address_group(self, context, address_group): """Create an address group.""" @@ -144,12 +150,15 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): 'description': fields['description']} ag = ag_obj.AddressGroup(context, **args) ag.create() + kwargs = {'address_group': self._make_address_group_dict(ag)} # TODO(mlavalle) this notification should be updated to publish when # the callback handler handle_event, class _ObjectChangeHandler in # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # new style payload objects as argument. registry.notify(ADDRESS_GROUP, events.AFTER_CREATE, self, - context=context, address_group_id=ag.id) + context=context, **kwargs) + # NOTE(hangyang): after sent the create notification we then handle + # adding addresses which will send another update notification if fields.get('addresses') is not constants.ATTR_NOT_SPECIFIED: self.add_addresses(context, ag.id, fields) ag.update() # reload synthetic fields @@ -158,15 +167,18 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): def update_address_group(self, context, id, address_group): fields = address_group['address_group'] ag = self._get_address_group(context, id) + kwargs = {'original_address_group': self._make_address_group_dict(ag)} ag.update_fields(fields) ag.update() + ag_dict = self._make_address_group_dict(ag) + kwargs['address_group'] = ag_dict # TODO(mlavalle) this notification should be updated to publish when # the callback handler handle_event, class _ObjectChangeHandler in # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # new style payload objects as argument. registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self, - context=context, address_group_id=ag.id) - return self._make_address_group_dict(ag) + context=context, **kwargs) + return ag_dict def get_address_group(self, context, id, fields=None): ag = self._get_address_group(context, id) @@ -188,11 +200,13 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): remote_address_group_id=id): # TODO(hangyang): use exception from neutron_lib raise AddressGroupInUse(address_group_id=id) - address_group = self._get_address_group(context, id) - address_group.delete() + ag = self._get_address_group(context, id) + ag.delete() + kwargs = {'address_group_id': id, 'name': ag['name'], + 'description': ag['description']} # TODO(mlavalle) this notification should be updated to publish when # the callback handler handle_event, class _ObjectChangeHandler in # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # new style payload objects as argument. registry.notify(ADDRESS_GROUP, events.AFTER_DELETE, self, - context=context, address_group_id=id) + context=context, **kwargs)