Skip to content
Snippets Groups Projects
Unverified Commit 806f0e6a authored by Varac's avatar Varac
Browse files

Use requests for prometheus test

parent 2f9e1b4c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment