Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 1 | import json |
| 2 | import requests |
| 3 | |
| 4 | |
| 5 | def test_elasticsearch_cluster(local_salt_client): |
| 6 | assert requests.get('http://log:9200/').status_code == 200, \ |
| 7 | 'Cannot check elasticsearch url. Info:' |
| 8 | |
| 9 | |
| 10 | def 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 | |
| 26 | def 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 = {} |
| 33 | for line in salt_output[salt_output.keys()[1]].split('\n')[1:]: |
| 34 | 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)) |