Merge "Adds service request parameter filter for V3 API os-hosts request"

This commit is contained in:
Jenkins 2014-02-23 21:10:17 +00:00 committed by Gerrit Code Review
commit ef3b1385cb
5 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,9 @@
{
"hosts": [
{
"host_name": "09c025b0efc64211bd23fc50fa974cdf",
"service": "compute",
"zone": "nova"
}
]
}

View File

@ -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 = []

View File

@ -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')

View File

@ -0,0 +1,9 @@
{
"hosts": [
{
"host_name": "%(host_name)s",
"service": "compute",
"zone": "nova"
}
]
}

View File

@ -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)