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') |
Oleksii Zhurba | 88bc047 | 2017-11-09 21:04:09 +0000 | [diff] [blame] | 11 | 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 Zhurba | b31323f | 2017-11-20 15:35:19 -0600 | [diff] [blame] | 28 | assert resp.split()[13] == '100.0%', \ |
Oleksii Zhurba | 88bc047 | 2017-11-09 21:04:09 +0000 | [diff] [blame] | 29 | 'elasticsearch status is not good {}'.format( |
| 30 | json.dumps(resp, indent=4)) |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 31 | |
| 32 | |
| 33 | def 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 | |
| 49 | def 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 Zhurba | f2af637 | 2017-11-01 22:53:03 +0000 | [diff] [blame] | 56 | for line in salt_output[salt_output.keys()[0]].split('\n')[1:]: |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 57 | shift = 0 |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 58 | 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)) |