blob: 4b42f15173eb8a968433ff2beb44f0e4fda4f582 [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]]
13 csv_result = requests.get('http://{}:9600/haproxy?stats;csv"'.format(
14 result[HAPROXY_STATS_IP[0]])).content
15 data = csv_result.lstrip('# ')
16 wrong_data = []
17 list_of_services = ['aptly', 'openldap', 'gerrit', 'jenkins', 'postgresql',
18 'pushkin', 'rundeck', 'elasticsearch']
19 for service in list_of_services:
20 check = local_salt_client.cmd(
21 '{}:client'.format(service),
22 'test.ping',
23 expr_form='pillar')
24 if check:
25 lines = [row for row in csv.DictReader(data.splitlines())
26 if service in row['pxname']]
27 for row in lines:
28 info = "Service {0} with svname {1} and status {2}".format(
29 row['pxname'], row['svname'], row['status'])
30 if row['svname'] == 'FRONTEND' and row['status'] != 'OPEN':
31 wrong_data.append(info)
32 if row['svname'] != 'FRONTEND' and row['status'] != 'UP':
33 wrong_data.append(info)
34
35 assert len(wrong_data) == 0, \
36 '''Some haproxy services are in wrong state
37 {}'''.format(json.dumps(wrong_data, indent=4))