Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 3 | |
| 4 | |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 5 | def test_check_package_versions(local_salt_client, nodes_in_group): |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 6 | output = local_salt_client.cmd("L@"+','.join(nodes_in_group), |
| 7 | 'lowpkg.list_pkgs', |
| 8 | expr_form='compound') |
Oleksii Zhurba | dad1acc | 2018-03-26 14:09:38 -0500 | [diff] [blame] | 9 | # Let's exclude cid01 and dbs01 nodes from this check |
| 10 | exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client", |
| 11 | 'test.ping', |
| 12 | expr_form='compound').keys() |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 13 | total_nodes = [i for i in output.keys() if i not in exclude_nodes] |
| 14 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 15 | pytest.skip("Nothing to compare - only 1 node") |
| 16 | |
| 17 | nodes = [] |
| 18 | pkts_data = [] |
| 19 | my_set = set() |
| 20 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 21 | for node in total_nodes: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 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, \ |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 39 | "Several problems found: {0}".format( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 40 | json.dumps(pkts_data, indent=4)) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 41 | |
| 42 | |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 43 | def test_check_module_versions(local_salt_client, nodes_in_group): |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 44 | pre_check = local_salt_client.cmd( |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 45 | "L@"+','.join(nodes_in_group), |
| 46 | 'cmd.run', |
| 47 | ['dpkg -l | grep "python-pip "'], |
| 48 | expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 49 | if pre_check.values().count('') > 0: |
| 50 | pytest.skip("pip is not installed on one or more nodes") |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 51 | |
| 52 | exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client", |
| 53 | 'test.ping', |
| 54 | expr_form='compound').keys() |
| 55 | total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes] |
| 56 | |
| 57 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 58 | pytest.skip("Nothing to compare - only 1 node") |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 59 | output = local_salt_client.cmd("L@"+','.join(nodes_in_group), |
| 60 | 'pip.freeze', expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 61 | |
| 62 | nodes = [] |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 63 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 64 | pkts_data = [] |
| 65 | my_set = set() |
| 66 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 67 | for node in total_nodes: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 68 | nodes.append(node) |
| 69 | my_set.update([x.split("=")[0] for x in output[node]]) |
| 70 | output[node] = dict([x.split("==") for x in output[node]]) |
| 71 | |
| 72 | for deb in my_set: |
| 73 | diff = [] |
| 74 | row = [] |
| 75 | for node in nodes: |
| 76 | if deb in output[node].keys(): |
| 77 | diff.append(output[node][deb]) |
| 78 | row.append("{}: {}".format(node, output[node][deb])) |
| 79 | else: |
| 80 | row.append("{}: No module".format(node)) |
| 81 | if diff.count(diff[0]) < len(nodes): |
| 82 | row.sort() |
| 83 | row.insert(0, deb) |
| 84 | pkts_data.append(row) |
| 85 | assert len(pkts_data) <= 1, \ |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 86 | "Several problems found: {0}".format( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 87 | json.dumps(pkts_data, indent=4)) |