Return complete response from services_client

Currently compute services_client returns Response by
removing top key from Response.
For example-
 return service_client.ResponseBody(resp, body['service'])

As service clients are in direction to move to Tempest-lib, all
service clients should return Response without any truncation.
One good example is Resource pagination links which are lost with current
way of return value. Resource pagination links are present in parallel
(not inside) to top key of Response.

This patch makes compute services_client to return
complete Response body.

Change-Id: I79bc3c14700c3201e8c8ac50e80d5f49c96e52c2
Implements: blueprint method-return-value-and-move-service-clients-to-lib
This commit is contained in:
ghanshyam
2015-08-24 17:47:41 +09:00
parent d4038b4f99
commit 0de0284fb1
4 changed files with 27 additions and 22 deletions

View File

@@ -31,25 +31,25 @@ class ServicesAdminTestJSON(base.BaseV2ComputeAdminTest):
@test.idempotent_id('5be41ef4-53d1-41cc-8839-5c2a48a1b283')
def test_list_services(self):
services = self.client.list_services()
services = self.client.list_services()['services']
self.assertNotEqual(0, len(services))
@test.idempotent_id('f345b1ec-bc6e-4c38-a527-3ca2bc00bef5')
def test_get_service_by_service_binary_name(self):
binary_name = 'nova-compute'
services = self.client.list_services(binary=binary_name)
services = self.client.list_services(binary=binary_name)['services']
self.assertNotEqual(0, len(services))
for service in services:
self.assertEqual(binary_name, service['binary'])
@test.idempotent_id('affb42d5-5b4b-43c8-8b0b-6dca054abcca')
def test_get_service_by_host_name(self):
services = self.client.list_services()
services = self.client.list_services()['services']
host_name = services[0]['host']
services_on_host = [service for service in services if
service['host'] == host_name]
services = self.client.list_services(host=host_name)
services = self.client.list_services(host=host_name)['services']
# we could have a periodic job checkin between the 2 service
# lookups, so only compare binary lists.
@@ -62,12 +62,12 @@ class ServicesAdminTestJSON(base.BaseV2ComputeAdminTest):
@test.idempotent_id('39397f6f-37b8-4234-8671-281e44c74025')
def test_get_service_by_service_and_host_name(self):
services = self.client.list_services()
services = self.client.list_services()['services']
host_name = services[0]['host']
binary_name = services[0]['binary']
services = self.client.list_services(host=host_name,
binary=binary_name)
binary=binary_name)['services']
self.assertEqual(1, len(services))
self.assertEqual(host_name, services[0]['host'])
self.assertEqual(binary_name, services[0]['binary'])

View File

@@ -40,22 +40,25 @@ class ServicesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
@test.idempotent_id('d0884a69-f693-4e79-a9af-232d15643bf7')
def test_get_service_by_invalid_params(self):
# return all services if send the request with invalid parameter
services = self.client.list_services()
services_xxx = self.client.list_services(xxx='nova-compute')
services = self.client.list_services()['services']
services_xxx = (self.client.list_services(xxx='nova-compute')
['services'])
self.assertEqual(len(services), len(services_xxx))
@test.attr(type=['negative'])
@test.idempotent_id('1e966d4a-226e-47c7-b601-0b18a27add54')
def test_get_service_by_invalid_service_and_valid_host(self):
services = self.client.list_services()
services = self.client.list_services()['services']
host_name = services[0]['host']
services = self.client.list_services(host=host_name, binary='xxx')
services = self.client.list_services(host=host_name,
binary='xxx')['services']
self.assertEqual(0, len(services))
@test.attr(type=['negative'])
@test.idempotent_id('64e7e7fb-69e8-4cb6-a71d-8d5eb0c98655')
def test_get_service_with_valid_service_and_invalid_host(self):
services = self.client.list_services()
services = self.client.list_services()['services']
binary_name = services[0]['binary']
services = self.client.list_services(host='xxx', binary=binary_name)
services = self.client.list_services(host='xxx',
binary=binary_name)['services']
self.assertEqual(0, len(services))

View File

@@ -31,7 +31,7 @@ class ServicesClient(service_client.ServiceClient):
resp, body = self.get(url)
body = json.loads(body)
self.validate_response(schema.list_services, resp, body)
return service_client.ResponseBodyList(resp, body['services'])
return service_client.ResponseBody(resp, body)
def enable_service(self, host_name, binary):
"""
@@ -43,7 +43,7 @@ class ServicesClient(service_client.ServiceClient):
resp, body = self.put('os-services/enable', post_body)
body = json.loads(body)
self.validate_response(schema.enable_service, resp, body)
return service_client.ResponseBody(resp, body['service'])
return service_client.ResponseBody(resp, body)
def disable_service(self, host_name, binary):
"""
@@ -54,4 +54,4 @@ class ServicesClient(service_client.ServiceClient):
post_body = json.dumps({'binary': binary, 'host': host_name})
resp, body = self.put('os-services/disable', post_body)
body = json.loads(body)
return service_client.ResponseBody(resp, body['service'])
return service_client.ResponseBody(resp, body)

View File

@@ -49,7 +49,8 @@ class TestServicesClient(base.TestCase):
fake_auth, 'compute', 'regionOne')
def _test_list_services(self, bytes_body=False):
serialized_body = json.dumps({"services": self.FAKE_SERVICES})
expected = {"services": self.FAKE_SERVICES}
serialized_body = json.dumps(expected)
if bytes_body:
serialized_body = serialized_body.encode('utf-8')
@@ -58,7 +59,7 @@ class TestServicesClient(base.TestCase):
'tempest.common.service_client.ServiceClient.get',
return_value=mocked_resp))
resp = self.client.list_services()
self.assertEqual(self.FAKE_SERVICES, resp)
self.assertEqual(expected, resp)
def test_list_services_with_str_body(self):
self._test_list_services()
@@ -67,7 +68,8 @@ class TestServicesClient(base.TestCase):
self._test_list_services(bytes_body=True)
def _test_enable_service(self, bytes_body=False):
serialized_body = json.dumps({"service": self.FAKE_SERVICE})
expected = {"service": self.FAKE_SERVICE}
serialized_body = json.dumps(expected)
if bytes_body:
serialized_body = serialized_body.encode('utf-8')
@@ -76,7 +78,7 @@ class TestServicesClient(base.TestCase):
'tempest.common.service_client.ServiceClient.put',
return_value=mocked_resp))
resp = self.client.enable_service("nova-conductor", "controller")
self.assertEqual(self.FAKE_SERVICE, resp)
self.assertEqual(expected, resp)
def test_enable_service_with_str_body(self):
self._test_enable_service()
@@ -87,8 +89,8 @@ class TestServicesClient(base.TestCase):
def _test_disable_service(self, bytes_body=False):
fake_service = copy.deepcopy(self.FAKE_SERVICE)
fake_service["status"] = "disable"
serialized_body = json.dumps({"service": self.FAKE_SERVICE})
expected = {"service": self.FAKE_SERVICE}
serialized_body = json.dumps(expected)
if bytes_body:
serialized_body = serialized_body.encode('utf-8')
@@ -97,7 +99,7 @@ class TestServicesClient(base.TestCase):
'tempest.common.service_client.ServiceClient.put',
return_value=mocked_resp))
resp = self.client.disable_service("nova-conductor", "controller")
self.assertEqual(self.FAKE_SERVICE, resp)
self.assertEqual(expected, resp)
def test_disable_service_with_str_body(self):
self._test_enable_service()