Skip to content

Commit

Permalink
Merge "Allow empty CPU info of hypervisors in API response"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Aug 27, 2016
2 parents 359d635 + 72fb672 commit a5cc0be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nova/api/openstack/compute/hypervisors.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def _view_hypervisor(self, hypervisor, service, detail, req, servers=None,
}

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

Expand Down
28 changes: 28 additions & 0 deletions nova/tests/unit/api/openstack/compute/test_hypervisors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -256,6 +257,26 @@ def test_view_hypervisor_servers(self):

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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a5cc0be

Please sign in to comment.