Expose register_objects function to register all known objects

This can be used directly instead of an ugly recursive import request.

Change-Id: I8fef9fcabc8e0d9f8ade8b41b788f1be71aa1c36
This commit is contained in:
Ihar Hrachyshka 2017-03-07 04:03:27 +00:00
parent a457949bf7
commit c62445d97a
3 changed files with 24 additions and 8 deletions

View File

@ -0,0 +1,19 @@
# 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 sys
def register_objects():
# local import to avoid circular import failure
from neutron.common import utils
utils.import_modules_recursively(sys.modules[__name__].__file__)

View File

@ -13,7 +13,6 @@
import collections
import copy
import itertools
import os.path
import random
import mock
@ -30,7 +29,6 @@ from oslo_versionedobjects import fixture
import testtools
from neutron.common import constants
from neutron.common import utils
from neutron.db import _model_query as model_query
from neutron.db.models import l3 as l3_model
from neutron.db import standard_attr
@ -494,7 +492,7 @@ class _BaseObjectTestCase(object):
# neutron.objects.db.api from core plugin instance
self.setup_coreplugin(self.CORE_PLUGIN)
# make sure all objects are loaded and registered in the registry
utils.import_modules_recursively(os.path.dirname(objects.__file__))
objects.register_objects()
self.context = context.get_admin_context()
self._unique_tracker = collections.defaultdict(set)
self.db_objs = [
@ -652,10 +650,10 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
'is_shared_with_tenant', return_value=False).start()
def fake_get_object(self, context, model, **kwargs):
objects = self.model_map[model]
if not objects:
objs = self.model_map[model]
if not objs:
return None
return [obj for obj in objects if obj['id'] == kwargs['id']][0]
return [obj for obj in objs if obj['id'] == kwargs['id']][0]
def fake_get_objects(self, context, model, **kwargs):
return self.model_map[model]

View File

@ -18,7 +18,6 @@ import pprint
from oslo_versionedobjects import base as obj_base
from oslo_versionedobjects import fixture
from neutron.common import utils
from neutron import objects
from neutron.tests import base as test_base
@ -91,7 +90,7 @@ class TestObjectVersions(test_base.BaseTestCase):
super(TestObjectVersions, self).setUp()
# NOTE(ihrachys): seed registry with all objects under neutron.objects
# before validating the hashes
utils.import_modules_recursively(os.path.dirname(objects.__file__))
objects.register_objects()
def test_versions(self):
checker = fixture.ObjectVersionChecker(