@obj_base.VersionedObjectRegistry.register
class QosPolicy(base.NeutronDbObject):
+ # Version 1.0: Initial version
+ VERSION = '1.0'
db_model = qos_db_model.QosPolicy
@obj_base.VersionedObjectRegistry.register
class QosBandwidthLimitRule(QosRule):
+ # Version 1.0: Initial version
+ VERSION = '1.0'
db_model = qos_db_model.QosBandwidthLimitRule
@obj_base.VersionedObjectRegistry.register
class QosRuleType(base.NeutronObject):
+ # Version 1.0: Initial version
+ VERSION = '1.0'
fields = {
'type': RuleTypeField(),
# See the License for the specific language governing permissions and
# limitations under the License.
+import copy
+
import mock
from oslo_versionedobjects import base as obj_base
from oslo_versionedobjects import fields as obj_fields
return resource
-@obj_base.VersionedObjectRegistry.register
class FakeResource(objects_base.NeutronObject):
+ # Version 1.0: Initial version
+ VERSION = '1.0'
fields = {
'id': obj_fields.UUIDField(),
def setUp(self):
super(ResourcesRpcBaseTestCase, self).setUp()
+
+ # TODO(mhickey) This is using temp registry pattern. The
+ # pattern solution is to backup the object registry, register
+ # a class locally, and then restore the original registry.
+ # Refer to https://review.openstack.org/#/c/263800/ for more
+ # details. This code should be updated when the patch is merged.
+ self._base_test_backup = copy.copy(
+ obj_base.VersionedObjectRegistry._registry._obj_classes)
+ self.addCleanup(self._restore_obj_registry)
+
self.context = context.get_admin_context()
+ def _restore_obj_registry(self):
+ obj_base.VersionedObjectRegistry._registry._obj_classes = (
+ self._base_test_backup)
+
class _ValidateResourceTypeTestCase(base.BaseTestCase):
def setUp(self):
self.assertIs(self.rpc, resources_rpc.ResourcesPullRpcApi())
def test_pull(self):
+ obj_base.VersionedObjectRegistry.register(FakeResource)
expected_obj = _create_test_resource(self.context)
resource_id = expected_obj.id
self.cctxt_mock.call.return_value = expected_obj.obj_to_primitive()
def setUp(self):
super(ResourcesPullRpcCallbackTestCase, self).setUp()
+ obj_base.VersionedObjectRegistry.register(FakeResource)
self.callbacks = resources_rpc.ResourcesPullRpcCallback()
self.resource_obj = _create_test_resource(self.context)
@mock.patch.object(resources_rpc.cons_registry, 'push')
def test_push(self, reg_push_mock):
+ obj_base.VersionedObjectRegistry.register(FakeResource)
self.callbacks.push(self.context, self.resource_prim, 'TYPE')
reg_push_mock.assert_called_once_with(self.resource_obj.obj_name(),
self.resource_obj, 'TYPE')
pass
-@obj_base.VersionedObjectRegistry.register
+@obj_base.VersionedObjectRegistry.register_if(False)
class FakeNeutronObject(base.NeutronDbObject):
+ # Version 1.0: Initial version
+ VERSION = '1.0'
db_model = FakeModel
--- /dev/null
+# Copyright 2015 IBM Corp.
+#
+# 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 os
+import pprint
+
+from oslo_versionedobjects import base as obj_base
+from oslo_versionedobjects import fixture
+
+from neutron.tests import base as test_base
+
+
+# NOTE: The hashes in this list should only be changed if they come with a
+# corresponding version bump in the affected objects.
+object_data = {
+ 'QosBandwidthLimitRule': '1.0-4e44a8f5c2895ab1278399f87b40a13d',
+ 'QosRuleType': '1.0-d0df298d49eeffab91af18d1a4cf7eaf',
+ 'QosPolicy': '1.0-721fa60ea8f0e8f15d456d6e917dfe59',
+}
+
+
+class TestObjectVersions(test_base.BaseTestCase):
+
+ def test_versions(self):
+ checker = fixture.ObjectVersionChecker(
+ obj_base.VersionedObjectRegistry.obj_classes())
+ fingerprints = checker.get_hashes()
+
+ if os.getenv('GENERATE_HASHES'):
+ file('object_hashes.txt', 'w').write(
+ pprint.pformat(fingerprints))
+
+ expected, actual = checker.test_hashes(object_data)
+ self.assertEqual(expected, actual,
+ 'Some objects have changed; please make sure the '
+ 'versions have been bumped, and then update their '
+ 'hashes in the object_data map in this test module.')
# The following vendor plugins are not required to confrm to the
# structural requirements.
"^plugins/ibm.*$"
+ # The following test is required for oslo.versionedobjects
+ "^objects/test_objects.py$"
# The following open source plugin tests are not actually unit
# tests and are ignored pending their relocation to the functional
# test tree.
[testenv]
setenv = VIRTUAL_ENV={envdir}
-passenv = TRACE_FAILONLY
+passenv = TRACE_FAILONLY GENERATE_HASHES
usedevelop = True
install_command =
constraints: {[testenv:common-constraints]install_command}