Add missing compat routine for Usage object

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
This commit is contained in:
Dan Smith 2016-10-22 23:20:49 -07:00
parent 6465e3f3d8
commit 7e36553fa1
2 changed files with 17 additions and 0 deletions

View 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:

View 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')