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 | |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 4 | import utils |
| 5 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 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): |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 8 | output = local_salt_client.cmd("L@"+','.join(nodes_in_group), |
| 9 | 'lowpkg.list_pkgs', |
| 10 | expr_form='compound') |
Oleksii Zhurba | dad1acc | 2018-03-26 14:09:38 -0500 | [diff] [blame] | 11 | # Let's exclude cid01 and dbs01 nodes from this check |
| 12 | exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client", |
| 13 | 'test.ping', |
| 14 | expr_form='compound').keys() |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 15 | total_nodes = [i for i in output.keys() if i not in exclude_nodes] |
| 16 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 17 | pytest.skip("Nothing to compare - only 1 node") |
| 18 | |
| 19 | nodes = [] |
| 20 | pkts_data = [] |
| 21 | my_set = set() |
| 22 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 23 | for node in total_nodes: |
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 | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 41 | "Several problems found: {0}".format( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 42 | json.dumps(pkts_data, indent=4)) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 43 | |
| 44 | |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 45 | def test_packages_are_latest(local_salt_client, nodes_in_group): |
| 46 | config = utils.get_configuration() |
| 47 | skip = config.get("test_packages")["skip_test"] |
| 48 | if skip: |
| 49 | pytest.skip("Test for the latest packages is disabled") |
| 50 | skipped_pkg = config.get("test_packages")["skipped_packages"] |
| 51 | info_salt = local_salt_client.cmd( |
| 52 | 'L@' + ','.join(nodes_in_group), |
| 53 | 'cmd.run', ['apt list --upgradable 2>/dev/null | grep -v Listing'], |
| 54 | expr_form='compound') |
| 55 | for node in nodes_in_group: |
| 56 | result = [] |
| 57 | if info_salt[node]: |
| 58 | upg_list = info_salt[node].split('\n') |
| 59 | for i in upg_list: |
| 60 | if i.split('/')[0] not in skipped_pkg: |
| 61 | result.append(i) |
| 62 | assert not result, "Please check not latest packages at {}:\n{}".format( |
| 63 | node, "\n".join(result)) |
| 64 | |
| 65 | |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 66 | def test_check_module_versions(local_salt_client, nodes_in_group): |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 67 | pre_check = local_salt_client.cmd( |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 68 | "L@"+','.join(nodes_in_group), |
| 69 | 'cmd.run', |
| 70 | ['dpkg -l | grep "python-pip "'], |
| 71 | expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 72 | if pre_check.values().count('') > 0: |
| 73 | pytest.skip("pip is not installed on one or more nodes") |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 74 | |
| 75 | exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client", |
| 76 | 'test.ping', |
| 77 | expr_form='compound').keys() |
| 78 | total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes] |
| 79 | |
| 80 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 81 | pytest.skip("Nothing to compare - only 1 node") |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 82 | output = local_salt_client.cmd("L@"+','.join(nodes_in_group), |
| 83 | 'pip.freeze', expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 84 | |
| 85 | nodes = [] |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 86 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 87 | pkts_data = [] |
| 88 | my_set = set() |
| 89 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 90 | for node in total_nodes: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 91 | nodes.append(node) |
| 92 | my_set.update([x.split("=")[0] for x in output[node]]) |
| 93 | output[node] = dict([x.split("==") for x in output[node]]) |
| 94 | |
| 95 | for deb in my_set: |
| 96 | diff = [] |
| 97 | row = [] |
| 98 | for node in nodes: |
| 99 | if deb in output[node].keys(): |
| 100 | diff.append(output[node][deb]) |
| 101 | row.append("{}: {}".format(node, output[node][deb])) |
| 102 | else: |
| 103 | row.append("{}: No module".format(node)) |
| 104 | if diff.count(diff[0]) < len(nodes): |
| 105 | row.sort() |
| 106 | row.insert(0, deb) |
| 107 | pkts_data.append(row) |
| 108 | assert len(pkts_data) <= 1, \ |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 109 | "Several problems found: {0}".format( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 110 | json.dumps(pkts_data, indent=4)) |