Use payloads for ADDRESS_GROUP callback events

This patch switches over to payload style of callbacks for the remaining
ADDRESS_GROUP based callback events.

Change-Id: I7aafd00211d66b0d1cc3bbdc79efc344c2acc700
This commit is contained in:
Nurmatov Mamatisa 2021-05-14 09:51:41 +03:00 committed by Mamatisa Nurmatov
parent 7e98d18927
commit 17adb4c3fb
2 changed files with 28 additions and 40 deletions

View File

@ -83,7 +83,7 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
def add_addresses(self, context, address_group_id, addresses): def add_addresses(self, context, address_group_id, addresses):
ag = self._get_address_group(context, address_group_id) ag = self._get_address_group(context, address_group_id)
kwargs = {'original_address_group': self._make_address_group_dict(ag)} original_address_group = self._make_address_group_dict(ag)
addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses( addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses(
ag, addresses['addresses']) ag, addresses['addresses'])
if addrs_in_ag: if addrs_in_ag:
@ -97,18 +97,16 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
addr_assoc.create() addr_assoc.create()
ag.update() # reload synthetic fields ag.update() # reload synthetic fields
ag_dict = {'address_group': self._make_address_group_dict(ag)} ag_dict = {'address_group': self._make_address_group_dict(ag)}
kwargs.update(ag_dict) registry.publish(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self,
# TODO(hangyang) this notification should be updated to publish when payload=events.DBEventPayload(
# the callback handler handle_event, class _ObjectChangeHandler in context,
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with resource_id=address_group_id,
# new style payload objects as argument. states=(original_address_group, ag_dict,)))
registry.notify(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self,
context=context, **kwargs)
return ag_dict return ag_dict
def remove_addresses(self, context, address_group_id, addresses): def remove_addresses(self, context, address_group_id, addresses):
ag = self._get_address_group(context, address_group_id) ag = self._get_address_group(context, address_group_id)
kwargs = {'original_address_group': self._make_address_group_dict(ag)} original_address_group = self._make_address_group_dict(ag)
addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses( addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses(
ag, addresses['addresses']) ag, addresses['addresses'])
if addrs_not_in_ag: if addrs_not_in_ag:
@ -119,13 +117,11 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
context, address_group_id=address_group_id, address=addr) context, address_group_id=address_group_id, address=addr)
ag.update() # reload synthetic fields ag.update() # reload synthetic fields
ag_dict = {'address_group': self._make_address_group_dict(ag)} ag_dict = {'address_group': self._make_address_group_dict(ag)}
kwargs.update(ag_dict) registry.publish(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self,
# TODO(hangyang) this notification should be updated to publish when payload=events.DBEventPayload(
# the callback handler handle_event, class _ObjectChangeHandler in context,
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with resource_id=address_group_id,
# new style payload objects as argument. states=(original_address_group, ag_dict,)))
registry.notify(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self,
context=context, **kwargs)
return ag_dict return ag_dict
def create_address_group(self, context, address_group): def create_address_group(self, context, address_group):
@ -137,13 +133,12 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
'description': fields['description']} 'description': fields['description']}
ag = ag_obj.AddressGroup(context, **args) ag = ag_obj.AddressGroup(context, **args)
ag.create() ag.create()
kwargs = {'address_group': self._make_address_group_dict(ag)} address_group = self._make_address_group_dict(ag)
# TODO(mlavalle) this notification should be updated to publish when registry.publish(resources.ADDRESS_GROUP, events.AFTER_CREATE, self,
# the callback handler handle_event, class _ObjectChangeHandler in payload=events.DBEventPayload(
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with context,
# new style payload objects as argument. resource_id=ag.id,
registry.notify(resources.ADDRESS_GROUP, events.AFTER_CREATE, self, states=(address_group,)))
context=context, **kwargs)
# NOTE(hangyang): after sent the create notification we then handle # NOTE(hangyang): after sent the create notification we then handle
# adding addresses which will send another update notification # adding addresses which will send another update notification
if fields.get('addresses') is not constants.ATTR_NOT_SPECIFIED: if fields.get('addresses') is not constants.ATTR_NOT_SPECIFIED:
@ -154,17 +149,15 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
def update_address_group(self, context, id, address_group): def update_address_group(self, context, id, address_group):
fields = address_group['address_group'] fields = address_group['address_group']
ag = self._get_address_group(context, id) ag = self._get_address_group(context, id)
kwargs = {'original_address_group': self._make_address_group_dict(ag)} original_address_group = self._make_address_group_dict(ag)
ag.update_fields(fields) ag.update_fields(fields)
ag.update() ag.update()
ag_dict = self._make_address_group_dict(ag) ag_dict = self._make_address_group_dict(ag)
kwargs['address_group'] = ag_dict registry.publish(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self,
# TODO(mlavalle) this notification should be updated to publish when payload=events.DBEventPayload(
# the callback handler handle_event, class _ObjectChangeHandler in context,
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with resource_id=id,
# new style payload objects as argument. states=(original_address_group, ag_dict,)))
registry.notify(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self,
context=context, **kwargs)
return ag_dict return ag_dict
def get_address_group(self, context, id, fields=None): def get_address_group(self, context, id, fields=None):
@ -189,11 +182,6 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
raise ag_exc.AddressGroupInUse(address_group_id=id) raise ag_exc.AddressGroupInUse(address_group_id=id)
ag = self._get_address_group(context, id) ag = self._get_address_group(context, id)
ag.delete() ag.delete()
kwargs = {'address_group_id': id, 'name': ag['name'], registry.publish(resources.ADDRESS_GROUP, events.AFTER_DELETE, self,
'description': ag['description']} payload=events.DBEventPayload(context, resource_id=id,
# TODO(mlavalle) this notification should be updated to publish when states=(ag,)))
# 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(resources.ADDRESS_GROUP, events.AFTER_DELETE, self,
context=context, **kwargs)

View File

@ -37,7 +37,7 @@ LOG = logging.getLogger(__name__)
class _ObjectChangeHandler(object): class _ObjectChangeHandler(object):
_PAYLOAD_RESOURCES = (resources.NETWORK,) _PAYLOAD_RESOURCES = (resources.NETWORK, resources.ADDRESS_GROUP,)
def __init__(self, resource, object_class, resource_push_api): def __init__(self, resource, object_class, resource_push_api):
self._resource = resource self._resource = resource