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