Merge "Allow empty CPU info of hypervisors in API response"

This commit is contained in:
Jenkins 2016-08-27 01:02:27 +00:00 committed by Gerrit Code Review
commit a5cc0be5c6
2 changed files with 32 additions and 1 deletions

View File

@ -69,7 +69,10 @@ class HypervisorsController(wsgi.Controller):
}
if api_version_request.is_supported(req, min_version='2.28'):
hyp_dict['cpu_info'] = jsonutils.loads(hypervisor.cpu_info)
if hypervisor.cpu_info:
hyp_dict['cpu_info'] = jsonutils.loads(hypervisor.cpu_info)
else:
hyp_dict['cpu_info'] = {}
else:
hyp_dict['cpu_info'] = hypervisor.cpu_info

View File

@ -200,6 +200,7 @@ class HypervisorsTestV21(test.NoDBTestCase):
state='up', status='enabled'),
dict(id=2, hypervisor_hostname="hyper2",
state='up', status='enabled')]
DETAIL_NULL_CPUINFO_DICT = {'': '', None: None}
def _get_request(self, use_admin_context, url=''):
return fakes.HTTPRequest.blank(url,
@ -256,6 +257,26 @@ class HypervisorsTestV21(test.NoDBTestCase):
self.assertEqual(result, expected_dict)
def _test_view_hypervisor_detail_cpuinfo_null(self, cpu_info):
req = self._get_request(True)
test_hypervisor_obj = copy.deepcopy(self.TEST_HYPERS_OBJ[0])
test_hypervisor_obj.cpu_info = cpu_info
result = self.controller._view_hypervisor(test_hypervisor_obj,
self.TEST_SERVICES[0],
True, req)
expected_dict = copy.deepcopy(self.DETAIL_HYPERS_DICTS[0])
expected_dict.update({'cpu_info':
self.DETAIL_NULL_CPUINFO_DICT[cpu_info]})
self.assertEqual(result, expected_dict)
def test_view_hypervisor_detail_cpuinfo_empty_string(self):
self._test_view_hypervisor_detail_cpuinfo_null('')
def test_view_hypervisor_detail_cpuinfo_none(self):
self._test_view_hypervisor_detail_cpuinfo_null(None)
def test_index(self):
req = self._get_request(True)
result = self.controller.index(req)
@ -487,6 +508,12 @@ class CellHypervisorsTestV21(HypervisorsTestV21):
hyp['id']))
for hyp in INDEX_HYPER_DICTS]
# __deepcopy__ is added for copying an object locally in
# _test_view_hypervisor_detail_cpuinfo_null
cells_utils.ComputeNodeProxy.__deepcopy__ = (lambda self, memo:
cells_utils.ComputeNodeProxy(copy.deepcopy(self._obj, memo),
self._cell_path))
@classmethod
def fake_compute_node_get_all(cls, context, limit=None, marker=None):
return cls.TEST_HYPERS_OBJ
@ -543,6 +570,7 @@ class HypervisorsTestV228(HypervisorsTestV21):
DETAIL_HYPERS_DICTS = copy.deepcopy(HypervisorsTestV21.DETAIL_HYPERS_DICTS)
DETAIL_HYPERS_DICTS[0]['cpu_info'] = jsonutils.loads(CPU_INFO)
DETAIL_HYPERS_DICTS[1]['cpu_info'] = jsonutils.loads(CPU_INFO)
DETAIL_NULL_CPUINFO_DICT = {'': {}, None: {}}
class HypervisorsTestV233(HypervisorsTestV228):