Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 1 | import requests |
| 2 | import csv |
| 3 | import json |
| 4 | |
| 5 | |
| 6 | def test_oss_status(local_salt_client): |
| 7 | result = local_salt_client.cmd( |
| 8 | 'docker:swarm:role:master', |
| 9 | 'pillar.fetch', |
| 10 | ['haproxy:proxy:listen:stats:binds:address'], |
| 11 | expr_form='pillar') |
| 12 | HAPROXY_STATS_IP = [node for node in result if result[node]] |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 13 | proxies = {"http": None, "https": None} |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 14 | csv_result = requests.get('http://{}:9600/haproxy?stats;csv"'.format( |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 15 | result[HAPROXY_STATS_IP[0]]), |
| 16 | proxies=proxies).content |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 17 | data = csv_result.lstrip('# ') |
| 18 | wrong_data = [] |
| 19 | list_of_services = ['aptly', 'openldap', 'gerrit', 'jenkins', 'postgresql', |
| 20 | 'pushkin', 'rundeck', 'elasticsearch'] |
| 21 | for service in list_of_services: |
| 22 | check = local_salt_client.cmd( |
| 23 | '{}:client'.format(service), |
| 24 | 'test.ping', |
| 25 | expr_form='pillar') |
| 26 | if check: |
| 27 | lines = [row for row in csv.DictReader(data.splitlines()) |
| 28 | if service in row['pxname']] |
| 29 | for row in lines: |
| 30 | info = "Service {0} with svname {1} and status {2}".format( |
| 31 | row['pxname'], row['svname'], row['status']) |
| 32 | if row['svname'] == 'FRONTEND' and row['status'] != 'OPEN': |
| 33 | wrong_data.append(info) |
| 34 | if row['svname'] != 'FRONTEND' and row['status'] != 'UP': |
| 35 | wrong_data.append(info) |
| 36 | |
| 37 | assert len(wrong_data) == 0, \ |
| 38 | '''Some haproxy services are in wrong state |
| 39 | {}'''.format(json.dumps(wrong_data, indent=4)) |