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