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): |
Oleksii Zhurba | e37cdab | 2017-11-02 20:00:03 +0000 | [diff] [blame^] | 6 | 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 Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | def 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 | |
| 32 | def 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 Zhurba | f2af637 | 2017-11-01 22:53:03 +0000 | [diff] [blame] | 39 | for line in salt_output[salt_output.keys()[0]].split('\n')[1:]: |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 40 | shift = 0 |
Oleksii Zhurba | e37cdab | 2017-11-02 20:00:03 +0000 | [diff] [blame^] | 41 | print line |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 42 | 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)) |