Browse Source

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
Michael Johnson 9 months ago
parent
commit
75c086b946
1 changed files with 54 additions and 0 deletions
  1. 54
    0
      octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py

+ 54
- 0
octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py View File

@@ -12,6 +12,8 @@
12 12
 #   License for the specific language governing permissions and limitations
13 13
 #   under the License.
14 14
 
15
+import json
16
+
15 17
 from tempest import config
16 18
 
17 19
 from octavia_tempest_plugin.services.load_balancer.v2 import base_client
@@ -23,6 +25,7 @@ class AmphoraClient(base_client.BaseLBaaSClient):
23 25
 
24 26
     root_tag = 'amphora'
25 27
     list_root_tag = 'amphorae'
28
+    stats_root_tag = 'amphora_stats'
26 29
     base_uri = '/v2.0/octavia/{object}'
27 30
 
28 31
     def show_amphora(self, amphora_id, query_params=None,
@@ -103,3 +106,54 @@ class AmphoraClient(base_client.BaseLBaaSClient):
103 106
         """
104 107
         return self._list_objects(query_params=query_params,
105 108
                                   return_object_only=return_object_only)
109
+
110
+    def get_amphora_stats(self, amphora_id, query_params=None,
111
+                          return_object_only=True):
112
+        """Get amphora statistics.
113
+
114
+        :param amphora_id: The amphora ID to query.
115
+        :param query_params: The optional query parameters to append to the
116
+                             request. Ex. fields=id&fields=name
117
+        :param return_object_only: If True, the response returns the object
118
+                                   inside the root tag. False returns the full
119
+                                   response from the API.
120
+        :raises AssertionError: if the expected_code isn't a valid http success
121
+                                response code
122
+        :raises BadRequest: If a 400 response code is received
123
+        :raises Conflict: If a 409 response code is received
124
+        :raises Forbidden: If a 403 response code is received
125
+        :raises Gone: If a 410 response code is received
126
+        :raises InvalidContentType: If a 415 response code is received
127
+        :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
128
+        :raises InvalidHttpSuccessCode: if the read code isn't an expected
129
+                                        http success code
130
+        :raises NotFound: If a 404 response code is received
131
+        :raises NotImplemented: If a 501 response code is received
132
+        :raises OverLimit: If a 413 response code is received and over_limit is
133
+                           not in the response body
134
+        :raises RateLimitExceeded: If a 413 response code is received and
135
+                                   over_limit is in the response body
136
+        :raises ServerFault: If a 500 response code is received
137
+        :raises Unauthorized: If a 401 response code is received
138
+        :raises UnexpectedContentType: If the content-type of the response
139
+                                       isn't an expect type
140
+        :raises UnexpectedResponseCode: If a response code above 400 is
141
+                                        received and it doesn't fall into any
142
+                                        of the handled checks
143
+        :raises UnprocessableEntity: If a 422 response code is received and
144
+                                     couldn't be parsed
145
+        :returns: An amphora statistics object.
146
+        """
147
+        uri = self.base_uri.format(object=self.list_root_tag)
148
+        if query_params:
149
+            request_uri = '{0}/{1}/stats?{2}'.format(uri, amphora_id,
150
+                                                     query_params)
151
+        else:
152
+            request_uri = '{0}/{1}/stats'.format(uri, amphora_id)
153
+
154
+        response, body = self.get(request_uri)
155
+        self.expected_success(200, response.status)
156
+        if return_object_only:
157
+            return json.loads(body.decode('utf-8'))[self.stats_root_tag]
158
+        else:
159
+            return json.loads(body.decode('utf-8'))

Loading…
Cancel
Save