From bb7fd80c23fd09a43f6cab45044da346ce6ae9e4 Mon Sep 17 00:00:00 2001 From: Boden R Date: Wed, 12 Jun 2019 13:57:00 -0600 Subject: [PATCH] use object standardattributes from neutron-lib This patch switches over to use the standardattributes module from neutron-lib's object extensions by removing the module and its tests from neutron and using it from lib instead. NeutronLibImpact Change-Id: Icbcd17315f9a36b676f730b14fa2bac99c7d00b7 --- neutron/objects/base.py | 2 +- .../objects/extensions/standardattributes.py | 39 -------------- neutron/objects/stdattrs.py | 2 +- .../tests/unit/objects/extensions/__init__.py | 0 .../extensions/test_standardattributes.py | 51 ------------------- 5 files changed, 2 insertions(+), 92 deletions(-) delete mode 100644 neutron/objects/extensions/standardattributes.py delete mode 100644 neutron/tests/unit/objects/extensions/__init__.py delete mode 100644 neutron/tests/unit/objects/extensions/test_standardattributes.py diff --git a/neutron/objects/base.py b/neutron/objects/base.py index 4e98c0affbc..9dd0138dcfe 100644 --- a/neutron/objects/base.py +++ b/neutron/objects/base.py @@ -19,6 +19,7 @@ import itertools from neutron_lib.db import api as db_api from neutron_lib import exceptions as n_exc from neutron_lib.objects import exceptions as o_exc +from neutron_lib.objects.extensions import standardattributes from oslo_db import exception as obj_exc from oslo_db.sqlalchemy import enginefacade from oslo_db.sqlalchemy import utils as db_utils @@ -34,7 +35,6 @@ from sqlalchemy import orm from neutron._i18n import _ from neutron.db import standard_attr from neutron.objects.db import api as obj_db_api -from neutron.objects.extensions import standardattributes LOG = logging.getLogger(__name__) diff --git a/neutron/objects/extensions/standardattributes.py b/neutron/objects/extensions/standardattributes.py deleted file mode 100644 index be9c9639299..00000000000 --- a/neutron/objects/extensions/standardattributes.py +++ /dev/null @@ -1,39 +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 oslo_versionedobjects import fields as obj_fields - -STANDARD_ATTRIBUTES = { - 'revision_number': obj_fields.IntegerField(), - 'description': obj_fields.StringField(nullable=True), - 'created_at': obj_fields.DateTimeField(nullable=True, tzinfo_aware=False), - 'updated_at': obj_fields.DateTimeField(nullable=True, tzinfo_aware=False), -} - - -def add_standard_attributes(cls): - # Don't use parent's fields in case child class doesn't create - # its own instance of list - cls.fields = cls.fields.copy() - cls.fields.update(STANDARD_ATTRIBUTES) - # those fields are updated by sqlalchemy itself - cls.fields_no_update += ('created_at', 'updated_at') - # revision numbers are managed by service plugin and are bumped - # automatically; consumers should not bump them explicitly - cls.fields_no_update.append('revision_number') - - -def add_tag_filter_names(cls): - cls.add_extra_filter_name("tags") - cls.add_extra_filter_name("not-tags") - cls.add_extra_filter_name("tags-any") - cls.add_extra_filter_name("not-tags-any") diff --git a/neutron/objects/stdattrs.py b/neutron/objects/stdattrs.py index faf4611773b..d7a509ba8f0 100644 --- a/neutron/objects/stdattrs.py +++ b/neutron/objects/stdattrs.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.objects.extensions import standardattributes as stdattr_obj from oslo_versionedobjects import fields as obj_fields from neutron.db import standard_attr from neutron.objects import base -from neutron.objects.extensions import standardattributes as stdattr_obj # TODO(ihrachys): add unit tests for the object diff --git a/neutron/tests/unit/objects/extensions/__init__.py b/neutron/tests/unit/objects/extensions/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/neutron/tests/unit/objects/extensions/test_standardattributes.py b/neutron/tests/unit/objects/extensions/test_standardattributes.py deleted file mode 100644 index ee421f9a95f..00000000000 --- a/neutron/tests/unit/objects/extensions/test_standardattributes.py +++ /dev/null @@ -1,51 +0,0 @@ -# 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. - -from neutron_lib.db import model_base -from oslo_versionedobjects import fields as obj_fields -import sqlalchemy as sa - -from neutron.db import standard_attr -from neutron.objects import base as objects_base -from neutron.objects import common_types -from neutron.tests.unit.objects import test_base -from neutron.tests.unit import testlib_api - - -class FakeDbModelWithStandardAttributes( - standard_attr.HasStandardAttributes, model_base.BASEV2): - id = sa.Column(sa.String(36), primary_key=True, nullable=False) - item = sa.Column(sa.String(64)) - api_collections = [] - collection_resource_map = {} - tag_support = False - - -@objects_base.NeutronObjectRegistry.register_if(False) -class FakeObjectWithStandardAttributes(objects_base.NeutronDbObject): - VERSION = '1.0' - db_model = FakeDbModelWithStandardAttributes - fields = { - 'id': common_types.UUIDField(), - 'item': obj_fields.StringField(), - } - - -class HasStandardAttributesDbTestCase(test_base.BaseDbObjectTestCase, - testlib_api.SqlTestCase): - _test_class = FakeObjectWithStandardAttributes - - -class HasStandardAttributesTestCase(test_base.BaseObjectIfaceTestCase): - _test_class = FakeObjectWithStandardAttributes