Skip to content
Snippets Groups Projects
Verified Commit b9e71b3d authored by Maarten de Waard's avatar Maarten de Waard :angel:
Browse files

fix docstring, change all_pods_ready to all_pods_running

parent 5f1c3843
No related branches found
No related tags found
No related merge requests found
......@@ -55,16 +55,16 @@ def get_release_status(name, namespace, api):
return release_status
def check_all_pods_ready(result):
def check_all_pods_running(pods):
"""
Loop through all the pods in an API result.
If a pod contains a "status" and "condition":
if that condition's type is "Ready" and its status is not true
Then, there is a pod that is not ready, return false.
Otherwise, returns True.
If a pod does not have an element `status.phase` with the value "Running",
return False. Otherwise, returns True.
:param kubernetes.V1Pod[] pods: list of V1Pod elements to check
"""
ret = True
for pod in result.items:
for pod in pods:
print("- {}: {}".format(pod.metadata.name, pod.status.phase))
if pod.status.phase != "Running":
ret = False
......@@ -116,7 +116,7 @@ def test_apps_running(host):
namespace=info['namespace'],
label_selector=info['label_selector'],
)
if not check_all_pods_ready(result):
if not check_all_pods_running(result.items):
failed += 1
print()
assert failed == 0, "Error: {} apps not 'Running'!".format(failed)
import re
import json
import pytest
import re
@pytest.mark.prometheus
def test_prometheus_alerts(host):
"""Test prometheus for firing alerts."""
def summarize_alerts(alerts):
"""Print a alert summary."""
print('Total alerts: %s' % len(alerts))
print(json.dumps(alerts, indent=2))
print("Starting prometheus test...")
url = 'http://monitoring-prometheus-oper-prometheus.oas.svc.cluster.local:9090/api/v1/alerts'
alert_json = json.loads(host.check_output('curl ' + url))
status = alert_json["status"]
alerts = alert_json["data"]["alerts"]
real_alerts = []
ignored_alerts = []
for alert in alerts:
# Filter out the ever firing "Dead mans switch" test alert
if ignore_alert(alert):
ignored_alerts.append(alert)
else:
real_alerts.append(alert)
print('\n\n\n========= Ignored ==========')
summarize_alerts(ignored_alerts)
print('\n\n\n========= Firing ==========')
summarize_alerts(real_alerts)
count = len(real_alerts)
assert status == "success", "Failure queriying the prometheus api at" + url
assert count == 0, "Firing alerts: {0}".format(count)
def ignore_alert(alert):
......@@ -92,5 +53,44 @@ def ignore_alert(alert):
return False
@pytest.mark.prometheus
def test_prometheus_alerts(host):
"""Test prometheus for firing alerts."""
def summarize_alerts(alerts):
"""Print a alert summary."""
print('Total alerts: %s' % len(alerts))
print(json.dumps(alerts, indent=2))
print("Starting prometheus test...")
url = 'http://monitoring-prometheus-oper-prometheus.oas.svc.cluster.local:9090/api/v1/alerts'
alert_json = json.loads(host.check_output('curl ' + url))
status = alert_json["status"]
alerts = alert_json["data"]["alerts"]
real_alerts = []
ignored_alerts = []
for alert in alerts:
# Filter out the ever firing "Dead mans switch" test alert
if ignore_alert(alert):
ignored_alerts.append(alert)
else:
real_alerts.append(alert)
print('\n\n\n========= Ignored ==========')
summarize_alerts(ignored_alerts)
print('\n\n\n========= Firing ==========')
summarize_alerts(real_alerts)
count = len(real_alerts)
assert status == "success", "Failure queriying the prometheus api at" + url
assert count == 0, "Firing alerts: {0}".format(count)
if __name__ == "__main__":
test_prometheus_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