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 | e0dedb5 | 2018-01-16 00:55:25 +0000 | [diff] [blame] | 9 | utils.node_groups.keys() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 10 | ) |
| 11 | def test_check_package_versions(local_salt_client, group): |
Oleksii Zhurba | e0dedb5 | 2018-01-16 00:55:25 +0000 | [diff] [blame] | 12 | output = local_salt_client.cmd("L@"+','.join(utils.node_groups[group]), 'lowpkg.list_pkgs', expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 13 | |
| 14 | if len(output.keys()) < 2: |
| 15 | pytest.skip("Nothing to compare - only 1 node") |
| 16 | |
| 17 | nodes = [] |
| 18 | pkts_data = [] |
| 19 | my_set = set() |
| 20 | |
| 21 | for node in output: |
| 22 | nodes.append(node) |
| 23 | my_set.update(output[node].keys()) |
| 24 | |
| 25 | for deb in my_set: |
| 26 | diff = [] |
| 27 | row = [] |
| 28 | for node in nodes: |
| 29 | if deb in output[node].keys(): |
| 30 | diff.append(output[node][deb]) |
| 31 | row.append("{}: {}".format(node, output[node][deb])) |
| 32 | else: |
| 33 | row.append("{}: No package".format(node)) |
| 34 | if diff.count(diff[0]) < len(nodes): |
| 35 | row.sort() |
| 36 | row.insert(0, deb) |
| 37 | pkts_data.append(row) |
| 38 | assert len(pkts_data) <= 1, \ |
| 39 | "Several problems found for {0} group: {1}".format( |
| 40 | group, json.dumps(pkts_data, indent=4)) |
| 41 | |
| 42 | |
| 43 | @pytest.mark.parametrize( |
| 44 | "group", |
Oleksii Zhurba | e0dedb5 | 2018-01-16 00:55:25 +0000 | [diff] [blame] | 45 | utils.node_groups.keys() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 46 | ) |
| 47 | def test_check_module_versions(local_salt_client, group): |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 48 | pre_check = local_salt_client.cmd( |
Oleksii Zhurba | e0dedb5 | 2018-01-16 00:55:25 +0000 | [diff] [blame] | 49 | "L@"+','.join(utils.node_groups[group]), 'cmd.run', ['dpkg -l | grep "python-pip "'], expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 50 | if pre_check.values().count('') > 0: |
| 51 | pytest.skip("pip is not installed on one or more nodes") |
| 52 | if len(pre_check.keys()) < 2: |
| 53 | pytest.skip("Nothing to compare - only 1 node") |
Oleksii Zhurba | e0dedb5 | 2018-01-16 00:55:25 +0000 | [diff] [blame] | 54 | output = local_salt_client.cmd("L@"+','.join(utils.node_groups[group]), 'pip.freeze', expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 55 | |
| 56 | nodes = [] |
| 57 | pkts_data = [] |
| 58 | my_set = set() |
| 59 | |
| 60 | for node in output: |
| 61 | nodes.append(node) |
| 62 | my_set.update([x.split("=")[0] for x in output[node]]) |
| 63 | output[node] = dict([x.split("==") for x in output[node]]) |
| 64 | |
| 65 | for deb in my_set: |
| 66 | diff = [] |
| 67 | row = [] |
| 68 | for node in nodes: |
| 69 | if deb in output[node].keys(): |
| 70 | diff.append(output[node][deb]) |
| 71 | row.append("{}: {}".format(node, output[node][deb])) |
| 72 | else: |
| 73 | row.append("{}: No module".format(node)) |
| 74 | if diff.count(diff[0]) < len(nodes): |
| 75 | row.sort() |
| 76 | row.insert(0, deb) |
| 77 | pkts_data.append(row) |
| 78 | assert len(pkts_data) <= 1, \ |
| 79 | "Several problems found for {0} group: {1}".format( |
| 80 | group, json.dumps(pkts_data, indent=4)) |