From 8646e5ae9786c7e07e781eb93c90db725eee4113 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Sat, 2 Oct 2021 19:58:34 +0000 Subject: [PATCH] API and scenario tests for PROMETHEUS listeners. This patch adds API and scenario tests for PROMETHEUS listeners. This includes scenario tests that connect to the metrics endpoint. Depends-On: https://review.opendev.org/c/openstack/octavia/+/812258 Change-Id: Ia46d8c0967bc5b0f7cd11b6e3ca3a4e03c0bc138 --- octavia_tempest_plugin/common/constants.py | 1 + octavia_tempest_plugin/config.py | 2 + .../tests/api/v2/test_listener.py | 56 +++++++++++++++++ .../tests/scenario/v2/test_traffic_ops.py | 62 +++++++++++++++++++ ...I-and-scenario-tests-ccab4b09f6a64428.yaml | 4 ++ 5 files changed, 125 insertions(+) create mode 100644 releasenotes/notes/Add-PROMETHEUS-listener-API-and-scenario-tests-ccab4b09f6a64428.yaml diff --git a/octavia_tempest_plugin/common/constants.py b/octavia_tempest_plugin/common/constants.py index 4d854f18..8ef8d943 100644 --- a/octavia_tempest_plugin/common/constants.py +++ b/octavia_tempest_plugin/common/constants.py @@ -131,6 +131,7 @@ SUPPORTED_LB_TOPOLOGIES = (SINGLE, ACTIVE_STANDBY) HTTP = 'HTTP' HTTPS = 'HTTPS' PROXY = 'PROXY' +PROMETHEUS = 'PROMETHEUS' TCP = 'TCP' TERMINATED_HTTPS = 'TERMINATED_HTTPS' UDP = 'UDP' diff --git a/octavia_tempest_plugin/config.py b/octavia_tempest_plugin/config.py index 4d1543b2..502bdec6 100644 --- a/octavia_tempest_plugin/config.py +++ b/octavia_tempest_plugin/config.py @@ -285,6 +285,8 @@ LBFeatureEnabledGroup = [ help="Whether the log offload tests will run. These require " "the tempest instance have access to the log files " "specified in the tempest configuration."), + cfg.BoolOpt('prometheus_listener_enabled', default=True, + help="Whether the PROMETHEUS listener tests will run."), ] # Extending this enforce_scope group defined in tempest diff --git a/octavia_tempest_plugin/tests/api/v2/test_listener.py b/octavia_tempest_plugin/tests/api/v2/test_listener.py index 1c2fa751..c58dbbbf 100644 --- a/octavia_tempest_plugin/tests/api/v2/test_listener.py +++ b/octavia_tempest_plugin/tests/api/v2/test_listener.py @@ -21,6 +21,7 @@ from tempest import config from tempest.lib.common.utils import data_utils from tempest.lib import decorators from tempest.lib import exceptions +import testtools from octavia_tempest_plugin.common import constants as const from octavia_tempest_plugin.tests import test_base @@ -79,6 +80,17 @@ class ListenerAPITest(test_base.LoadBalancerBaseTest): def test_tcp_listener_create(self): self._test_listener_create(const.TCP, 8002) + @decorators.idempotent_id('1a6ba0d0-f309-4088-a686-dda0e9ab7e43') + @testtools.skipUnless( + CONF.loadbalancer_feature_enabled.prometheus_listener_enabled, + 'PROMETHEUS listener tests are disabled in the tempest configuration.') + def test_prometheus_listener_create(self): + if not self.mem_listener_client.is_version_supported( + self.api_version, '2.25'): + raise self.skipException('PROMETHEUS listeners are only available ' + 'on Octavia API version 2.25 or newer.') + self._test_listener_create(const.PROMETHEUS, 8090) + @decorators.idempotent_id('7b53f336-47bc-45ae-bbd7-4342ef0673fc') # Skipping due to a status update bug in the amphora driver. @decorators.skip_because( @@ -369,6 +381,17 @@ class ListenerAPITest(test_base.LoadBalancerBaseTest): def test_https_listener_list(self): self._test_listener_list(const.HTTPS, 8030) + @decorators.idempotent_id('5473e071-8277-4ac5-9277-01ecaf46e274') + @testtools.skipUnless( + CONF.loadbalancer_feature_enabled.prometheus_listener_enabled, + 'PROMETHEUS listener tests are disabled in the tempest configuration.') + def test_prometheus_listener_list(self): + if not self.mem_listener_client.is_version_supported( + self.api_version, '2.25'): + raise self.skipException('PROMETHEUS listeners are only available ' + 'on Octavia API version 2.25 or newer.') + self._test_listener_list(const.PROMETHEUS, 8091) + @decorators.idempotent_id('1cd476e2-7788-415e-bcaf-c377acfc9794') def test_tcp_listener_list(self): self._test_listener_list(const.TCP, 8030) @@ -735,6 +758,17 @@ class ListenerAPITest(test_base.LoadBalancerBaseTest): def test_https_listener_show(self): self._test_listener_show(const.HTTPS, 8051) + @decorators.idempotent_id('b851b754-4333-4115-9063-a9fce44c2e46') + @testtools.skipUnless( + CONF.loadbalancer_feature_enabled.prometheus_listener_enabled, + 'PROMETHEUS listener tests are disabled in the tempest configuration.') + def test_prometheus_listener_show(self): + if not self.mem_listener_client.is_version_supported( + self.api_version, '2.25'): + raise self.skipException('PROMETHEUS listeners are only available ' + 'on Octavia API version 2.25 or newer.') + self._test_listener_show(const.PROMETHEUS, 8092) + @decorators.idempotent_id('1fcbbee2-b697-4890-b6bf-d308ac1c94cd') def test_tcp_listener_show(self): self._test_listener_show(const.TCP, 8052) @@ -888,6 +922,17 @@ class ListenerAPITest(test_base.LoadBalancerBaseTest): def test_https_listener_update(self): self._test_listener_update(const.HTTPS, 8061) + @decorators.idempotent_id('cbba6bf8-9184-4da5-95e9-5efe1f89ddf0') + @testtools.skipUnless( + CONF.loadbalancer_feature_enabled.prometheus_listener_enabled, + 'PROMETHEUS listener tests are disabled in the tempest configuration.') + def test_prometheus_listener_update(self): + if not self.mem_listener_client.is_version_supported( + self.api_version, '2.25'): + raise self.skipException('PROMETHEUS listeners are only available ' + 'on Octavia API version 2.25 or newer.') + self._test_listener_update(const.PROMETHEUS, 8093) + @decorators.idempotent_id('8d933121-db03-4ccc-8b77-4e879064a9ba') def test_tcp_listener_update(self): self._test_listener_update(const.TCP, 8062) @@ -1139,6 +1184,17 @@ class ListenerAPITest(test_base.LoadBalancerBaseTest): def test_https_listener_delete(self): self._test_listener_delete(const.HTTPS, 8071) + @decorators.idempotent_id('322a6372-6b56-4a3c-87e3-dd82074bc83e') + @testtools.skipUnless( + CONF.loadbalancer_feature_enabled.prometheus_listener_enabled, + 'PROMETHEUS listener tests are disabled in the tempest configuration.') + def test_prometheus_listener_delete(self): + if not self.mem_listener_client.is_version_supported( + self.api_version, '2.25'): + raise self.skipException('PROMETHEUS listeners are only available ' + 'on Octavia API version 2.25 or newer.') + self._test_listener_delete(const.PROMETHEUS, 8094) + @decorators.idempotent_id('f5ca019d-2b33-48f9-9c2d-2ec169b423ca') def test_tcp_listener_delete(self): self._test_listener_delete(const.TCP, 8072) diff --git a/octavia_tempest_plugin/tests/scenario/v2/test_traffic_ops.py b/octavia_tempest_plugin/tests/scenario/v2/test_traffic_ops.py index fc050c6d..e8221fe8 100644 --- a/octavia_tempest_plugin/tests/scenario/v2/test_traffic_ops.py +++ b/octavia_tempest_plugin/tests/scenario/v2/test_traffic_ops.py @@ -1557,3 +1557,65 @@ class TrafficOperationsScenarioTest(test_base.LoadBalancerBaseTestWithCompute): CONF.load_balancer.check_interval, CONF.load_balancer.check_timeout, error_ok=True, pool_id=pool_id) + + @decorators.idempotent_id('05e99fb3-2b37-478e-889b-77f1c731a471') + @testtools.skipUnless( + CONF.loadbalancer_feature_enabled.prometheus_listener_enabled, + 'PROMETHEUS listener tests are disabled in the tempest configuration.') + def test_prometheus_listener_metrics_page(self): + """Tests PROMETHEUS listener create and metrics endpoint is available + + * Create PROMETHEUS listener. + * Query the metrics endpoint on the load balancer. + """ + if not self.mem_listener_client.is_version_supported( + self.api_version, '2.25'): + raise self.skipException('PROMETHEUS listeners are only available ' + 'on Octavia API version 2.25 or newer.') + + # Listener create + listener_name = data_utils.rand_name("lb_member_prometheus_listener") + listener_description = data_utils.arbitrary_string(size=255) + listener_kwargs = { + const.NAME: listener_name, + const.DESCRIPTION: listener_description, + const.ADMIN_STATE_UP: True, + const.PROTOCOL: const.PROMETHEUS, + const.PROTOCOL_PORT: 8080, + const.LOADBALANCER_ID: self.lb_id, + const.CONNECTION_LIMIT: 200, + } + + if self.mem_listener_client.is_version_supported( + self.api_version, '2.1'): + listener_kwargs.update({ + const.TIMEOUT_CLIENT_DATA: 1000, + const.TIMEOUT_MEMBER_CONNECT: 1000, + const.TIMEOUT_MEMBER_DATA: 1000, + const.TIMEOUT_TCP_INSPECT: 50, + }) + if self.mem_listener_client.is_version_supported( + self.api_version, '2.12'): + listener_kwargs.update({const.ALLOWED_CIDRS: ['0.0.0.0/0']}) + + listener = self.mem_listener_client.create_listener(**listener_kwargs) + self.addCleanup( + self.mem_listener_client.cleanup_listener, + listener[const.ID], + lb_client=self.mem_lb_client, lb_id=self.lb_id) + + waiters.wait_for_status( + self.mem_lb_client.show_loadbalancer, self.lb_id, + const.PROVISIONING_STATUS, const.ACTIVE, + CONF.load_balancer.build_interval, + CONF.load_balancer.build_timeout) + listener = waiters.wait_for_status( + self.mem_listener_client.show_listener, + listener[const.ID], const.PROVISIONING_STATUS, + const.ACTIVE, + CONF.load_balancer.build_interval, + CONF.load_balancer.build_timeout) + + # Make a request to the stats page + URL = 'http://{0}:{1}/metrics'.format(self.lb_vip_address, '8080') + self.validate_URL_response(URL, expected_status_code=200) diff --git a/releasenotes/notes/Add-PROMETHEUS-listener-API-and-scenario-tests-ccab4b09f6a64428.yaml b/releasenotes/notes/Add-PROMETHEUS-listener-API-and-scenario-tests-ccab4b09f6a64428.yaml new file mode 100644 index 00000000..f88f51bb --- /dev/null +++ b/releasenotes/notes/Add-PROMETHEUS-listener-API-and-scenario-tests-ccab4b09f6a64428.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Added API and scenario tests for PROMETHEUS listeners.