Adds service request parameter filter for V3 API os-hosts request
Both V2 and V3 API do not support service request parameter filter for os-hosts request. For V2 API, there is no need to having two different clouds having different APIs (one with service filter one without) but just take V2 API as a document bug. This patch will only fix V3 API. DocImpact Adds the ability to filter a hosts list request by service for the V3 API. Change-Id: I42163707049300b0dee677558ed49280bcc7369d Partial-Bug: #1224763
This commit is contained in:
parent
145017be82
commit
67c0d16eb6
@ -0,0 +1,9 @@
|
||||
{
|
||||
"hosts": [
|
||||
{
|
||||
"host_name": "09c025b0efc64211bd23fc50fa974cdf",
|
||||
"service": "compute",
|
||||
"zone": "nova"
|
||||
}
|
||||
]
|
||||
}
|
@ -80,6 +80,9 @@ class HostController(wsgi.Controller):
|
||||
zone = req.GET.get('zone', None)
|
||||
if zone:
|
||||
filters['availability_zone'] = zone
|
||||
service = req.GET.get('service')
|
||||
if service:
|
||||
filters['topic'] = service
|
||||
services = self.api.service_get_all(context, filters=filters,
|
||||
set_zones=True)
|
||||
hosts = []
|
||||
|
@ -132,6 +132,16 @@ class FakeRequestWithNovaZone(object):
|
||||
GET = {"zone": "nova"}
|
||||
|
||||
|
||||
class FakeRequestWithNovaService(object):
|
||||
environ = {"nova.context": context_maker.get_admin_context()}
|
||||
GET = {"service": "compute"}
|
||||
|
||||
|
||||
class FakeRequestWithInvalidNovaService(object):
|
||||
environ = {"nova.context": context_maker.get_admin_context()}
|
||||
GET = {"service": "invalid"}
|
||||
|
||||
|
||||
class HostTestCase(test.TestCase):
|
||||
"""Test Case for hosts."""
|
||||
|
||||
@ -174,6 +184,14 @@ class HostTestCase(test.TestCase):
|
||||
hosts = result['hosts']
|
||||
self.assertEqual(fake_hosts.HOST_LIST_NOVA_ZONE, hosts)
|
||||
|
||||
def test_list_hosts_with_service(self):
|
||||
result = self.controller.index(FakeRequestWithNovaService())
|
||||
self.assertEqual(fake_hosts.HOST_LIST_NOVA_ZONE, result['hosts'])
|
||||
|
||||
def test_list_hosts_with_invalid_service(self):
|
||||
result = self.controller.index(FakeRequestWithInvalidNovaService())
|
||||
self.assertEqual([], result['hosts'])
|
||||
|
||||
def test_disable_host(self):
|
||||
self._test_host_update('host_c1', 'status', 'disable', 'disabled')
|
||||
self._test_host_update('host_c2', 'status', 'disable', 'enabled')
|
||||
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"hosts": [
|
||||
{
|
||||
"host_name": "%(host_name)s",
|
||||
"service": "compute",
|
||||
"zone": "nova"
|
||||
}
|
||||
]
|
||||
}
|
@ -49,3 +49,9 @@ class HostsSampleJsonTest(api_sample_base.ApiSampleTestBaseV3):
|
||||
response = self._do_get('os-hosts')
|
||||
subs = self._get_regexes()
|
||||
self._verify_response('hosts-list-resp', subs, response, 200)
|
||||
|
||||
def test_hosts_list_compute_service(self):
|
||||
response = self._do_get('os-hosts?service=compute')
|
||||
subs = self._get_regexes()
|
||||
self._verify_response('hosts-list-compute-service-resp',
|
||||
subs, response, 200)
|
||||
|
Loading…
Reference in New Issue
Block a user