From 74bd3b18659daf7571f8addbd870b48e614e1f73 Mon Sep 17 00:00:00 2001 From: Lin Tan Date: Wed, 25 Nov 2015 15:49:05 +0800 Subject: Add a test to enforce object version bump correctly Add a test to help developers to check if the change of objects need a version bump. Any changes of object fields or remotable methods need to bump its version. Use oslo_versionobjects to generate the hashes and compare with a pre-define hash map. Change-Id: I5c12ab72937f05ba46eb58d049f9b7fc7c806218 Closes-Bug: 1502895 Implements: blueprint online-upgrade-support --- ironic/tests/unit/objects/test_objects.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ironic/tests/unit/objects/test_objects.py b/ironic/tests/unit/objects/test_objects.py index 1cb67fe26..7a2b2cc94 100644 --- a/ironic/tests/unit/objects/test_objects.py +++ b/ironic/tests/unit/objects/test_objects.py @@ -21,6 +21,7 @@ import mock from oslo_context import context from oslo_versionedobjects import base as object_base from oslo_versionedobjects import exception as object_exception +from oslo_versionedobjects import fixture as object_fixture import six from ironic.objects import base @@ -416,6 +417,33 @@ class TestObject(_LocalTest, _TestObject): pass +# The hashes are help developers to check if the change of objects need a +# version bump. It is md5 hash of object fields and remotable methods. +# The fingerprint values should only be changed if there is a version bump. +expected_object_fingerprints = { + 'Node': '1.14-9ee8ab283b06398545880dfdedb49891', + 'MyObj': '1.5-4f5efe8f0fcaf182bbe1c7fe3ba858db', + 'Chassis': '1.3-d656e039fd8ae9f34efc232ab3980905', + 'Port': '1.4-f5aa3ff81d1459d6d7e6d9d9dceed351', + 'Conductor': '1.0-5091f249719d4a465062a1b3dc7f860d' +} + + +class TestObjectVersions(test_base.TestCase): + + def test_object_version_check(self): + classes = base.IronicObjectRegistry.obj_classes() + checker = object_fixture.ObjectVersionChecker(obj_classes=classes) + # Compute the difference between actual fingerprints and + # expect fingerprints. expect = actual = {} if there is no change. + expect, actual = checker.test_hashes(expected_object_fingerprints) + self.assertEqual(expect, actual, + "Some objects fields or remotable methods have been " + "modified. Please make sure the version of those " + "objects have been bumped and then update " + "expected_object_fingerprints with the new hashes. ") + + class TestObjectSerializer(test_base.TestCase): def test_object_serialization(self): -- cgit v1.2.1