From 75c086b946ac96211bb207088394e660369e1f16 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Mon, 23 Jul 2018 17:29:48 -0700 Subject: [PATCH] Adds get_amphora_stats to the service client This patch adds a get_amphora_stats method to the service client. Depends-On: https://review.openstack.org/#/c/585031/ Change-Id: Ic79606ae628131f83f8b2b3cad0e61dedfa3d399 --- .../load_balancer/v2/amphora_client.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py b/octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py index 65a8077b..54f280ec 100644 --- a/octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py +++ b/octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import json + from tempest import config from octavia_tempest_plugin.services.load_balancer.v2 import base_client @@ -23,6 +25,7 @@ class AmphoraClient(base_client.BaseLBaaSClient): root_tag = 'amphora' list_root_tag = 'amphorae' + stats_root_tag = 'amphora_stats' base_uri = '/v2.0/octavia/{object}' def show_amphora(self, amphora_id, query_params=None, @@ -103,3 +106,54 @@ class AmphoraClient(base_client.BaseLBaaSClient): """ return self._list_objects(query_params=query_params, return_object_only=return_object_only) + + def get_amphora_stats(self, amphora_id, query_params=None, + return_object_only=True): + """Get amphora statistics. + + :param amphora_id: The amphora ID to query. + :param query_params: The optional query parameters to append to the + request. Ex. fields=id&fields=name + :param return_object_only: If True, the response returns the object + inside the root tag. False returns the full + response from the API. + :raises AssertionError: if the expected_code isn't a valid http success + response code + :raises BadRequest: If a 400 response code is received + :raises Conflict: If a 409 response code is received + :raises Forbidden: If a 403 response code is received + :raises Gone: If a 410 response code is received + :raises InvalidContentType: If a 415 response code is received + :raises InvalidHTTPResponseBody: The response body wasn't valid JSON + :raises InvalidHttpSuccessCode: if the read code isn't an expected + http success code + :raises NotFound: If a 404 response code is received + :raises NotImplemented: If a 501 response code is received + :raises OverLimit: If a 413 response code is received and over_limit is + not in the response body + :raises RateLimitExceeded: If a 413 response code is received and + over_limit is in the response body + :raises ServerFault: If a 500 response code is received + :raises Unauthorized: If a 401 response code is received + :raises UnexpectedContentType: If the content-type of the response + isn't an expect type + :raises UnexpectedResponseCode: If a response code above 400 is + received and it doesn't fall into any + of the handled checks + :raises UnprocessableEntity: If a 422 response code is received and + couldn't be parsed + :returns: An amphora statistics object. + """ + uri = self.base_uri.format(object=self.list_root_tag) + if query_params: + request_uri = '{0}/{1}/stats?{2}'.format(uri, amphora_id, + query_params) + else: + request_uri = '{0}/{1}/stats'.format(uri, amphora_id) + + response, body = self.get(request_uri) + self.expected_success(200, response.status) + if return_object_only: + return json.loads(body.decode('utf-8'))[self.stats_root_tag] + else: + return json.loads(body.decode('utf-8'))