blob: e2446c198071032d1d1ed90d172deabf0e0d0e70 [file] [log] [blame]
Oleksii Zhurba020fab42017-11-01 20:13:28 +00001import json
2import requests
3
4
5def test_elasticsearch_cluster(local_salt_client):
Oleksii Zhurbae37cdab2017-11-02 20:00:03 +00006 salt_output = local_salt_client.cmd(
7 'elasticsearch:client',
8 'pillar.get',
9 ['_param:haproxy_elasticsearch_bind_host'],
10 expr_form='pillar')
Oleksii Zhurba88bc0472017-11-09 21:04:09 +000011 for node in salt_output.keys():
12 IP = salt_output[node]
13 assert requests.get('http://{}:9200/'.format(IP)).status_code == 200, \
14 'Cannot check elasticsearch url on {}.'.format(IP)
15 resp = requests.get('http://{}:9200/_cat/health'.format(IP)).content
16 assert resp.split()[3] == 'green', \
17 'elasticsearch status is not good {}'.format(
18 json.dumps(resp, indent=4))
19 assert resp.split()[4] == '3', \
20 'elasticsearch status is not good {}'.format(
21 json.dumps(resp, indent=4))
22 assert resp.split()[5] == '3', \
23 'elasticsearch status is not good {}'.format(
24 json.dumps(resp, indent=4))
25 assert resp.split()[10] == '0', \
26 'elasticsearch status is not good {}'.format(
27 json.dumps(resp, indent=4))
Oleksii Zhurbab31323f2017-11-20 15:35:19 -060028 assert resp.split()[13] == '100.0%', \
Oleksii Zhurba88bc0472017-11-09 21:04:09 +000029 'elasticsearch status is not good {}'.format(
30 json.dumps(resp, indent=4))
Oleksii Zhurba020fab42017-11-01 20:13:28 +000031
32
33def test_stacklight_services_replicas(local_salt_client):
34 salt_output = local_salt_client.cmd(
35 'docker:client:stack:monitoring',
36 'cmd.run',
37 ['docker service ls'],
38 expr_form='pillar')
39 wrong_items = []
40 for line in salt_output[salt_output.keys()[0]].split('\n'):
41 if line[line.find('/') - 1] != line[line.find('/') + 1] \
42 and 'replicated' in line:
43 wrong_items.append(line)
44 assert len(wrong_items) == 0, \
45 '''Some monitoring services doesn't have expected number of replicas:
46 {}'''.format(json.dumps(wrong_items, indent=4))
47
48
49def test_stacklight_containers_status(local_salt_client):
50 salt_output = local_salt_client.cmd(
51 'docker:swarm:role:master',
52 'cmd.run',
53 ['docker service ps $(docker stack services -q monitoring)'],
54 expr_form='pillar')
55 result = {}
Oleksii Zhurbaf2af6372017-11-01 22:53:03 +000056 for line in salt_output[salt_output.keys()[0]].split('\n')[1:]:
Oleksii Zhurba020fab42017-11-01 20:13:28 +000057 shift = 0
Oleksii Zhurba020fab42017-11-01 20:13:28 +000058 if line.split()[1] == '\\_':
59 shift = 1
60 if line.split()[1 + shift] not in result.keys():
61 result[line.split()[1]] = 'NOT OK'
62 if line.split()[4 + shift] == 'Running' \
63 or line.split()[4 + shift] == 'Ready':
64 result[line.split()[1 + shift]] = 'OK'
65 assert 'NOT OK' not in result.values(), \
66 '''Some containers are in incorrect state:
67 {}'''.format(json.dumps(result, indent=4))