Browse Source

Add listener stats service client and API test

This patch adds the listener stats service client and tempest API test.

Change-Id: I008204d5000c9a2fb4852021f0c759a2490c69b7
Story: 2004853
Task: 29079
Michael Johnson 2 months ago
parent
commit
69cb566d5a

+ 52
- 0
octavia_tempest_plugin/services/load_balancer/v2/listener_client.py View File

@@ -13,6 +13,8 @@
13 13
 #   under the License.
14 14
 #
15 15
 
16
+import json
17
+
16 18
 from tempest import config
17 19
 
18 20
 from octavia_tempest_plugin.services.load_balancer.v2 import base_client
@@ -291,3 +293,53 @@ class ListenerClient(base_client.BaseLBaaSClient):
291 293
         """
292 294
         return self._delete_obj(obj_id=listener_id,
293 295
                                 ignore_errors=ignore_errors)
296
+
297
+    def get_listener_stats(self, listener_id, query_params=None,
298
+                           return_object_only=True):
299
+        """Get listener statistics.
300
+
301
+        :param listener_id: The listener ID to query.
302
+        :param query_params: The optional query parameters to append to the
303
+                             request. Ex. fields=id&fields=name
304
+        :param return_object_only: If True, the response returns the object
305
+                                   inside the root tag. False returns the full
306
+                                   response from the API.
307
+        :raises AssertionError: if the expected_code isn't a valid http success
308
+                                response code
309
+        :raises BadRequest: If a 400 response code is received
310
+        :raises Conflict: If a 409 response code is received
311
+        :raises Forbidden: If a 403 response code is received
312
+        :raises Gone: If a 410 response code is received
313
+        :raises InvalidContentType: If a 415 response code is received
314
+        :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
315
+        :raises InvalidHttpSuccessCode: if the read code isn't an expected
316
+                                        http success code
317
+        :raises NotFound: If a 404 response code is received
318
+        :raises NotImplemented: If a 501 response code is received
319
+        :raises OverLimit: If a 413 response code is received and over_limit is
320
+                           not in the response body
321
+        :raises RateLimitExceeded: If a 413 response code is received and
322
+                                   over_limit is in the response body
323
+        :raises ServerFault: If a 500 response code is received
324
+        :raises Unauthorized: If a 401 response code is received
325
+        :raises UnexpectedContentType: If the content-type of the response
326
+                                       isn't an expect type
327
+        :raises UnexpectedResponseCode: If a response code above 400 is
328
+                                        received and it doesn't fall into any
329
+                                        of the handled checks
330
+        :raises UnprocessableEntity: If a 422 response code is received and
331
+                                     couldn't be parsed
332
+        :returns: A listener statistics object.
333
+        """
334
+        if query_params:
335
+            request_uri = '{0}/{1}/stats?{2}'.format(self.uri, listener_id,
336
+                                                     query_params)
337
+        else:
338
+            request_uri = '{0}/{1}/stats'.format(self.uri, listener_id)
339
+
340
+        response, body = self.get(request_uri)
341
+        self.expected_success(200, response.status)
342
+        if return_object_only:
343
+            return json.loads(body.decode('utf-8'))['stats']
344
+        else:
345
+            return json.loads(body.decode('utf-8'))

+ 73
- 0
octavia_tempest_plugin/tests/api/v2/test_listener.py View File

@@ -764,3 +764,76 @@ class ListenerAPITest(test_base.LoadBalancerBaseTest):
764 764
             const.ACTIVE,
765 765
             CONF.load_balancer.check_interval,
766 766
             CONF.load_balancer.check_timeout)
767
+
768
+    @decorators.idempotent_id('6f14a6c1-945e-43bc-8215-410c8a5edb25')
769
+    def test_listener_show_stats(self):
770
+        """Tests listener show statistics API.
771
+
772
+        * Create a listener.
773
+        * Validates that other accounts cannot see the stats for the
774
+        *   listener.
775
+        * Show listener statistics.
776
+        * Validate the show reflects the expected values.
777
+        """
778
+        listener_name = data_utils.rand_name("lb_member_listener1-stats")
779
+        listener_description = data_utils.arbitrary_string(size=255)
780
+
781
+        listener_kwargs = {
782
+            const.NAME: listener_name,
783
+            const.DESCRIPTION: listener_description,
784
+            const.ADMIN_STATE_UP: True,
785
+            const.PROTOCOL: const.HTTP,
786
+            const.PROTOCOL_PORT: 84,
787
+            const.LOADBALANCER_ID: self.lb_id,
788
+            const.CONNECTION_LIMIT: 200,
789
+        }
790
+
791
+        listener = self.mem_listener_client.create_listener(**listener_kwargs)
792
+        self.addCleanup(
793
+            self.mem_listener_client.cleanup_listener,
794
+            listener[const.ID],
795
+            lb_client=self.mem_lb_client, lb_id=self.lb_id)
796
+
797
+        waiters.wait_for_status(
798
+            self.mem_lb_client.show_loadbalancer, self.lb_id,
799
+            const.PROVISIONING_STATUS, const.ACTIVE,
800
+            CONF.load_balancer.build_interval,
801
+            CONF.load_balancer.build_timeout)
802
+        listener = waiters.wait_for_status(
803
+            self.mem_listener_client.show_listener,
804
+            listener[const.ID], const.PROVISIONING_STATUS,
805
+            const.ACTIVE,
806
+            CONF.load_balancer.build_interval,
807
+            CONF.load_balancer.build_timeout)
808
+        if not CONF.load_balancer.test_with_noop:
809
+            listener = waiters.wait_for_status(
810
+                self.mem_listener_client.show_listener,
811
+                listener[const.ID], const.OPERATING_STATUS,
812
+                const.ONLINE,
813
+                CONF.load_balancer.build_interval,
814
+                CONF.load_balancer.build_timeout)
815
+
816
+        # Test that a user, without the load balancer member role, cannot
817
+        # use this command
818
+        if CONF.load_balancer.RBAC_test_type == const.ADVANCED:
819
+            self.assertRaises(
820
+                exceptions.Forbidden,
821
+                self.os_primary.listener_client.get_listener_stats,
822
+                listener[const.ID])
823
+
824
+        # Test that a different user, with the load balancer role, cannot see
825
+        # the listener stats
826
+        if not CONF.load_balancer.RBAC_test_type == const.NONE:
827
+            member2_client = self.os_roles_lb_member2.listener_client
828
+            self.assertRaises(exceptions.Forbidden,
829
+                              member2_client.get_listener_stats,
830
+                              listener[const.ID])
831
+
832
+        stats = self.mem_listener_client.get_listener_stats(listener[const.ID])
833
+
834
+        self.assertEqual(5, len(stats))
835
+        self.assertEqual(0, stats[const.ACTIVE_CONNECTIONS])
836
+        self.assertEqual(0, stats[const.BYTES_IN])
837
+        self.assertEqual(0, stats[const.BYTES_OUT])
838
+        self.assertEqual(0, stats[const.REQUEST_ERRORS])
839
+        self.assertEqual(0, stats[const.TOTAL_CONNECTIONS])

+ 4
- 0
releasenotes/notes/add-listener-stats-api-test-88947cf5e6ae9cae.yaml View File

@@ -0,0 +1,4 @@
1
+---
2
+features:
3
+  - |
4
+    Added the listener stats service client and API test.

Loading…
Cancel
Save