Add some stacklight tests
diff --git a/cvp_checks/tests/test_stacklight.py b/cvp_checks/tests/test_stacklight.py
new file mode 100644
index 0000000..d839042
--- /dev/null
+++ b/cvp_checks/tests/test_stacklight.py
@@ -0,0 +1,44 @@
+import json
+import requests
+
+
+def test_elasticsearch_cluster(local_salt_client):
+ assert requests.get('http://log:9200/').status_code == 200, \
+ 'Cannot check elasticsearch url. Info:'
+
+
+def test_stacklight_services_replicas(local_salt_client):
+ salt_output = local_salt_client.cmd(
+ 'docker:client:stack:monitoring',
+ 'cmd.run',
+ ['docker service ls'],
+ expr_form='pillar')
+ wrong_items = []
+ for line in salt_output[salt_output.keys()[0]].split('\n'):
+ if line[line.find('/') - 1] != line[line.find('/') + 1] \
+ and 'replicated' in line:
+ wrong_items.append(line)
+ assert len(wrong_items) == 0, \
+ '''Some monitoring services doesn't have expected number of replicas:
+ {}'''.format(json.dumps(wrong_items, indent=4))
+
+
+def test_stacklight_containers_status(local_salt_client):
+ salt_output = local_salt_client.cmd(
+ 'docker:swarm:role:master',
+ 'cmd.run',
+ ['docker service ps $(docker stack services -q monitoring)'],
+ expr_form='pillar')
+ result = {}
+ for line in salt_output[salt_output.keys()[1]].split('\n')[1:]:
+ shift = 0
+ if line.split()[1] == '\\_':
+ shift = 1
+ if line.split()[1 + shift] not in result.keys():
+ result[line.split()[1]] = 'NOT OK'
+ if line.split()[4 + shift] == 'Running' \
+ or line.split()[4 + shift] == 'Ready':
+ result[line.split()[1 + shift]] = 'OK'
+ assert 'NOT OK' not in result.values(), \
+ '''Some containers are in incorrect state:
+ {}'''.format(json.dumps(result, indent=4))
diff --git a/cvp_checks/tests/test_ui_addresses.py b/cvp_checks/tests/test_ui_addresses.py
new file mode 100644
index 0000000..565da42
--- /dev/null
+++ b/cvp_checks/tests/test_ui_addresses.py
@@ -0,0 +1,68 @@
+from cvp_checks import utils
+import pytest
+
+
+def test_ui_horizon(local_salt_client):
+ salt_output = local_salt_client.cmd(
+ 'horizon:server',
+ 'pillar.get',
+ ['_param:openstack_proxy_address'],
+ expr_form='pillar')
+ IP = [salt_output[node] for node in salt_output
+ if salt_output[node]]
+ result = local_salt_client.cmd(
+ 'keystone:server',
+ 'cmd.run',
+ ['curl --insecure https://{}/auth/login/ 2>&1 | \
+ grep Login'.format(IP[0])],
+ expr_form='pillar')
+ assert len(result[result.keys()[0]]) != 0, \
+ 'Horizon login page is not reachable on {} from ctl nodes'.format(
+ IP[0])
+
+
+def test_ui_kibana(local_salt_client):
+ IP = utils.get_monitoring_ip('stacklight_log_address')
+ result = local_salt_client.cmd(
+ 'keystone:server',
+ 'cmd.run',
+ ['curl http://{}:5601/app/kibana 2>&1 | \
+ grep loading'.format(IP)],
+ expr_form='pillar')
+ assert len(result[result.keys()[0]]) != 0, \
+ 'Kibana login page is not reachable on {} from ctl nodes'.format(IP)
+
+
+def test_ui_prometheus(local_salt_client):
+ pytest.skip("This test doesn't work. Skipped")
+ IP = utils.get_monitoring_ip('keepalived_prometheus_vip_address')
+ result = local_salt_client.cmd(
+ 'keystone:server',
+ 'cmd.run',
+ ['curl http://{}:15010/ 2>&1 | \
+ grep loading'.format(IP)],
+ expr_form='pillar')
+ assert len(result[result.keys()[0]]) != 0, \
+ 'Prometheus page is not reachable on {} from ctl nodes'.format(IP)
+
+
+def test_ui_alert_manager(local_salt_client):
+ IP = utils.get_monitoring_ip('cluster_public_host')
+ result = local_salt_client.cmd(
+ 'keystone:server',
+ 'cmd.run',
+ ['curl http://{}:15011/ 2>&1 | grep AlertManager'.format(IP)],
+ expr_form='pillar')
+ assert len(result[result.keys()[0]]) != 0, \
+ 'AlertManager page is not reachable on {} from ctl nodes'.format(IP)
+
+
+def test_ui_grafana(local_salt_client):
+ IP = utils.get_monitoring_ip('cluster_public_host')
+ result = local_salt_client.cmd(
+ 'keystone:server',
+ 'cmd.run',
+ ['curl http://{}:15013/login 2>&1 | grep Grafana'.format(IP)],
+ expr_form='pillar')
+ assert len(result[result.keys()[0]]) != 0, \
+ 'Grafana page is not reachable on {} from ctl nodes'.format(IP)
diff --git a/cvp_checks/utils/__init__.py b/cvp_checks/utils/__init__.py
index 4475683..c05a281 100644
--- a/cvp_checks/utils/__init__.py
+++ b/cvp_checks/utils/__init__.py
@@ -36,6 +36,16 @@
return result.strip(' ' + separator + ' ')
+def get_monitoring_ip(param_name):
+ local_salt_client = init_salt_client()
+ salt_output = local_salt_client.cmd(
+ 'docker:client:stack:monitoring',
+ 'pillar.get',
+ ['_param:{}'.format(param_name)],
+ expr_form='pillar')
+ return salt_output[salt_output.keys()[0]]
+
+
def get_active_nodes(test=None):
config = get_configuration()
local_salt_client = init_salt_client()