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
This commit is contained in:
parent
ce8b73ba87
commit
100491cec7
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
)
|
Loading…
Reference in New Issue
Block a user