From cd4d96a4f7c7e8430477402928f64e6ac8b657a7 Mon Sep 17 00:00:00 2001 From: Nurmatov Mamatisa Date: Tue, 20 Apr 2021 11:15:11 +0300 Subject: [PATCH] Use exceptions and resources from neutron-lib Exceptions and resources were released in neutron-lib 2.7.0 Change-Id: Ic53f44ceb82c86ca72565ceda75a251339d5cc4e --- neutron/db/address_group_db.py | 29 +++++++---------------------- neutron/plugins/ml2/ovo_rpc.py | 5 +---- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/neutron/db/address_group_db.py b/neutron/db/address_group_db.py index a69890e4dbb..f995ad51da8 100644 --- a/neutron/db/address_group_db.py +++ b/neutron/db/address_group_db.py @@ -13,14 +13,13 @@ import netaddr from neutron_lib.callbacks import events from neutron_lib.callbacks import registry +from neutron_lib.callbacks import resources from neutron_lib import constants from neutron_lib.db import resource_extend from neutron_lib.db import utils as db_utils -from neutron_lib import exceptions from neutron_lib.exceptions import address_group as ag_exc from oslo_utils import uuidutils -from neutron._i18n import _ from neutron.common import utils as common_utils from neutron.extensions import address_group as ag_ext from neutron.objects import address_group as ag_obj @@ -28,19 +27,6 @@ from neutron.objects import base as base_obj from neutron.objects import securitygroup as sg_obj -# TODO(hangyang): Remove this exception once neutron_lib > 2.6.1 is released. -class AddressGroupInUse(exceptions.InUse): - message = _("Address group %(address_group_id)s is in use on one or more " - "security group rules.") - - -# TODO(mlavalle) Following line should be deleted when -# https://review.opendev.org/#/c/756927/ is released. All references in this -# module to ADDRESS_GROUP should point to the definition in -# neutron_lib/callbacks/resources -ADDRESS_GROUP = 'address_group' - - @resource_extend.has_resource_extenders class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): """Mixin class to add address group to db_base_plugin_v2.""" @@ -116,7 +102,7 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): # 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, + registry.notify(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self, context=context, **kwargs) return ag_dict @@ -138,7 +124,7 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): # 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, + registry.notify(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self, context=context, **kwargs) return ag_dict @@ -156,7 +142,7 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): # 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, + registry.notify(resources.ADDRESS_GROUP, events.AFTER_CREATE, self, context=context, **kwargs) # NOTE(hangyang): after sent the create notification we then handle # adding addresses which will send another update notification @@ -177,7 +163,7 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): # 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, + registry.notify(resources.ADDRESS_GROUP, events.AFTER_UPDATE, self, context=context, **kwargs) return ag_dict @@ -200,8 +186,7 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): if sg_obj.SecurityGroupRule.get_objects( common_utils.get_elevated_context(context), remote_address_group_id=id): - # TODO(hangyang): use exception from neutron_lib - raise AddressGroupInUse(address_group_id=id) + raise ag_exc.AddressGroupInUse(address_group_id=id) ag = self._get_address_group(context, id) ag.delete() kwargs = {'address_group_id': id, 'name': ag['name'], @@ -210,5 +195,5 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase): # 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, + registry.notify(resources.ADDRESS_GROUP, events.AFTER_DELETE, self, context=context, **kwargs) diff --git a/neutron/plugins/ml2/ovo_rpc.py b/neutron/plugins/ml2/ovo_rpc.py index 23f538bb8b5..45cb126e9bc 100644 --- a/neutron/plugins/ml2/ovo_rpc.py +++ b/neutron/plugins/ml2/ovo_rpc.py @@ -148,10 +148,7 @@ class OVOServerRpcInterface(object): resources.NETWORK: network.Network, resources.SECURITY_GROUP: securitygroup.SecurityGroup, resources.SECURITY_GROUP_RULE: securitygroup.SecurityGroupRule, - # TODO(mlavalle) Following line should be replaced by: - # resources.ADDRESS_GROUP: address_group.AddressGroup, - # when https://review.opendev.org/#/c/756927/ is released - 'address_group': address_group.AddressGroup, + resources.ADDRESS_GROUP: address_group.AddressGroup, } self._resource_handlers = { res: _ObjectChangeHandler(res, obj_class, self._rpc_pusher)