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): |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 7 | HAPROXY_STATS_IP = local_salt_client.pillar_get( |
| 8 | tgt='docker:swarm:role:master', |
| 9 | param='haproxy:proxy:listen:stats:binds:address') |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 10 | proxies = {"http": None, "https": None} |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 11 | csv_result = requests.get('http://{}:9600/haproxy?stats;csv"'.format( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 12 | HAPROXY_STATS_IP), |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 13 | proxies=proxies).content |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 14 | data = csv_result.lstrip('# ') |
| 15 | wrong_data = [] |
| 16 | list_of_services = ['aptly', 'openldap', 'gerrit', 'jenkins', 'postgresql', |
| 17 | 'pushkin', 'rundeck', 'elasticsearch'] |
| 18 | for service in list_of_services: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 19 | check = local_salt_client.test_ping(tgt='{}:client'.format(service)) |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 20 | if check: |
| 21 | lines = [row for row in csv.DictReader(data.splitlines()) |
| 22 | if service in row['pxname']] |
| 23 | for row in lines: |
| 24 | info = "Service {0} with svname {1} and status {2}".format( |
| 25 | row['pxname'], row['svname'], row['status']) |
| 26 | if row['svname'] == 'FRONTEND' and row['status'] != 'OPEN': |
| 27 | wrong_data.append(info) |
| 28 | if row['svname'] != 'FRONTEND' and row['status'] != 'UP': |
| 29 | wrong_data.append(info) |
| 30 | |
| 31 | assert len(wrong_data) == 0, \ |
| 32 | '''Some haproxy services are in wrong state |
| 33 | {}'''.format(json.dumps(wrong_data, indent=4)) |