Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 1 | import json |
| 2 | import requests |
Oleksii Zhurba | 468e6c7 | 2018-01-16 17:43:15 +0000 | [diff] [blame] | 3 | from cvp_checks import utils |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 4 | |
| 5 | |
| 6 | def test_elasticsearch_cluster(local_salt_client): |
Oleksii Zhurba | e37cdab | 2017-11-02 20:00:03 +0000 | [diff] [blame] | 7 | salt_output = local_salt_client.cmd( |
| 8 | 'elasticsearch:client', |
| 9 | 'pillar.get', |
| 10 | ['_param:haproxy_elasticsearch_bind_host'], |
| 11 | expr_form='pillar') |
Oleksii Zhurba | 88bc047 | 2017-11-09 21:04:09 +0000 | [diff] [blame] | 12 | for node in salt_output.keys(): |
| 13 | IP = salt_output[node] |
| 14 | assert requests.get('http://{}:9200/'.format(IP)).status_code == 200, \ |
| 15 | 'Cannot check elasticsearch url on {}.'.format(IP) |
| 16 | resp = requests.get('http://{}:9200/_cat/health'.format(IP)).content |
| 17 | assert resp.split()[3] == 'green', \ |
| 18 | 'elasticsearch status is not good {}'.format( |
Oleksii Zhurba | 0c039ee | 2018-01-16 19:44:53 +0000 | [diff] [blame] | 19 | json.dumps(resp, indent=4)) |
Oleksii Zhurba | 88bc047 | 2017-11-09 21:04:09 +0000 | [diff] [blame] | 20 | assert resp.split()[4] == '3', \ |
| 21 | 'elasticsearch status is not good {}'.format( |
Oleksii Zhurba | 0c039ee | 2018-01-16 19:44:53 +0000 | [diff] [blame] | 22 | json.dumps(resp, indent=4)) |
Oleksii Zhurba | 88bc047 | 2017-11-09 21:04:09 +0000 | [diff] [blame] | 23 | assert resp.split()[5] == '3', \ |
| 24 | 'elasticsearch status is not good {}'.format( |
Oleksii Zhurba | 0c039ee | 2018-01-16 19:44:53 +0000 | [diff] [blame] | 25 | json.dumps(resp, indent=4)) |
Oleksii Zhurba | 88bc047 | 2017-11-09 21:04:09 +0000 | [diff] [blame] | 26 | assert resp.split()[10] == '0', \ |
| 27 | 'elasticsearch status is not good {}'.format( |
Oleksii Zhurba | 0c039ee | 2018-01-16 19:44:53 +0000 | [diff] [blame] | 28 | json.dumps(resp, indent=4)) |
Oleksii Zhurba | b31323f | 2017-11-20 15:35:19 -0600 | [diff] [blame] | 29 | assert resp.split()[13] == '100.0%', \ |
Oleksii Zhurba | 88bc047 | 2017-11-09 21:04:09 +0000 | [diff] [blame] | 30 | 'elasticsearch status is not good {}'.format( |
Oleksii Zhurba | 0c039ee | 2018-01-16 19:44:53 +0000 | [diff] [blame] | 31 | json.dumps(resp, indent=4)) |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 32 | |
| 33 | |
| 34 | def test_stacklight_services_replicas(local_salt_client): |
| 35 | salt_output = local_salt_client.cmd( |
| 36 | 'docker:client:stack:monitoring', |
| 37 | 'cmd.run', |
| 38 | ['docker service ls'], |
| 39 | expr_form='pillar') |
| 40 | wrong_items = [] |
| 41 | for line in salt_output[salt_output.keys()[0]].split('\n'): |
| 42 | if line[line.find('/') - 1] != line[line.find('/') + 1] \ |
| 43 | and 'replicated' in line: |
| 44 | wrong_items.append(line) |
| 45 | assert len(wrong_items) == 0, \ |
| 46 | '''Some monitoring services doesn't have expected number of replicas: |
| 47 | {}'''.format(json.dumps(wrong_items, indent=4)) |
| 48 | |
| 49 | |
Oleksii Zhurba | 468e6c7 | 2018-01-16 17:43:15 +0000 | [diff] [blame] | 50 | def test_prometheus_alert_count(local_salt_client): |
| 51 | IP = utils.get_monitoring_ip('cluster_public_host') |
| 52 | # keystone:server can return 3 nodes instead of 1 |
| 53 | # this will be fixed later |
| 54 | # TODO |
Oleksii Zhurba | 0c039ee | 2018-01-16 19:44:53 +0000 | [diff] [blame] | 55 | nodes_info = local_salt_client.cmd( |
Oleksii Zhurba | 468e6c7 | 2018-01-16 17:43:15 +0000 | [diff] [blame] | 56 | 'keystone:server', |
| 57 | 'cmd.run', |
Oleksii Zhurba | 0c039ee | 2018-01-16 19:44:53 +0000 | [diff] [blame] | 58 | ['curl -s http://{}:15010/alerts | grep icon-chevron-down | ' |
| 59 | 'grep -v "0 active"'.format(IP)], |
Oleksii Zhurba | 468e6c7 | 2018-01-16 17:43:15 +0000 | [diff] [blame] | 60 | expr_form='pillar') |
Oleksii Zhurba | 0c039ee | 2018-01-16 19:44:53 +0000 | [diff] [blame] | 61 | result = nodes_info[nodes_info.keys()[0]].replace('</td>', '').replace( |
| 62 | '<td><i class="icon-chevron-down"></i> <b>', '').replace('</b>', '') |
| 63 | assert result == '', 'AlertManager page has some alerts! {}'.format( |
| 64 | json.dumps(result), indent=4) |
Oleksii Zhurba | 468e6c7 | 2018-01-16 17:43:15 +0000 | [diff] [blame] | 65 | |
| 66 | |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 67 | def test_stacklight_containers_status(local_salt_client): |
| 68 | salt_output = local_salt_client.cmd( |
| 69 | 'docker:swarm:role:master', |
| 70 | 'cmd.run', |
| 71 | ['docker service ps $(docker stack services -q monitoring)'], |
| 72 | expr_form='pillar') |
| 73 | result = {} |
Oleksii Zhurba | 468e6c7 | 2018-01-16 17:43:15 +0000 | [diff] [blame] | 74 | # for old reclass models, docker:swarm:role:master can return |
| 75 | # 2 nodes instead of one. Here is temporary fix. |
| 76 | # TODO |
| 77 | if len(salt_output.keys()) > 1: |
| 78 | if 'CURRENT STATE' not in salt_output[salt_output.keys()[0]]: |
| 79 | del salt_output[salt_output.keys()[0]] |
Oleksii Zhurba | f2af637 | 2017-11-01 22:53:03 +0000 | [diff] [blame] | 80 | for line in salt_output[salt_output.keys()[0]].split('\n')[1:]: |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 81 | shift = 0 |
Oleksii Zhurba | 020fab4 | 2017-11-01 20:13:28 +0000 | [diff] [blame] | 82 | if line.split()[1] == '\\_': |
| 83 | shift = 1 |
| 84 | if line.split()[1 + shift] not in result.keys(): |
| 85 | result[line.split()[1]] = 'NOT OK' |
| 86 | if line.split()[4 + shift] == 'Running' \ |
| 87 | or line.split()[4 + shift] == 'Ready': |
| 88 | result[line.split()[1 + shift]] = 'OK' |
| 89 | assert 'NOT OK' not in result.values(), \ |
| 90 | '''Some containers are in incorrect state: |
| 91 | {}'''.format(json.dumps(result, indent=4)) |