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