blob: 8a63f1b66ce958dc7794a15e3b9a62ca001ab4c5 [file] [log] [blame]
Oleksii Zhurba020fab42017-11-01 20:13:28 +00001import json
2import requests
Oleksii Zhurba468e6c72018-01-16 17:43:15 +00003from cvp_checks import utils
Oleksii Zhurba020fab42017-11-01 20:13:28 +00004
5
6def test_elasticsearch_cluster(local_salt_client):
Oleksii Zhurbae37cdab2017-11-02 20:00:03 +00007 salt_output = local_salt_client.cmd(
8 'elasticsearch:client',
9 'pillar.get',
10 ['_param:haproxy_elasticsearch_bind_host'],
11 expr_form='pillar')
Oleksii Zhurba88bc0472017-11-09 21:04:09 +000012 for node in salt_output.keys():
13 IP = salt_output[node]
14 assert requests.get('http://{}:9200/'.format(IP)).status_code == 200, \
15 'Cannot check elasticsearch url on {}.'.format(IP)
16 resp = requests.get('http://{}:9200/_cat/health'.format(IP)).content
17 assert resp.split()[3] == 'green', \
18 'elasticsearch status is not good {}'.format(
Oleksii Zhurba0c039ee2018-01-16 19:44:53 +000019 json.dumps(resp, indent=4))
Oleksii Zhurba88bc0472017-11-09 21:04:09 +000020 assert resp.split()[4] == '3', \
21 'elasticsearch status is not good {}'.format(
Oleksii Zhurba0c039ee2018-01-16 19:44:53 +000022 json.dumps(resp, indent=4))
Oleksii Zhurba88bc0472017-11-09 21:04:09 +000023 assert resp.split()[5] == '3', \
24 'elasticsearch status is not good {}'.format(
Oleksii Zhurba0c039ee2018-01-16 19:44:53 +000025 json.dumps(resp, indent=4))
Oleksii Zhurba88bc0472017-11-09 21:04:09 +000026 assert resp.split()[10] == '0', \
27 'elasticsearch status is not good {}'.format(
Oleksii Zhurba0c039ee2018-01-16 19:44:53 +000028 json.dumps(resp, indent=4))
Oleksii Zhurbab31323f2017-11-20 15:35:19 -060029 assert resp.split()[13] == '100.0%', \
Oleksii Zhurba88bc0472017-11-09 21:04:09 +000030 'elasticsearch status is not good {}'.format(
Oleksii Zhurba0c039ee2018-01-16 19:44:53 +000031 json.dumps(resp, indent=4))
Oleksii Zhurba020fab42017-11-01 20:13:28 +000032
33
34def test_stacklight_services_replicas(local_salt_client):
35 salt_output = local_salt_client.cmd(
36 'docker:client:stack:monitoring',
37 'cmd.run',
38 ['docker service ls'],
39 expr_form='pillar')
40 wrong_items = []
41 for line in salt_output[salt_output.keys()[0]].split('\n'):
42 if line[line.find('/') - 1] != line[line.find('/') + 1] \
43 and 'replicated' in line:
44 wrong_items.append(line)
45 assert len(wrong_items) == 0, \
46 '''Some monitoring services doesn't have expected number of replicas:
47 {}'''.format(json.dumps(wrong_items, indent=4))
48
49
Oleksii Zhurba468e6c72018-01-16 17:43:15 +000050def test_prometheus_alert_count(local_salt_client):
51 IP = utils.get_monitoring_ip('cluster_public_host')
52 # keystone:server can return 3 nodes instead of 1
53 # this will be fixed later
54 # TODO
Oleksii Zhurba0c039ee2018-01-16 19:44:53 +000055 nodes_info = local_salt_client.cmd(
Oleksii Zhurba468e6c72018-01-16 17:43:15 +000056 'keystone:server',
57 'cmd.run',
Oleksii Zhurba0c039ee2018-01-16 19:44:53 +000058 ['curl -s http://{}:15010/alerts | grep icon-chevron-down | '
59 'grep -v "0 active"'.format(IP)],
Oleksii Zhurba468e6c72018-01-16 17:43:15 +000060 expr_form='pillar')
Oleksii Zhurba0c039ee2018-01-16 19:44:53 +000061 result = nodes_info[nodes_info.keys()[0]].replace('</td>', '').replace(
62 '<td><i class="icon-chevron-down"></i> <b>', '').replace('</b>', '')
63 assert result == '', 'AlertManager page has some alerts! {}'.format(
64 json.dumps(result), indent=4)
Oleksii Zhurba468e6c72018-01-16 17:43:15 +000065
66
Oleksii Zhurba020fab42017-11-01 20:13:28 +000067def test_stacklight_containers_status(local_salt_client):
68 salt_output = local_salt_client.cmd(
69 'docker:swarm:role:master',
70 'cmd.run',
71 ['docker service ps $(docker stack services -q monitoring)'],
72 expr_form='pillar')
73 result = {}
Oleksii Zhurba468e6c72018-01-16 17:43:15 +000074 # for old reclass models, docker:swarm:role:master can return
75 # 2 nodes instead of one. Here is temporary fix.
76 # TODO
77 if len(salt_output.keys()) > 1:
78 if 'CURRENT STATE' not in salt_output[salt_output.keys()[0]]:
79 del salt_output[salt_output.keys()[0]]
Oleksii Zhurbaf2af6372017-11-01 22:53:03 +000080 for line in salt_output[salt_output.keys()[0]].split('\n')[1:]:
Oleksii Zhurba020fab42017-11-01 20:13:28 +000081 shift = 0
Oleksii Zhurba020fab42017-11-01 20:13:28 +000082 if line.split()[1] == '\\_':
83 shift = 1
84 if line.split()[1 + shift] not in result.keys():
85 result[line.split()[1]] = 'NOT OK'
86 if line.split()[4 + shift] == 'Running' \
87 or line.split()[4 + shift] == 'Ready':
88 result[line.split()[1 + shift]] = 'OK'
89 assert 'NOT OK' not in result.values(), \
90 '''Some containers are in incorrect state:
91 {}'''.format(json.dumps(result, indent=4))