blob: 02bb7bc04ac197dc5fe92e142df05d34e52df1f7 [file] [log] [blame]
Oleksii Zhurba020fab42017-11-01 20:13:28 +00001import json
2import requests
3
4
5def test_elasticsearch_cluster(local_salt_client):
6 assert requests.get('http://log:9200/').status_code == 200, \
7 'Cannot check elasticsearch url. Info:'
8
9
10def test_stacklight_services_replicas(local_salt_client):
11 salt_output = local_salt_client.cmd(
12 'docker:client:stack:monitoring',
13 'cmd.run',
14 ['docker service ls'],
15 expr_form='pillar')
16 wrong_items = []
17 for line in salt_output[salt_output.keys()[0]].split('\n'):
18 if line[line.find('/') - 1] != line[line.find('/') + 1] \
19 and 'replicated' in line:
20 wrong_items.append(line)
21 assert len(wrong_items) == 0, \
22 '''Some monitoring services doesn't have expected number of replicas:
23 {}'''.format(json.dumps(wrong_items, indent=4))
24
25
26def test_stacklight_containers_status(local_salt_client):
27 salt_output = local_salt_client.cmd(
28 'docker:swarm:role:master',
29 'cmd.run',
30 ['docker service ps $(docker stack services -q monitoring)'],
31 expr_form='pillar')
32 result = {}
Oleksii Zhurbaf2af6372017-11-01 22:53:03 +000033 for line in salt_output[salt_output.keys()[0]].split('\n')[1:]:
Oleksii Zhurba020fab42017-11-01 20:13:28 +000034 shift = 0
35 if line.split()[1] == '\\_':
36 shift = 1
37 if line.split()[1 + shift] not in result.keys():
38 result[line.split()[1]] = 'NOT OK'
39 if line.split()[4 + shift] == 'Running' \
40 or line.split()[4 + shift] == 'Ready':
41 result[line.split()[1 + shift]] = 'OK'
42 assert 'NOT OK' not in result.values(), \
43 '''Some containers are in incorrect state:
44 {}'''.format(json.dumps(result, indent=4))