Fixes for stacklight tests
1. Move test_prometheus_alert_count from curl to requests
2. Add authorization for prometheus and alermanager
Change-Id: Ic29c957c0b93fc8762d22624d1314af441eeea0e
Related-prod: PROD-31822 PROD-34064
diff --git a/test_set/cvp-sanity/tests/test_stacklight.py b/test_set/cvp-sanity/tests/test_stacklight.py
index 03b5a42..78e190c 100644
--- a/test_set/cvp-sanity/tests/test_stacklight.py
+++ b/test_set/cvp-sanity/tests/test_stacklight.py
@@ -143,21 +143,32 @@
@pytest.mark.usefixtures('check_prometheus')
def test_prometheus_alert_count(local_salt_client, ctl_nodes_pillar):
IP = local_salt_client.pillar_get(param='_param:cluster_public_host')
+ prometheus_password_old = local_salt_client.pillar_get(
+ param='_param:keepalived_prometheus_vip_password_generated')
+ prometheus_password = local_salt_client.pillar_get(
+ param='_param:prometheus_server_proxy_password_generated')
proto = local_salt_client.pillar_get(
param='_param:cluster_public_protocol')
+ proxies = {"http": None, "https": None}
# keystone:server can return 3 nodes instead of 1
# this will be fixed later
# TODO
- nodes_info = local_salt_client.cmd(
- tgt=ctl_nodes_pillar,
- param='curl -k -s {0}://{1}:15010/alerts | grep icon-chevron-down | '
- 'grep -v "0 active"'.format(proto, IP),
- expr_form='pillar')
-
- result = nodes_info[nodes_info.keys()[0]].replace('</td>', '').replace(
- '<td><i class="icon-chevron-down"></i> <b>', '').replace('</b>', '')
- assert result == '', 'AlertManager page has some alerts!\n{}'.format(
- json.dumps(result), indent=4)
+ if prometheus_password == '':
+ prometheus_password = prometheus_password_old
+ response = requests.get(
+ '{0}://{1}:15010/api/v1/alerts'.format(proto, IP),
+ proxies=proxies,
+ auth=('prometheus', prometheus_password))
+ assert response.status_code == 200, (
+ 'Issues with accessing prometheus alerts on {}:\n{}'.format(
+ IP, response.text)
+ )
+ alerts = json.loads(response.content)
+ short_alerts = ''
+ for i in alerts['data']['alerts']:
+ short_alerts = '{}* {}\n'.format(short_alerts, i['annotations']['description'])
+ assert alerts['data']['alerts'] == [], 'AlertManager page has some alerts!\n{}'.format(
+ short_alerts)
@pytest.mark.sl_dup
diff --git a/test_set/cvp-sanity/tests/test_ui_addresses.py b/test_set/cvp-sanity/tests/test_ui_addresses.py
index 5e6ccdb..12ff05c 100644
--- a/test_set/cvp-sanity/tests/test_ui_addresses.py
+++ b/test_set/cvp-sanity/tests/test_ui_addresses.py
@@ -1,3 +1,4 @@
+import requests
import pytest
@@ -101,15 +102,24 @@
@pytest.mark.usefixtures('check_prometheus')
def test_public_ui_prometheus(local_salt_client, ctl_nodes_pillar):
IP = local_salt_client.pillar_get(param='_param:cluster_public_host')
+ prometheus_password_old = local_salt_client.pillar_get(
+ param='_param:keepalived_prometheus_vip_password_generated')
+ prometheus_password = local_salt_client.pillar_get(
+ param='_param:prometheus_server_proxy_password_generated')
proto = local_salt_client.pillar_get(
param='_param:cluster_public_protocol')
- port = '15010'
- url = "{}://{}:{}".format(proto, IP, port)
- result = local_salt_client.cmd(
- tgt=ctl_nodes_pillar,
- param='curl -k {}/graph 2>&1 | grep Prometheus'.format(url),
- expr_form='pillar')
- assert len(result[result.keys()[0]]) != 0, (
+ proxies = {"http": None, "https": None}
+ if prometheus_password == '':
+ prometheus_password = prometheus_password_old
+ response = requests.get(
+ '{0}://{1}:15010/graph'.format(proto, IP),
+ proxies=proxies,
+ auth=('prometheus', prometheus_password))
+ assert response.status_code == 200, (
+ 'Issues with accessing public prometheus ui on {}:\n{}'.format(
+ IP, response.text)
+ )
+ assert response.content.find('Prometheus Time Series Collection') > -1, (
'Public Prometheus page is not reachable on {} from ctl '
'nodes'.format(url)
)
@@ -138,15 +148,24 @@
@pytest.mark.usefixtures('check_prometheus')
def test_public_ui_alert_manager(local_salt_client, ctl_nodes_pillar):
IP = local_salt_client.pillar_get(param='_param:cluster_public_host')
+ alermanager_password_old = local_salt_client.pillar_get(
+ param='_param:keepalived_prometheus_vip_password_generated')
+ alermanager_password = local_salt_client.pillar_get(
+ param='_param:prometheus_alermanager_proxy_password_generated')
proto = local_salt_client.pillar_get(
param='_param:cluster_public_protocol')
- port = '15011'
- url = "{}://{}:{}".format(proto, IP, port)
- result = local_salt_client.cmd(
- tgt=ctl_nodes_pillar,
- param='curl -k -s {}/ | grep Alertmanager'.format(url),
- expr_form='pillar')
- assert len(result[result.keys()[0]]) != 0, (
+ proxies = {"http": None, "https": None}
+ if alermanager_password == '':
+ alermanager_password = alermanager_password_old
+ response = requests.get(
+ '{0}://{1}:15011/'.format(proto, IP),
+ proxies=proxies,
+ auth=('alertmanager', alermanager_password))
+ assert response.status_code == 200, (
+ 'Issues with accessing public alert manager ui on {}:\n{}'.format(
+ IP, response.text)
+ )
+ assert response.content.find('<title>Alertmanager</title>') > -1, (
'Public AlertManager page is not reachable on {} '
'from ctl nodes'.format(url)
)