Merge "use object standardattributes from neutron-lib"
This commit is contained in:
@@ -19,6 +19,7 @@ import itertools
|
|||||||
from neutron_lib.db import api as db_api
|
from neutron_lib.db import api as db_api
|
||||||
from neutron_lib import exceptions as n_exc
|
from neutron_lib import exceptions as n_exc
|
||||||
from neutron_lib.objects import exceptions as o_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 import exception as obj_exc
|
||||||
from oslo_db.sqlalchemy import enginefacade
|
from oslo_db.sqlalchemy import enginefacade
|
||||||
from oslo_db.sqlalchemy import utils as db_utils
|
from oslo_db.sqlalchemy import utils as db_utils
|
||||||
@@ -34,7 +35,6 @@ from sqlalchemy import orm
|
|||||||
from neutron._i18n import _
|
from neutron._i18n import _
|
||||||
from neutron.db import standard_attr
|
from neutron.db import standard_attr
|
||||||
from neutron.objects.db import api as obj_db_api
|
from neutron.objects.db import api as obj_db_api
|
||||||
from neutron.objects.extensions import standardattributes
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|||||||
@@ -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")
|
|
||||||
@@ -10,11 +10,11 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from neutron_lib.objects.extensions import standardattributes as stdattr_obj
|
||||||
from oslo_versionedobjects import fields as obj_fields
|
from oslo_versionedobjects import fields as obj_fields
|
||||||
|
|
||||||
from neutron.db import standard_attr
|
from neutron.db import standard_attr
|
||||||
from neutron.objects import base
|
from neutron.objects import base
|
||||||
from neutron.objects.extensions import standardattributes as stdattr_obj
|
|
||||||
|
|
||||||
|
|
||||||
# TODO(ihrachys): add unit tests for the object
|
# TODO(ihrachys): add unit tests for the object
|
||||||
|
|||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user