Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame^] | 3 | import os |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 4 | from cvp_checks import utils |
| 5 | |
| 6 | |
| 7 | @pytest.mark.parametrize( |
| 8 | "group", |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame^] | 9 | utils.get_groups(os.path.basename(__file__)) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 10 | ) |
| 11 | def test_check_services(local_salt_client, group): |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame^] | 12 | if "skipped" in group: |
| 13 | pytest.skip("skipped in config") |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 14 | output = local_salt_client.cmd(group, 'service.get_all', expr_form='pcre') |
| 15 | |
| 16 | if len(output.keys()) < 2: |
| 17 | pytest.skip("Nothing to compare - only 1 node") |
| 18 | |
| 19 | nodes = [] |
| 20 | pkts_data = [] |
| 21 | my_set = set() |
| 22 | |
| 23 | for node in output: |
| 24 | nodes.append(node) |
| 25 | my_set.update(output[node]) |
| 26 | |
| 27 | for srv in my_set: |
| 28 | diff = [] |
| 29 | row = [] |
| 30 | for node in nodes: |
| 31 | if srv in output[node]: |
| 32 | diff.append(srv) |
| 33 | row.append("{}: +".format(node)) |
| 34 | else: |
| 35 | row.append("{}: No service".format(node)) |
| 36 | if diff.count(diff[0]) < len(nodes): |
| 37 | row.sort() |
| 38 | row.insert(0, srv) |
| 39 | pkts_data.append(row) |
| 40 | assert len(pkts_data) <= 1, \ |
| 41 | "Several problems found for {0} group: {1}".format( |
| 42 | group, json.dumps(pkts_data, indent=4)) |