From 806f0e6aca672d1fe68c6ae15c1250ce37632cb1 Mon Sep 17 00:00:00 2001 From: Varac <varac@varac.net> Date: Fri, 30 Jul 2021 10:36:20 +0200 Subject: [PATCH] Use requests for prometheus test --- .gitlab-ci.yml | 4 ---- test/pytest/test_prometheus.py | 12 +++++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 24dd7807a..ab8dea1b5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -835,15 +835,11 @@ kube-prometheus-stack-alerts: variables: # RESOURCE var is used in job specific rules (i.e. .kube_prometheus_stack_rules) RESOURCE: "kube-prometheus-stack" - CURL_CA_BUNDLE: "pytest/le-staging-bundle.pem" - CURL_OPTS: '--config curl.conf' allow_failure: true script: - *debug_information - export BASIC_AUTH_PW=$(python3 -m openappstack $HOSTNAME secrets | grep oas-prometheus-basic-auth | cut -d'=' -f2) - cd test/ - # Ensure password is not part of the URL and leaked on errors - - echo "user=admin:$BASIC_AUTH_PW" > curl.conf - pytest -s -m 'prometheus' --connection=ansible --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*' extends: - .ssh_setup diff --git a/test/pytest/test_prometheus.py b/test/pytest/test_prometheus.py index fc9cfee26..b90bd59a9 100755 --- a/test/pytest/test_prometheus.py +++ b/test/pytest/test_prometheus.py @@ -2,6 +2,7 @@ import re import json import os import pytest +import requests def ignore_alert(alert): @@ -65,9 +66,6 @@ def test_prometheus_alerts(host): print("Starting prometheus test...") - curl_opts = os.environ.get("CURL_OPTS") - # assert curl_opts, "Please export the BASIC_AUTH_PW env var!" - domain = os.environ.get("FQDN") if domain: print(f"Using domain {domain} from FQDN environment variable.") @@ -75,10 +73,14 @@ def test_prometheus_alerts(host): ansible_vars = host.ansible.get_variables() domain = ansible_vars["domain"] print(f"Using domain {domain} from ansible inventory.") - url = f'https://prometheus.{domain}/api/v1/alerts' - alert_json = json.loads(host.check_output(f'curl {curl_opts} {url}')) + basic_auth_pw = os.environ.get("BASIC_AUTH_PW") + assert basic_auth_pw, 'Please export BASIC_AUTH_PW env var!' + + resp = requests.get(url, auth=('admin', basic_auth_pw)) + assert resp.status_code == 200 + alert_json = json.loads(resp.content) status = alert_json["status"] alerts = alert_json["data"]["alerts"] -- GitLab