From: Matt Riedemann Date: Tue, 10 Nov 2015 20:55:46 +0000 (-0800) Subject: Test for object version hash changes X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=17cc592c68cb94461c6377dd5049fc300227844a;p=openstack-build%2Fcinder-build.git Test for object version hash changes Use the ObjectVersionChecker fixture from oslo.versionedobjects to check when Cinder's registered objects have a change (new remotable method, new field, etc) that require a version bump. Fixes some registration problems along the way: 1. CinderObject doesn't need to be registered. 2. TestObject should be registered where it's used, not globally. Removes deps=requirements.txt from tox.ini since it's not necessary and prevents us from pip installing oslo.versionedobjects[fixtures]. Closes-Bug: #1514926 Change-Id: Id57c56a75ea11411e9e54104165bd44b577c1485 --- diff --git a/cinder/objects/base.py b/cinder/objects/base.py index 8353cee45..cb41dbc34 100644 --- a/cinder/objects/base.py +++ b/cinder/objects/base.py @@ -36,7 +36,6 @@ class CinderObjectRegistry(base.VersionedObjectRegistry): setattr(objects, cls.obj_name(), cls) -@CinderObjectRegistry.register class CinderObject(base.VersionedObject): # NOTE(thangp): OBJ_PROJECT_NAMESPACE needs to be set so that nova, # cinder, and other objects can exist on the same bus and be distinguished diff --git a/cinder/test.py b/cinder/test.py index a06e44394..75b7d53e0 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -21,6 +21,7 @@ inline callbacks. """ +import copy import logging import os import shutil @@ -42,6 +43,7 @@ from cinder.common import config # noqa Need to register global_opts from cinder.db import migration from cinder.db.sqlalchemy import api as sqla_api from cinder import i18n +from cinder.objects import base as objects_base from cinder import rpc from cinder import service from cinder.tests.unit import conf_fixture @@ -209,6 +211,14 @@ class TestCase(testtools.TestCase): sqlite_clean_db=CONF.sqlite_clean_db) self.useFixture(_DB_CACHE) + # NOTE(danms): Make sure to reset us back to non-remote objects + # for each test to avoid interactions. Also, backup the object + # registry. + objects_base.CinderObject.indirection_api = None + self._base_test_obj_backup = copy.copy( + objects_base.CinderObjectRegistry._registry._obj_classes) + self.addCleanup(self._restore_obj_registry) + # emulate some of the mox stuff, we can't use the metaclass # because it screws with our generators mox_fixture = self.useFixture(moxstubout.MoxStubout()) @@ -242,6 +252,10 @@ class TestCase(testtools.TestCase): self._disable_osprofiler() + def _restore_obj_registry(self): + objects_base.CinderObjectRegistry._registry._obj_classes = \ + self._base_test_obj_backup + def _disable_osprofiler(self): """Disable osprofiler. diff --git a/cinder/tests/unit/objects/test_base.py b/cinder/tests/unit/objects/test_base.py index 8f47a488f..50354277c 100644 --- a/cinder/tests/unit/objects/test_base.py +++ b/cinder/tests/unit/objects/test_base.py @@ -22,7 +22,7 @@ from cinder.objects import base from cinder.tests.unit import objects as test_objects -@base.CinderObjectRegistry.register +@base.CinderObjectRegistry.register_if(False) class TestObject(base.CinderObject): fields = { 'scheduled_at': base.fields.DateTimeField(nullable=True), diff --git a/cinder/tests/unit/objects/test_objects.py b/cinder/tests/unit/objects/test_objects.py new file mode 100644 index 000000000..030229c4a --- /dev/null +++ b/cinder/tests/unit/objects/test_objects.py @@ -0,0 +1,53 @@ +# 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. + +from oslo_versionedobjects import fixture + +from cinder.objects import base +from cinder import test + + +# NOTE: The hashes in this list should only be changed if they come with a +# corresponding version bump in the affected objects. +object_data = { + 'Backup': '1.1-f2e7befd20d3bb388700f17c4f386b28', + 'BackupImport': '1.1-f2e7befd20d3bb388700f17c4f386b28', + 'BackupList': '1.0-db44728c8d21bb23bba601a5499550f8', + 'CGSnapshot': '1.0-d50e9480cee2abcb2222997f2bb85656', + 'CGSnapshotList': '1.0-3361be608f396c5ae045b6d94f901346', + 'ConsistencyGroup': '1.0-98714c3d8f83914fd7a17317c3c29e01', + 'ConsistencyGroupList': '1.0-a906318d3e69d847f31df561d12540b3', + 'Service': '1.0-b81a04373ce0ad2d07de525eb534afd6', + 'ServiceList': '1.0-1911175eadd43fb6eafbefd18c802f2c', + 'Snapshot': '1.0-54a2726a282cbdb47ddd326107e821ce', + 'SnapshotList': '1.0-46abf2a1e65ef55dad4f36fe787f9a78', + 'Volume': '1.1-adc26d52b646723bd0633b0771ad2598', + 'VolumeAttachment': '1.0-4fd93dbfa57d048a4859f5bb1ca66bed', + 'VolumeAttachmentList': '1.0-829c18b1d929ea1f8a451b3c4e0a0289', + 'VolumeList': '1.1-d41f3a850be5fbaa94eb4cc955c7ca60', + 'VolumeType': '1.0-8cb7daad27570133543c2c359d85c658', + 'VolumeTypeList': '1.0-980f0b518aed9df0beb55cc533eff632' +} + + +class TestObjectVersions(test.TestCase): + + def test_versions(self): + checker = fixture.ObjectVersionChecker( + base.CinderObjectRegistry.obj_classes()) + 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.') diff --git a/tox.ini b/tox.ini index a2bb71ef9..e14b77051 100644 --- a/tox.ini +++ b/tox.ini @@ -13,8 +13,10 @@ install_command = constraints: {[testenv:common-constraints]install_command} pip install {opts} {packages} -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt +# TODO(mriedem): Move oslo.versionedobjects[fixtures] to test-requirements.txt +# after I937823ffeb95725f0b55e298ebee1857d6482883 lands. +deps = -r{toxinidir}/test-requirements.txt + oslo.versionedobjects[fixtures] # By default ostestr will set concurrency # to ncpu, to specify something else use