From 100491cec72ecf694cc8cbd6cd17b66a191a5bd7 Mon Sep 17 00:00:00 2001 From: Boden R Date: Fri, 1 Jun 2018 14:03:45 -0600 Subject: [PATCH] use object utils from neutron-lib The neutron.object.utils module was rehomed into neutron-lib with https://review.openstack.org/#/c/557809/ This patch consumes it by removing the neutron.objects.utils module and corresponding test module, updating the contributor internals for objects and using lib's version of the module. NeutronLibImpact Change-Id: If53d0ad660851275462d2641ed1829cdb4c32d05 --- .../contributor/internals/objects_usage.rst | 6 +- neutron/db/_model_query.py | 2 +- neutron/objects/agent.py | 2 +- neutron/objects/db/api.py | 2 +- neutron/objects/utils.py | 60 ------------------- neutron/tests/unit/objects/db/test_api.py | 2 +- neutron/tests/unit/objects/test_base.py | 2 +- neutron/tests/unit/objects/test_utils.py | 52 ---------------- 8 files changed, 8 insertions(+), 120 deletions(-) delete mode 100644 neutron/objects/utils.py delete mode 100644 neutron/tests/unit/objects/test_utils.py diff --git a/doc/source/contributor/internals/objects_usage.rst b/doc/source/contributor/internals/objects_usage.rst index 62798d517bd..5f6f4b50ee4 100644 --- a/doc/source/contributor/internals/objects_usage.rst +++ b/doc/source/contributor/internals/objects_usage.rst @@ -72,7 +72,7 @@ using example of DNSNameServer: # will return list of all dns name servers from DB # for fetching objects with substrings in a string field: - from neutron.objects import utils as obj_utils + from neutron_lib.objects import utils as obj_utils dnses = DNSNameServer.get_objects(context, address=obj_utils.StringContains('10.0.0')) # will return list of all dns name servers from DB that has '10.0.0' in their addresses @@ -668,7 +668,7 @@ objects :code:`get_objects()` method, for example: return subnet_obj.Subnet.get_objects(context, **filters) The :code:`convert_filters` method is available in -``neutron.objects.utils`` [#]_. +``neutron_lib.objects.utils`` [#]_. References ---------- @@ -678,4 +678,4 @@ References .. [#] https://git.openstack.org/cgit/openstack/neutron/tree/neutron/objects/base.py?h=stable/ocata#n542 .. [#] https://docs.openstack.org/neutron/latest/contributor/internals/db_layer.html#the-standard-attribute-table .. [#] https://git.openstack.org/cgit/openstack/neutron/tree/neutron/objects/rbac_db.py?h=stable/ocata#n291 -.. [#] https://git.openstack.org/cgit/openstack/neutron/tree/neutron/objects/utils.py?h=stable/ocata +.. [#] https://git.openstack.org/cgit/openstack/neutron-lib/tree/neutron_lib/objects/utils.py diff --git a/neutron/db/_model_query.py b/neutron/db/_model_query.py index 8e196eb8a8a..e621ed871e6 100644 --- a/neutron/db/_model_query.py +++ b/neutron/db/_model_query.py @@ -18,13 +18,13 @@ NOTE: This module shall not be used by external projects. It will be moved from neutron_lib.api import attributes from neutron_lib.db import utils as db_utils +from neutron_lib.objects import utils as obj_utils from neutron_lib.utils import helpers from oslo_db.sqlalchemy import utils as sa_utils from sqlalchemy import sql, or_, and_ from sqlalchemy.ext import associationproxy from neutron.db import _utils as ndb_utils -from neutron.objects import utils as obj_utils # Classes implementing extensions will register hooks into this dictionary # for "augmenting" the "core way" of building a query for retrieving objects diff --git a/neutron/objects/agent.py b/neutron/objects/agent.py index 73cebfea6a2..40009e83e36 100644 --- a/neutron/objects/agent.py +++ b/neutron/objects/agent.py @@ -13,6 +13,7 @@ # under the License. from neutron_lib import constants as const +from neutron_lib.objects import utils as obj_utils from oslo_versionedobjects import fields as obj_fields from sqlalchemy import func @@ -23,7 +24,6 @@ from neutron.db.models import l3ha as l3ha_model from neutron.db import models_v2 from neutron.objects import base from neutron.objects import common_types -from neutron.objects import utils as obj_utils @base.NeutronObjectRegistry.register diff --git a/neutron/objects/db/api.py b/neutron/objects/db/api.py index 3053ebc300d..d5004d34371 100644 --- a/neutron/objects/db/api.py +++ b/neutron/objects/db/api.py @@ -14,10 +14,10 @@ # backends from neutron_lib import exceptions as n_exc +from neutron_lib.objects import utils as obj_utils from oslo_utils import uuidutils from neutron.db import _model_query as model_query -from neutron.objects import utils as obj_utils # Common database operation implementations diff --git a/neutron/objects/utils.py b/neutron/objects/utils.py deleted file mode 100644 index d761ddf4dd3..00000000000 --- a/neutron/objects/utils.py +++ /dev/null @@ -1,60 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from neutron.common import exceptions - - -def convert_filters(**kwargs): - result = copy.deepcopy(kwargs) - if 'tenant_id' in result: - if 'project_id' in result: - raise exceptions.TenantIdProjectIdFilterConflict() - - result['project_id'] = result.pop('tenant_id') - return result - - -class StringMatchingFilterObj(object): - @property - def is_contains(self): - return bool(getattr(self, "contains", False)) - - @property - def is_starts(self): - return bool(getattr(self, "starts", False)) - - @property - def is_ends(self): - return bool(getattr(self, "ends", False)) - - -class StringContains(StringMatchingFilterObj): - - def __init__(self, matching_string): - super(StringContains, self).__init__() - self.contains = matching_string - - -class StringStarts(StringMatchingFilterObj): - - def __init__(self, matching_string): - super(StringStarts, self).__init__() - self.starts = matching_string - - -class StringEnds(StringMatchingFilterObj): - - def __init__(self, matching_string): - super(StringEnds, self).__init__() - self.ends = matching_string diff --git a/neutron/tests/unit/objects/db/test_api.py b/neutron/tests/unit/objects/db/test_api.py index da91546b30e..3fbda6b58e8 100644 --- a/neutron/tests/unit/objects/db/test_api.py +++ b/neutron/tests/unit/objects/db/test_api.py @@ -15,12 +15,12 @@ import copy import mock from neutron_lib import context from neutron_lib import exceptions as n_exc +from neutron_lib.objects import utils as obj_utils from neutron.db import _model_query as model_query from neutron.objects import base from neutron.objects.db import api from neutron.objects import network -from neutron.objects import utils as obj_utils from neutron.tests import base as test_base from neutron.tests.unit import testlib_api diff --git a/neutron/tests/unit/objects/test_base.py b/neutron/tests/unit/objects/test_base.py index 277942842fb..b037e9c7b36 100644 --- a/neutron/tests/unit/objects/test_base.py +++ b/neutron/tests/unit/objects/test_base.py @@ -22,6 +22,7 @@ from neutron_lib import constants from neutron_lib import context from neutron_lib import exceptions as n_exc from neutron_lib.objects import exceptions as o_exc +from neutron_lib.objects import utils as obj_utils from neutron_lib.utils import helpers from oslo_db import exception as obj_exc from oslo_db.sqlalchemy import utils as db_utils @@ -48,7 +49,6 @@ from neutron.objects import router from neutron.objects import securitygroup from neutron.objects import stdattrs from neutron.objects import subnet -from neutron.objects import utils as obj_utils from neutron.tests import base as test_base from neutron.tests import tools from neutron.tests.unit.db import test_db_base_plugin_v2 diff --git a/neutron/tests/unit/objects/test_utils.py b/neutron/tests/unit/objects/test_utils.py deleted file mode 100644 index 84f1d88d43a..00000000000 --- a/neutron/tests/unit/objects/test_utils.py +++ /dev/null @@ -1,52 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.common import exceptions -from neutron.objects import utils -from neutron.tests import base as test_base - - -class TestConvertFilters(test_base.BaseTestCase): - - def test_convert_filters_no_tenant_id(self): - kwargs = { - 'filter%d' % i: 'value%d' % i - for i in range(0, 10) - } - self.assertEqual(kwargs, utils.convert_filters(**kwargs)) - - def test_convert_filters_tenant_id(self): - expected_project_id = 'fake-tenant-id' - kwargs = { - 'filter%d' % i: 'value%d' % i - for i in range(0, 10) - } - expected = kwargs.copy() - expected['project_id'] = expected_project_id - - self.assertEqual( - expected, - utils.convert_filters(tenant_id=expected_project_id, **kwargs) - ) - - def test_convert_filters_tenant_id_and_project_id_raises(self): - kwargs = { - 'filter%d' % i: 'value%d' % i - for i in range(0, 10) - } - kwargs['tenant_id'] = 'fake-tenant-id' - kwargs['project_id'] = 'fake-tenant-id' - - self.assertRaises( - exceptions.TenantIdProjectIdFilterConflict, - utils.convert_filters, **kwargs - )