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