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