Fix v2.1 hypervisor servers to return empty list

In v2.1, os-hypervisors/servers API returns empty servers list in
case where hypervisors does not have any servers.

But this is not case with v2 API. v2 API does not put 'servers' field
in response if it is empty.

v2.1 APIs should be same as v2 in all cases/scenarios.

This is bug fix so not putting as microversions, its just a change to
the v2.1 code so it is equivalent to v2. If later needed then, this can
be reverted back as current ways via microversion.

This was no best test coverage to catch this kind of issue.
This was caught while merging the v2 and v2.1 tests
- I5ddf3c54dd80a67f71762769d6130db41e772b01

Change-Id: I32e5cde65baeca71ec06b814b7db7aa7469eac64
Closes-Bug: #1435668
This commit is contained in:
ghanshyam 2015-03-24 14:33:01 +09:00 committed by Ken'ichi Ohmichi
parent 20c47ea3d5
commit 7f5462777b
4 changed files with 4 additions and 19 deletions

View File

@ -4,8 +4,7 @@
"hypervisor_hostname": "fake-mini",
"id": 1,
"state": "up",
"status": "enabled",
"servers": []
"status": "enabled"
}
]
}

View File

@ -64,7 +64,7 @@ class HypervisorsController(wsgi.Controller):
'disabled_reason': service.disabled_reason,
}
if servers is not None:
if servers:
hyp_dict['servers'] = [dict(name=serv['name'], uuid=serv['uuid'])
for serv in servers]

View File

@ -4,8 +4,7 @@
"hypervisor_hostname": "fake-mini",
"id": 1,
"state": "up",
"status": "enabled",
"servers": []
"status": "enabled"
}
]
}

View File

@ -179,10 +179,6 @@ class HypervisorsTestV21(test.NoDBTestCase):
dict(id=2, hypervisor_hostname="hyper2",
state='up', status='enabled')]
NO_SERVER_HYPER_DICTS = copy.deepcopy(INDEX_HYPER_DICTS)
NO_SERVER_HYPER_DICTS[0].update({'servers': []})
NO_SERVER_HYPER_DICTS[1].update({'servers': []})
def _get_request(self, use_admin_context):
return fakes.HTTPRequest.blank('', use_admin_context=use_admin_context)
@ -385,7 +381,7 @@ class HypervisorsTestV21(test.NoDBTestCase):
fake_instance_get_all_by_host_return_empty)
req = self._get_request(True)
result = self.controller.servers(req, '1')
self.assertEqual(result, dict(hypervisors=self.NO_SERVER_HYPER_DICTS))
self.assertEqual(result, dict(hypervisors=self.INDEX_HYPER_DICTS))
def test_statistics(self):
req = self._get_request(True)
@ -429,15 +425,6 @@ class HypervisorsTestV2(HypervisorsTestV21):
del INDEX_HYPER_DICTS[0]['status']
del INDEX_HYPER_DICTS[1]['status']
NO_SERVER_HYPER_DICTS = copy.deepcopy(
HypervisorsTestV21.NO_SERVER_HYPER_DICTS)
del NO_SERVER_HYPER_DICTS[0]['state']
del NO_SERVER_HYPER_DICTS[1]['state']
del NO_SERVER_HYPER_DICTS[0]['status']
del NO_SERVER_HYPER_DICTS[1]['status']
del NO_SERVER_HYPER_DICTS[0]['servers']
del NO_SERVER_HYPER_DICTS[1]['servers']
def _set_up_controller(self):
self.context = context.get_admin_context()
self.ext_mgr = extensions.ExtensionManager()