blob: f8806f66a5390653e3f94cb0ca7d41cd03d9e30b [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')
11 IP = salt_output[salt_output.keys()[0]]
12 assert requests.get('http://{}:9200/'.format(IP)).status_code == 200, \
13 'Cannot check elasticsearch url on {}.'.format(IP)
Oleksii Zhurba020fab42017-11-01 20:13:28 +000014
15
16def test_stacklight_services_replicas(local_salt_client):
17 salt_output = local_salt_client.cmd(
18 'docker:client:stack:monitoring',
19 'cmd.run',
20 ['docker service ls'],
21 expr_form='pillar')
22 wrong_items = []
23 for line in salt_output[salt_output.keys()[0]].split('\n'):
24 if line[line.find('/') - 1] != line[line.find('/') + 1] \
25 and 'replicated' in line:
26 wrong_items.append(line)
27 assert len(wrong_items) == 0, \
28 '''Some monitoring services doesn't have expected number of replicas:
29 {}'''.format(json.dumps(wrong_items, indent=4))
30
31
32def test_stacklight_containers_status(local_salt_client):
33 salt_output = local_salt_client.cmd(
34 'docker:swarm:role:master',
35 'cmd.run',
36 ['docker service ps $(docker stack services -q monitoring)'],
37 expr_form='pillar')
38 result = {}
Oleksii Zhurbaf2af6372017-11-01 22:53:03 +000039 for line in salt_output[salt_output.keys()[0]].split('\n')[1:]:
Oleksii Zhurba020fab42017-11-01 20:13:28 +000040 shift = 0
Oleksii Zhurbae37cdab2017-11-02 20:00:03 +000041 print line
Oleksii Zhurba020fab42017-11-01 20:13:28 +000042 if line.split()[1] == '\\_':
43 shift = 1
44 if line.split()[1 + shift] not in result.keys():
45 result[line.split()[1]] = 'NOT OK'
46 if line.split()[4 + shift] == 'Running' \
47 or line.split()[4 + shift] == 'Ready':
48 result[line.split()[1 + shift]] = 'OK'
49 assert 'NOT OK' not in result.values(), \
50 '''Some containers are in incorrect state:
51 {}'''.format(json.dumps(result, indent=4))