Extend address group notification data

* Instead of just passing address group id in callback notifications, now
  we pass all the object fields info.

* Also fixed the create_address_group notification order to ensure the create
  event is sent before the update event.

Change-Id: I7978d5a9b1b03027a1ba7c3aed61aff4b918081b
Implements: blueprint address-groups-in-sg-rules
This commit is contained in:
Hang Yang 2020-12-28 16:24:32 -06:00
parent 92359b6fb9
commit 49c27eeda2
1 changed files with 24 additions and 10 deletions

View File

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