Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 1 | import requests |
| 2 | import csv |
| 3 | import json |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 4 | import pytest |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 5 | |
| 6 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 7 | @pytest.mark.full |
| 8 | #probably in sl |
Hanna Arhipova | 50a2167 | 2019-04-25 12:20:52 +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 | """ |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 18 | HAPROXY_STATS_IP = local_salt_client.pillar_get( |
| 19 | tgt='docker:swarm:role:master', |
| 20 | param='haproxy:proxy:listen:stats:binds:address') |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 21 | proxies = {"http": None, "https": None} |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 22 | csv_result = requests.get('http://{}:9600/haproxy?stats;csv"'.format( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 23 | HAPROXY_STATS_IP), |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 24 | proxies=proxies).content.decode() |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 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: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 30 | check = local_salt_client.test_ping(tgt='{}:client'.format(service)) |
Oleksii Zhurba | 1f17f6c | 2017-10-31 18:41:03 +0000 | [diff] [blame] | 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 | |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 42 | assert len(wrong_data) == 0, ( |
| 43 | "Some haproxy services are in wrong state:\n{}".format( |
| 44 | json.dumps(wrong_data, indent=4)) |
| 45 | ) |