From a1c93eb3e28592ee3c4b2e2563ef1b66722a1bee Mon Sep 17 00:00:00 2001 From: Alexandre Allard Date: Fri, 28 Jan 2022 16:32:53 +0100 Subject: [PATCH] tests: Add a test to ensure we can access Loki API This test is to ensure we can access a specific Loki instance through the Services. --- tests/post/features/logging.feature | 4 ++++ tests/post/steps/test_logging.py | 37 ++++++++++++++++++----------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/tests/post/features/logging.feature b/tests/post/features/logging.feature index 22cf38c50d..0d6d177521 100644 --- a/tests/post/features/logging.feature +++ b/tests/post/features/logging.feature @@ -25,3 +25,7 @@ Feature: Logging stack is up and running Given the Kubernetes API is available And the Loki API is available Then we can retrieve 'Watchdog' alert from Loki API + + Scenario: We can access a specific Loki instance + Given the Kubernetes API is available + Then the Loki API is available through Service 'loki-0' diff --git a/tests/post/steps/test_logging.py b/tests/post/steps/test_logging.py index 2fa1b531d0..b987860cfe 100644 --- a/tests/post/steps/test_logging.py +++ b/tests/post/steps/test_logging.py @@ -57,20 +57,8 @@ def test_logging_pipeline_is_working(host): @given("the Loki API is available") -def check_loki_api(k8s_client): - def _check_loki_ready(): - # NOTE: We use Kubernetes client instead of DynamicClient as it - # ease the "service proxy path" - client = kubernetes.client.CoreV1Api(api_client=k8s_client.client) - try: - response = client.connect_get_namespaced_service_proxy_with_path( - "loki:http-metrics", "metalk8s-logging", path="ready" - ) - except Exception as exc: # pylint: disable=broad-except - assert False, str(exc) - assert response == "ready\n" - - utils.retry(_check_loki_ready, times=10, wait=2, name="checking Loki API ready") +def given_check_loki_api(k8s_client): + check_loki_api(k8s_client, "loki") @given("we have set up a logger pod", target_fixture="pod_creation_ts") @@ -232,6 +220,11 @@ def _check_alert_exists(): ) +@then("the Loki API is available through Service '{service}'") +def then_check_loki_api(k8s_client, service): + check_loki_api(k8s_client, service) + + # }}} # Helpers {{{ @@ -260,4 +253,20 @@ def query_loki_api(k8s_client, content, route="query"): return response +def check_loki_api(k8s_client, service): + def _check_loki_ready(): + # NOTE: We use Kubernetes client instead of DynamicClient as it + # ease the "service proxy path" + client = kubernetes.client.CoreV1Api(api_client=k8s_client.client) + try: + response = client.connect_get_namespaced_service_proxy_with_path( + f"{service}:http-metrics", "metalk8s-logging", path="ready" + ) + except Exception as exc: # pylint: disable=broad-except + assert False, str(exc) + assert response == "ready\n" + + utils.retry(_check_loki_ready, times=10, wait=2, name="checking Loki API ready") + + # }}}