diff --git a/test/README.md b/test/README.md index 5ff076a3f371fb4decbb77fb44d20e889eb3023a..7b4c0d2f6a1bc5fc41b09c217fa23c9678dcadfd 100644 --- a/test/README.md +++ b/test/README.md @@ -1,18 +1,27 @@ # Run testinfra tests -Test host configured in `test/inventory.yml` +Test host configured in `../clusters/CLUSTERNAME/inventory.yml` - py.test -v --ansible-inventory=../inventory.yml --hosts='ansible://*' + export inventory=../clusters/CLUSTERNAME/inventory.yml + + + py.test -v --ansible-inventory=${inventory} --hosts='ansible://*' Specify host manually: py.test -v --hosts='ssh://root@example.openappstack.net' +Run only tests tagged with `prometheus`: + + py.test -v --ansible-inventory=${inventory} --hosts='ansible://*' -m prometheus + +## Cert tests + Run cert test manually using the ansible inventory file: ADDRESS='example.openappstack.net' py.test -v -m 'certs' \ --connection=ansible \ - --ansible-inventory=../ansible/inventory.yml \ + --ansible-inventory=${inventory} \ --hosts='ansible://*' Run cert test manually against a different cluster, not configured in any diff --git a/test/pytest/test_prometheus.py b/test/pytest/test_prometheus.py index 416a97a52dbaed6c20013dcb518ec0d35f50cb33..d7a3fcce70941d6aa9d7febe0c1c89ab2c84fd26 100755 --- a/test/pytest/test_prometheus.py +++ b/test/pytest/test_prometheus.py @@ -6,12 +6,9 @@ import requests def test_prometheus_alerts(host): print("Starting prometheus test...") - #cmd = host.run("hostname") - #print("Hostname: " + cmd.stdout) url = 'http://127.0.0.1:30090/api/v1/alerts' alert_json = json.loads(host.check_output('curl ' + url)) - print(type(alert_json)) status = alert_json["status"] alerts = alert_json["data"]["alerts"] @@ -19,12 +16,11 @@ def test_prometheus_alerts(host): real_alerts = [alert for alert in alerts if alert["labels"]["severity"] != "none"] + alert_names = list(map(lambda alert: alert["labels"]["alertname"], real_alerts)) count = len(real_alerts) - print(json.dumps(real_alerts)) - assert status == "success", "Failure queriying the prometheus api at" + url - assert count == 0, "There are prometheus alerts firing !" + assert count == 0, "Firing alerts: {0}".format(str(alert_names)) if __name__ == "__main__":