blob: 58a4151dec40b4f83a19ee01c29631047747422c [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):
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 Zhurbae592ed12018-06-21 18:01:09 -050013 proxies = {"http": None, "https": None}
Oleksii Zhurba1f17f6c2017-10-31 18:41:03 +000014 csv_result = requests.get('http://{}:9600/haproxy?stats;csv"'.format(
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050015 result[HAPROXY_STATS_IP[0]]),
16 proxies=proxies).content
Oleksii Zhurba1f17f6c2017-10-31 18:41:03 +000017 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))