Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 1 | import requests |
| 2 | import csv |
| 3 | import json |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 4 | import pytest |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 5 | |
| 6 | |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 7 | @pytest.mark.full |
| 8 | #probably in sl |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 9 | def 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)) |