blob: a9623db17606580e73176ec93b70a49e68044589 [file] [log] [blame]
Oleksii Zhurba1f17f6c2017-10-31 18:41:03 +00001import requests
2import csv
3import json
4
5
6def test_oss_status(local_salt_client):
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -05007 HAPROXY_STATS_IP = local_salt_client.pillar_get(
8 tgt='docker:swarm:role:master',
9 param='haproxy:proxy:listen:stats:binds:address')
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050010 proxies = {"http": None, "https": None}
Oleksii Zhurba1f17f6c2017-10-31 18:41:03 +000011 csv_result = requests.get('http://{}:9600/haproxy?stats;csv"'.format(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050012 HAPROXY_STATS_IP),
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050013 proxies=proxies).content
Oleksii Zhurba1f17f6c2017-10-31 18:41:03 +000014 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 Zhurba4bfd2ee2019-04-10 21:56:58 -050019 check = local_salt_client.test_ping(tgt='{}:client'.format(service))
Oleksii Zhurba1f17f6c2017-10-31 18:41:03 +000020 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))