]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Add missing compat routine for Usage object
authorDan Smith <dansmith@redhat.com>
Sun, 23 Oct 2016 06:20:49 +0000 (23:20 -0700)
committerDan Smith <dansmith@redhat.com>
Sun, 23 Oct 2016 06:22:26 +0000 (23:22 -0700)
We added a v1.1 to Usage without a compat routine to go with it. It's not really
a big deal as we're not sending this over RPC anywhere yet that I know of, but
we should have this for the sake of completeness.

Change-Id: Ia50448741b29e1c33e4988a9476418b6ba835983

nova/objects/resource_provider.py
nova/tests/unit/objects/test_resource_provider.py

index 30dc71e208011d14afe26984b636ff154fc939ff..7d0f460907f78b7c2f9abb981560c6ab211f7399 100644 (file)
@@ -937,6 +937,13 @@ class Usage(base.NovaObject):
         'usage': fields.NonNegativeIntegerField(),
     }
 
+    def obj_make_compatible(self, primitive, target_version):
+        super(Usage, self).obj_make_compatible(primitive, target_version)
+        target_version = versionutils.convert_version_to_tuple(target_version)
+        if target_version < (1, 1) and 'resource_class' in primitive:
+            rc = primitive['resource_class']
+            rc_cache.raise_if_custom_resource_class_pre_v1_1(rc)
+
     @staticmethod
     def _from_db_object(context, target, source):
         for field in target.fields:
index bd0ba3ccc46b4ce54cb3034a9fa06a98a64be5d7..75e2c01e9691208cc2a2d61c46d284be7c1fcb04 100644 (file)
@@ -541,3 +541,13 @@ class TestAllocationListNoDB(test_objects._LocalTest,
 class TestRemoteAllocationListNoDB(test_objects._RemoteTest,
                                _TestAllocationListNoDB):
     USES_DB = False
+
+
+class TestUsageNoDB(test_objects._LocalTest):
+    USES_DB = False
+
+    def test_v1_1_resource_class(self):
+        usage = objects.Usage(resource_class='foo')
+        self.assertRaises(ValueError,
+                          usage.obj_to_primitive,
+                          target_version='1.0')