blob: 9e919c511f5d716ad12a5fa4734af47f959f428a [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import requests
2import csv
3import json
4
5
6def test_oss_status(local_salt_client, check_cicd):
7 """
8 # Get IP of HAPROXY interface from pillar using 'salt -C "I@docker:swarm:role:master" pillar.get haproxy:proxy:listen:stats:binds:address'
9 # Read info from web-page "http://{haproxy:proxy:listen:stats:binds:address}:9600/haproxy?stats;csv"
10 # Check that each service from list 'aptly', 'openldap', 'gerrit', 'jenkins', 'postgresql',
11 'pushkin', 'rundeck', 'elasticsearch' :
12 * has UP status
13 * has OPEN status
14 """
15 HAPROXY_STATS_IP = local_salt_client.pillar_get(
16 tgt='docker:swarm:role:master',
17 param='haproxy:proxy:listen:stats:binds:address')
18 proxies = {"http": None, "https": None}
19 csv_result = requests.get('http://{}:9600/haproxy?stats;csv"'.format(
20 HAPROXY_STATS_IP),
21 proxies=proxies).content
22 data = csv_result.lstrip('# ')
23 wrong_data = []
24 list_of_services = ['aptly', 'openldap', 'gerrit', 'jenkins', 'postgresql',
25 'pushkin', 'rundeck', 'elasticsearch']
26 for service in list_of_services:
27 check = local_salt_client.test_ping(tgt='{}:client'.format(service))
28 if check:
29 lines = [row for row in csv.DictReader(data.splitlines())
30 if service in row['pxname']]
31 for row in lines:
32 info = "Service {0} with svname {1} and status {2}".format(
33 row['pxname'], row['svname'], row['status'])
34 if row['svname'] == 'FRONTEND' and row['status'] != 'OPEN':
35 wrong_data.append(info)
36 if row['svname'] != 'FRONTEND' and row['status'] != 'UP':
37 wrong_data.append(info)
38
39 assert len(wrong_data) == 0, \
40 '''Some haproxy services are in wrong state
41 {}'''.format(json.dumps(wrong_data, indent=4))