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