Revert "Squash revert to breaking changes"
This reverts commit b0fd58800a
.
NeutronLibImpact
Change-Id: I3c1eb9ff07ad2db458b3a83a19c7fcaa7df3f449
This commit is contained in:
parent
e004c925f2
commit
ced332ceea
|
@ -1,35 +0,0 @@
|
|||
# Copyright (c) 2012 OpenStack Foundation.
|
||||
#
|
||||
# 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_lib.db import model_base as lib_mb
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron.common import _deprecate
|
||||
|
||||
|
||||
_deprecate._moved_global('HasTenant', new_module=lib_mb, new_name='HasProject')
|
||||
|
||||
|
||||
def get_unique_keys(model):
|
||||
try:
|
||||
constraints = model.__table__.constraints
|
||||
except AttributeError:
|
||||
constraints = []
|
||||
return [[c.name for c in constraint.columns]
|
||||
for constraint in constraints
|
||||
if isinstance(constraint, sa.UniqueConstraint)]
|
||||
|
||||
# This shim is used to deprecate the old contents.
|
||||
_deprecate._MovedGlobals(lib_mb)
|
|
@ -18,6 +18,7 @@ import itertools
|
|||
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from oslo_db import exception as obj_exc
|
||||
from oslo_db.sqlalchemy import utils as db_utils
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
|
@ -26,7 +27,6 @@ import six
|
|||
from neutron._i18n import _
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import model_base
|
||||
from neutron.db import standard_attr
|
||||
from neutron.objects.db import api as obj_db_api
|
||||
from neutron.objects import exceptions as o_exc
|
||||
|
@ -240,7 +240,8 @@ class DeclarativeObject(abc.ABCMeta):
|
|||
model_to_obj_translation = {
|
||||
v: k for (k, v) in cls.fields_need_translation.items()}
|
||||
|
||||
for model_unique_key in model_base.get_unique_keys(model):
|
||||
keys = db_utils.get_unique_keys(model) or []
|
||||
for model_unique_key in keys:
|
||||
obj_unique_key = [model_to_obj_translation.get(key, key)
|
||||
for key in model_unique_key]
|
||||
if obj_field_names.issuperset(obj_unique_key):
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
# Copyright (c) 2016 Mirantis, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 mock
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron.db import model_base
|
||||
from neutron.tests import base as test_base
|
||||
|
||||
|
||||
class GetUniqueKeysTestCase(test_base.BaseTestCase):
|
||||
|
||||
def test_with_unique_constraints(self):
|
||||
model = mock.Mock()
|
||||
metadata = sa.MetaData()
|
||||
model.__table__ = sa.Table(
|
||||
"test_table", metadata,
|
||||
sa.Column("a", sa.Integer, unique=True),
|
||||
sa.Column("b", sa.Integer),
|
||||
sa.Column("c", sa.Integer),
|
||||
sa.Column("d", sa.Integer),
|
||||
sa.UniqueConstraint("c", "d"))
|
||||
expected = {("a",), ("c", "d")}
|
||||
observed = {tuple(sorted(key)) for key in
|
||||
model_base.get_unique_keys(model)}
|
||||
self.assertEqual(expected, observed)
|
||||
|
||||
def test_without_unique_constraints(self):
|
||||
model = mock.Mock()
|
||||
metadata = sa.MetaData()
|
||||
model.__table__ = sa.Table(
|
||||
"test_table", metadata,
|
||||
sa.Column("a", sa.Integer),
|
||||
sa.Column("b", sa.Integer))
|
||||
self.assertEqual([], model_base.get_unique_keys(model))
|
||||
|
||||
def test_not_a_model(self):
|
||||
self.assertEqual([], model_base.get_unique_keys(None))
|
|
@ -20,6 +20,7 @@ import mock
|
|||
import netaddr
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from oslo_db import exception as obj_exc
|
||||
from oslo_db.sqlalchemy import utils as db_utils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
|
@ -31,7 +32,6 @@ from neutron.common import constants
|
|||
from neutron.common import utils
|
||||
from neutron import context
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import model_base
|
||||
from neutron.db.models import external_net as ext_net_model
|
||||
from neutron.db.models import l3 as l3_model
|
||||
from neutron.db import standard_attr
|
||||
|
@ -661,7 +661,7 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
|
|||
self.assertTrue(self._is_test_class(obj))
|
||||
self._check_equal(self.objs[0], obj)
|
||||
get_object_mock.assert_called_once_with(
|
||||
self.context, self._test_class.db_model,
|
||||
mock.ANY, self._test_class.db_model,
|
||||
**self._test_class.modify_fields_to_db(obj_keys))
|
||||
|
||||
def _get_synthetic_fields_get_objects_calls(self, db_objs):
|
||||
|
@ -1019,7 +1019,7 @@ class BaseDbObjectUniqueKeysTestCase(BaseObjectIfaceTestCase):
|
|||
class UniqueKeysTestCase(test_base.BaseTestCase):
|
||||
|
||||
def test_class_creation(self):
|
||||
m_get_unique_keys = mock.patch.object(model_base, 'get_unique_keys')
|
||||
m_get_unique_keys = mock.patch.object(db_utils, 'get_unique_keys')
|
||||
with m_get_unique_keys as get_unique_keys:
|
||||
get_unique_keys.return_value = [['field1'],
|
||||
['field2', 'db_field3']]
|
||||
|
|
Loading…
Reference in New Issue