Fix MonitorMetric obj_make_compatible

The 'obj_make_compatible' method of MonitorMetric object
doesn't work properly because conditional expression is not correct.
So fix it and add a unit test for it.

Change-Id: I9e5e8b975195b8120e6c10398c284d6a2f5efab9
Closes-Bug: #1617859
This commit is contained in:
Takashi NATSUME 2016-08-29 10:24:20 +09:00
parent dee72f44fe
commit c651572d5a
2 changed files with 13 additions and 1 deletions

View File

@ -49,7 +49,7 @@ class MonitorMetric(base.NovaObject):
super(MonitorMetric, self).obj_make_compatible(primitive,
target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'numa_nodes_values' in primitive:
if target_version < (1, 1) and 'numa_membw_values' in primitive:
del primitive['numa_membw_values']
# NOTE(jaypipes): This method exists to convert the object to the

View File

@ -85,6 +85,18 @@ class _TestMonitorMetricObject(object):
exp = spec['value'] * 100
self.assertEqual(exp, metric.value)
def test_obj_make_compatible(self):
monitormetric_obj = objects.MonitorMetric(
name=fields.MonitorMetricType.NUMA_MEM_BW_CURRENT,
numa_membw_values={"0": 10, "1": 43},
timestamp=_ts_now.isoformat(),
source='nova.virt.libvirt.driver')
primitive = monitormetric_obj.obj_to_primitive()
self.assertIn('numa_membw_values', primitive['nova_object.data'])
monitormetric_obj.obj_make_compatible(primitive['nova_object.data'],
'1.0')
self.assertNotIn('numa_membw_values', primitive['nova_object.data'])
class TestMonitorMetricObject(test_objects._LocalTest,
_TestMonitorMetricObject):