]> git-server-git.apps.pok.os.sepia.ceph.com Git - cephmetrics.git/commitdiff
Add some dashboard tests
authorZack Cerza <zack@redhat.com>
Wed, 30 May 2018 21:01:50 +0000 (15:01 -0600)
committerZack Cerza <zack@redhat.com>
Thu, 31 May 2018 18:37:03 +0000 (12:37 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
dashboards/mgr-prometheus/tests/__init__.py [new file with mode: 0644]
dashboards/mgr-prometheus/tests/test_mgr_dashboards.py [new file with mode: 0644]
dashboards/mgr-prometheus/tests/util.py [new symlink]
dashboards/tests/util.py [new file with mode: 0644]
tox.ini

diff --git a/dashboards/mgr-prometheus/tests/__init__.py b/dashboards/mgr-prometheus/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/dashboards/mgr-prometheus/tests/test_mgr_dashboards.py b/dashboards/mgr-prometheus/tests/test_mgr_dashboards.py
new file mode 100644 (file)
index 0000000..4d417f4
--- /dev/null
@@ -0,0 +1,66 @@
+import pytest
+
+from .util import TestDashboards, get_dashboards
+
+
+def walk(obj, callback, parent_key=None, path=None):
+    if path is None:
+        path = '.'
+    if isinstance(obj, dict):
+        for key, value in obj.items():
+            walk(
+                value,
+                callback,
+                parent_key=key,
+                path='{}["{}"]'.format(path, key),
+            )
+    elif isinstance(obj, list):
+        for i in range(len(obj)):
+            walk(
+                obj[i],
+                callback,
+                parent_key=parent_key,
+                path='{}[{}]'.format(path, i),
+            )
+    else:
+        callback(obj, parent_key, path)
+
+
+class TestMgrDashboards(TestDashboards):
+    dashboards = get_dashboards()
+
+    @pytest.mark.parametrize("name", dashboards.keys())
+    def test_type(self, name):
+        assert name
+        obj = self.dashboards[name]
+        assert type(obj) is dict
+
+    @pytest.mark.parametrize("name", dashboards.keys())
+    def test_no_collectd(self, name):
+        def test(item, pkey, path):
+            if type(item) in (basestring, unicode):
+                assert 'collectd' not in item
+        walk(self.dashboards[name], test)
+
+    @pytest.mark.parametrize("name", dashboards.keys())
+    def test_no_ds_local(self, name):
+        def test(item, pkey, path):
+            if type(item) in (basestring, unicode):
+                assert '${DS_LOCAL}' not in item
+        walk(self.dashboards[name], test)
+
+    @pytest.mark.parametrize("name", dashboards.keys())
+    def test_no_influxdb_dstype(self, name):
+        def test(item, pkey, path):
+            if pkey == 'dsType' and type(item) in (basestring, unicode):
+                assert 'influxdb' not in item
+        walk(self.dashboards[name], test)
+
+    @pytest.mark.parametrize("name", dashboards.keys())
+    def test_no_influxdb_query(self, name):
+        def test(item, pkey, path):
+            if pkey == 'query':
+                assert 'SELECT' not in item
+                assert 'FROM' not in item
+                assert 'WHERE' not in item
+        walk(self.dashboards[name], test)
diff --git a/dashboards/mgr-prometheus/tests/util.py b/dashboards/mgr-prometheus/tests/util.py
new file mode 120000 (symlink)
index 0000000..47f38a1
--- /dev/null
@@ -0,0 +1 @@
+../../tests/util.py
\ No newline at end of file
diff --git a/dashboards/tests/util.py b/dashboards/tests/util.py
new file mode 100644 (file)
index 0000000..5b04e88
--- /dev/null
@@ -0,0 +1,27 @@
+import os
+import json
+
+
+def get_dashboards():
+    dashboards = dict()
+    db_dir = os.path.realpath(
+        os.path.join(
+            os.path.dirname(__file__),
+            '..',
+        )
+    )
+    for item in os.listdir(db_dir):
+        if item.endswith('.json'):
+            db_path = os.path.join(
+                os.path.dirname(__file__),
+                '..',
+                item,
+            )
+            dashboards[item] = json.loads(
+                open(db_path).read()
+            )
+    return dashboards
+
+
+class TestDashboards(object):
+    dashboards = None
diff --git a/tox.ini b/tox.ini
index 4f3396397dae41d1cbdddacc1240f65a1cd81ac9..b6d8eb3fa7e50368174721f55857ae8833386dcc 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
 [tox]
 skipsdist = True
-envlist=ansible-lint,ansible-syntax,flake8
+envlist=ansible-lint,ansible-syntax,flake8,dashboards
 
 [testenv:ansible-lint]
 install_command = pip install --upgrade {opts} {packages}
@@ -37,3 +37,11 @@ deps=
 changedir=ansible
 commands=
   py.test -v -n auto --connection=ansible --ansible-inventory {posargs} ./roles/
+
+[testenv:dashboards]
+install_command = pip install --upgrade {opts} {packages}
+deps=
+  pytest
+changedir=dashboards
+commands=
+  py.test -v ./