From ef77ee3fdf4bee219f3754a1f4ad42082d7b4a75 Mon Sep 17 00:00:00 2001 From: Anna Khmelnitsky Date: Wed, 17 May 2017 15:23:06 -0700 Subject: [PATCH] Stop using neutron PLURALS dict As part of ocata sync effort, stop using PLURALS defined in neutron, as it was removed by Ifdf29b8fc4c824c0ee840c4f51593a5aa8a22127. Use locally defined dictionary instead. Change-Id: I763e6036177b57c0bc8ef7311b9c8bbbcefbe634 --- gbpservice/neutron/extensions/__init__.py | 10 ++++++++++ gbpservice/neutron/extensions/group_policy.py | 6 +++--- gbpservice/neutron/extensions/servicechain.py | 6 +++--- gbpservice/neutron/services/grouppolicy/plugin.py | 11 ++--------- .../neutron/services/servicechain/plugins/sharing.py | 8 -------- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/gbpservice/neutron/extensions/__init__.py b/gbpservice/neutron/extensions/__init__.py index e69de29bb..5b9ab54c3 100644 --- a/gbpservice/neutron/extensions/__init__.py +++ b/gbpservice/neutron/extensions/__init__.py @@ -0,0 +1,10 @@ +GBP_PLURALS = {} + + +def register_plurals(plural_mappings): + for plural, single in plural_mappings.items(): + GBP_PLURALS[single] = plural + + +def get_plural(single): + return GBP_PLURALS.get(single) diff --git a/gbpservice/neutron/extensions/group_policy.py b/gbpservice/neutron/extensions/group_policy.py index 905b1fa83..74c523805 100644 --- a/gbpservice/neutron/extensions/group_policy.py +++ b/gbpservice/neutron/extensions/group_policy.py @@ -27,7 +27,7 @@ from oslo_log import log as logging from oslo_utils import uuidutils import six -import gbpservice.neutron.extensions +from gbpservice.neutron import extensions as gbp_extensions from gbpservice.neutron.extensions import patch # noqa from gbpservice.neutron.services.grouppolicy.common import ( constants as gp_constants) @@ -36,7 +36,7 @@ from gbpservice.neutron.services.grouppolicy.common import ( # The code below is a monkey patch of key Neutron's modules. This is needed for # the GBP service to be loaded correctly. GBP extensions' path is added # to Neutron's so that it's found at extension scanning time. -extensions.append_api_extensions_path(gbpservice.neutron.extensions.__path__) +extensions.append_api_extensions_path(gbp_extensions.__path__) LOG = logging.getLogger(__name__) @@ -980,7 +980,7 @@ class Group_policy(extensions.ExtensionDescriptor): 'external_policies': 'external_policy'} plural_mappings = resource_helper.build_plural_mappings( special_mappings, RESOURCE_ATTRIBUTE_MAP) - attr.PLURALS.update(plural_mappings) + gbp_extensions.register_plurals(plural_mappings) return resource_helper.build_resource_info(plural_mappings, RESOURCE_ATTRIBUTE_MAP, constants.GROUP_POLICY, diff --git a/gbpservice/neutron/extensions/servicechain.py b/gbpservice/neutron/extensions/servicechain.py index c62a13fe8..8c18aa3c6 100644 --- a/gbpservice/neutron/extensions/servicechain.py +++ b/gbpservice/neutron/extensions/servicechain.py @@ -24,7 +24,7 @@ from oslo_config import cfg from oslo_log import log as logging import six -import gbpservice.neutron.extensions +from gbpservice.neutron import extensions as gbp_extensions import gbpservice.neutron.extensions.group_policy # noqa from gbpservice.neutron.services.servicechain.common import constants as scc @@ -32,7 +32,7 @@ from gbpservice.neutron.services.servicechain.common import constants as scc # The code below is a monkey patch of key Neutron's modules. This is needed for # the GBP service to be loaded correctly. GBP extensions' path is added # to Neutron's so that it's found at extension scanning time. -extensions.append_api_extensions_path(gbpservice.neutron.extensions.__path__) +extensions.append_api_extensions_path(gbp_extensions.__path__) LOG = logging.getLogger(__name__) @@ -294,7 +294,7 @@ class Servicechain(extensions.ExtensionDescriptor): def get_resources(cls): plural_mappings = resource_helper.build_plural_mappings( {}, RESOURCE_ATTRIBUTE_MAP) - attr.PLURALS.update(plural_mappings) + gbp_extensions.register_plurals(plural_mappings) return resource_helper.build_resource_info(plural_mappings, RESOURCE_ATTRIBUTE_MAP, constants.SERVICECHAIN, diff --git a/gbpservice/neutron/services/grouppolicy/plugin.py b/gbpservice/neutron/services/grouppolicy/plugin.py index 45b165f51..f5295f889 100644 --- a/gbpservice/neutron/services/grouppolicy/plugin.py +++ b/gbpservice/neutron/services/grouppolicy/plugin.py @@ -13,7 +13,6 @@ import netaddr import six -from neutron.api.v2 import attributes as nattr from neutron import context as n_ctx from neutron.db import api as db_api from neutron.extensions import portbindings @@ -30,6 +29,7 @@ from gbpservice._i18n import _LW from gbpservice.common import utils as gbp_utils from gbpservice.neutron.db.grouppolicy import group_policy_db as gpdb from gbpservice.neutron.db.grouppolicy import group_policy_mapping_db +from gbpservice.neutron import extensions as gbp_extensions from gbpservice.neutron.extensions import group_policy as gpex from gbpservice.neutron.services.grouppolicy import ( extension_manager as ext_manager) @@ -118,13 +118,6 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin): 'policy_target_group'}, 'application_policy_group': {} } - _plurals = None - - @property - def plurals(self): - if not self._plurals: - self._plurals = dict((nattr.PLURALS[k], k) for k in nattr.PLURALS) - return self._plurals @staticmethod def _validate_shared_create(self, context, obj, identity): @@ -137,7 +130,7 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin): ids = [ids] ref_type = links[attr] linked_objects = getattr( - self, 'get_%s' % self.plurals[ref_type])( + self, 'get_%s' % gbp_extensions.get_plural(ref_type))( context, filters={'id': ids}) link_ids = set() for linked in linked_objects: diff --git a/gbpservice/neutron/services/servicechain/plugins/sharing.py b/gbpservice/neutron/services/servicechain/plugins/sharing.py index 82266067f..581ccd672 100644 --- a/gbpservice/neutron/services/servicechain/plugins/sharing.py +++ b/gbpservice/neutron/services/servicechain/plugins/sharing.py @@ -10,7 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.api.v2 import attributes as nattr from neutron import manager as n_manager from neutron.plugins.common import constants as pconst from oslo_log import log as logging @@ -36,13 +35,6 @@ class SharingMixin(object): 'servicechain_instance': {}, 'service_profile': {}, } - _plurals = None - - @property - def plurals(self): - if not self._plurals: - self._plurals = dict((nattr.PLURALS[k], k) for k in nattr.PLURALS) - return self._plurals @property def gbp_plugin(self):