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 | |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 6 | def is_deb_in_exception(inconsistency_rule, package_name, error_node_list): |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 7 | short_names_in_error_nodes = [n.split('.')[0] for n in error_node_list] |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 8 | for node, excluded_packages in inconsistency_rule.items(): |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 9 | if package_name in excluded_packages and node in short_names_in_error_nodes: |
| 10 | return True |
| 11 | return False |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 12 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 13 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 14 | def test_check_package_versions(local_salt_client, nodes_in_group): |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 15 | """Validate package has same versions on all the nodes. |
| 16 | Steps: |
| 17 | 1) Collect packages for nodes_in_group |
| 18 | "salt -C '<group_of_nodes>' cmd.run 'lowpkg.list_pkgs'" |
| 19 | 2) Exclude nodes without packages and exceptions |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 20 | 3) Go through each package and save it with version from each node to the |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 21 | list. Mark 'No version' if package is not found. |
| 22 | If pachage name in the eception list or in inconsistency_rule, ignore it. |
| 23 | 4) Compare items in that list - they should be equal and match the amout of nodes |
| 24 | |
| 25 | """ |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 26 | # defines packages specific to the concrete nodes |
| 27 | inconsistency_rule = {"kvm03": ["rsync", "sysstat", "xz-utils"], "log01": ["python-elasticsearch"], "ctl01": ["python-gnocchiclient", "python-ujson"]} |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 28 | exclude_packages = utils.get_configuration().get("skipped_packages", []) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 29 | group, nodes = nodes_in_group |
| 30 | packages_versions = local_salt_client.cmd(tgt="L@"+','.join(nodes), |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 31 | fun='lowpkg.list_pkgs', |
| 32 | expr_form='compound') |
Oleksii Zhurba | dad1acc | 2018-03-26 14:09:38 -0500 | [diff] [blame] | 33 | # Let's exclude cid01 and dbs01 nodes from this check |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 34 | exclude_nodes = list(local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client", |
| 35 | expr_form='compound').keys()) |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 36 | # PROD-30833 |
| 37 | gtw01 = local_salt_client.pillar_get( |
| 38 | param='_param:openstack_gateway_node01_hostname') or 'gtw01' |
| 39 | cluster_domain = local_salt_client.pillar_get( |
| 40 | param='_param:cluster_domain') or '.local' |
| 41 | gtw01 += '.' + cluster_domain |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 42 | if gtw01 in nodes: |
| 43 | octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes), |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 44 | fun='pillar.get', |
| 45 | param='octavia:manager:enabled', |
| 46 | expr_form='compound') |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 47 | gtws = [gtw for gtw in list(octavia.values()) if gtw] |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 48 | if len(gtws) == 1: |
| 49 | exclude_nodes.append(gtw01) |
| 50 | logging.info("gtw01 node is skipped in test_check_package_versions") |
| 51 | |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 52 | total_nodes = [i for i in nodes if i not in exclude_nodes] |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 53 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 54 | pytest.skip("Nothing to compare - only 1 node") |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 55 | nodes_with_packages = [] |
| 56 | packages_with_different_versions = [] |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 57 | packages_names = set() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 58 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 59 | for node in total_nodes: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 60 | if not packages_versions[node]: |
| 61 | # TODO: do not skip node |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 62 | logging.warning("Node {} is skipped".format(node)) |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 63 | continue |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 64 | nodes_with_packages.append(node) |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 65 | packages_names.update(list(packages_versions[node].keys())) |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 66 | for deb in packages_names: |
| 67 | if deb in exclude_packages: |
| 68 | continue |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 69 | diff = [] |
| 70 | row = [] |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 71 | for node in nodes_with_packages: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 72 | if not packages_versions[node]: |
| 73 | continue |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 74 | if deb in list(packages_versions[node].keys()): |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 75 | diff.append(packages_versions[node][deb]) |
| 76 | row.append("{}: {}".format(node, packages_versions[node][deb])) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 77 | else: |
| 78 | row.append("{}: No package".format(node)) |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 79 | |
| 80 | if diff.count(diff[0]) < len(nodes_with_packages): |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 81 | if not is_deb_in_exception(inconsistency_rule, deb, row): |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 82 | row.sort() |
| 83 | row.insert(0, deb) |
| 84 | packages_with_different_versions.append(row) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 85 | assert len(packages_with_different_versions) == 0, ( |
| 86 | "Non-uniform package versions are installed on '{}' group of nodes:\n" |
| 87 | "{}".format( |
| 88 | group, json.dumps(packages_with_different_versions, indent=4)) |
| 89 | ) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 90 | |
| 91 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 92 | @pytest.mark.full |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 93 | def test_packages_are_latest(local_salt_client, nodes_in_group): |
| 94 | config = utils.get_configuration() |
| 95 | skip = config.get("test_packages")["skip_test"] |
Ievgeniia Zadorozhna | 0c306fd | 2019-11-12 16:03:51 +0300 | [diff] [blame] | 96 | if skip.lower() == 'true': |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 97 | pytest.skip("Test for the latest packages is disabled") |
| 98 | skipped_pkg = config.get("test_packages")["skipped_packages"] |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 99 | group, nodes = nodes_in_group |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 100 | info_salt = local_salt_client.cmd( |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 101 | tgt='L@' + ','.join(nodes), |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 102 | param='apt list --upgradable 2>/dev/null | grep -v Listing', |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 103 | expr_form='compound') |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 104 | for node in nodes: |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 105 | result = [] |
| 106 | if info_salt[node]: |
| 107 | upg_list = info_salt[node].split('\n') |
| 108 | for i in upg_list: |
| 109 | if i.split('/')[0] not in skipped_pkg: |
| 110 | result.append(i) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 111 | assert not result, ( |
| 112 | "Packages are not of latest version on '{}' node:\n{}".format( |
| 113 | node, "\n".join(result)) |
| 114 | ) |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 115 | |
| 116 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 117 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 118 | def test_check_module_versions(local_salt_client, nodes_in_group): |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 119 | # defines modules specific to the concrete nodes |
| 120 | inconsistency_rule = {"ctl01": ["gnocchiclient", "ujson"], "log01": ["elasticsearch"]} |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 121 | exclude_modules = utils.get_configuration().get("skipped_modules", []) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 122 | group, nodes = nodes_in_group |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 123 | pre_check = local_salt_client.cmd( |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 124 | tgt="L@"+','.join(nodes), |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 125 | param='dpkg -l | grep "python-pip "', |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 126 | expr_form='compound') |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 127 | if list(pre_check.values()).count('') > 0: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 128 | pytest.skip("pip is not installed on one or more nodes") |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 129 | |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 130 | exclude_nodes = list(local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client", |
| 131 | expr_form='compound').keys()) |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 132 | |
| 133 | # PROD-30833 |
| 134 | gtw01 = local_salt_client.pillar_get( |
| 135 | param='_param:openstack_gateway_node01_hostname') or 'gtw01' |
| 136 | cluster_domain = local_salt_client.pillar_get( |
| 137 | param='_param:cluster_domain') or '.local' |
| 138 | gtw01 += '.' + cluster_domain |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 139 | if gtw01 in nodes: |
| 140 | octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes), |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 141 | fun='pillar.get', |
| 142 | param='octavia:manager:enabled', |
| 143 | expr_form='compound') |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 144 | gtws = [gtw for gtw in list(octavia.values()) if gtw] |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 145 | if len(gtws) == 1: |
| 146 | exclude_nodes.append(gtw01) |
| 147 | logging.info("gtw01 node is skipped in test_check_module_versions") |
| 148 | |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 149 | total_nodes = [i for i in list(pre_check.keys()) if i not in exclude_nodes] |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 150 | |
| 151 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 152 | pytest.skip("Nothing to compare - only 1 node") |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 153 | list_of_pip_packages = local_salt_client.cmd( |
| 154 | tgt="L@"+','.join(nodes), |
| 155 | fun='pip.freeze', expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 156 | |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 157 | nodes_with_packages = [] |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 158 | |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 159 | modules_with_different_versions = [] |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 160 | packages_names = set() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 161 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 162 | for node in total_nodes: |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 163 | nodes_with_packages.append(node) |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 164 | packages_names.update([x.split("=")[0] for x in list_of_pip_packages[node]]) |
| 165 | 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] | 166 | |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 167 | for deb in packages_names: |
| 168 | if deb in exclude_modules: |
| 169 | continue |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 170 | diff = [] |
| 171 | row = [] |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 172 | for node in nodes_with_packages: |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 173 | if deb in list(list_of_pip_packages[node].keys()): |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 174 | diff.append(list_of_pip_packages[node][deb]) |
| 175 | row.append("{}: {}".format(node, list_of_pip_packages[node][deb])) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 176 | else: |
| 177 | row.append("{}: No module".format(node)) |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 178 | if diff.count(diff[0]) < len(nodes_with_packages): |
| 179 | if not is_deb_in_exception(inconsistency_rule, deb, row): |
| 180 | row.sort() |
| 181 | row.insert(0, deb) |
| 182 | modules_with_different_versions.append(row) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 183 | assert len(modules_with_different_versions) == 0, ( |
| 184 | "Non-uniform pip modules are installed on '{}' group of nodes:\n" |
| 185 | "{}".format( |
| 186 | group, json.dumps(modules_with_different_versions, indent=4)) |
| 187 | ) |
Hanna Arhipova | 5a56ae6 | 2021-02-11 16:27:52 +0200 | [diff] [blame] | 188 | |
| 189 | |
| 190 | @pytest.mark.full |
| 191 | def test_restricted_updates_repo(local_salt_client): |
| 192 | restricted_repo_enabled = local_salt_client.pillar_get( |
| 193 | tgt="I@salt:master", |
Hanna Arhipova | 1d87dbe | 2021-02-16 19:26:27 +0200 | [diff] [blame^] | 194 | param='_param:updates_mirantis_login', |
Hanna Arhipova | 5a56ae6 | 2021-02-11 16:27:52 +0200 | [diff] [blame] | 195 | expr_form='compound') |
| 196 | if not restricted_repo_enabled: |
| 197 | pytest.skip("This env doesn't required the restricted ubuntu repo") |
| 198 | |
| 199 | repos_by_nodes=local_salt_client.cmd( |
| 200 | tgt="*", |
| 201 | param="apt-cache policy |grep updates.mirantis.com" |
| 202 | ) |
| 203 | |
Hanna Arhipova | 1d87dbe | 2021-02-16 19:26:27 +0200 | [diff] [blame^] | 204 | assert all(list(repos_by_nodes.values())), \ |
Hanna Arhipova | 5a56ae6 | 2021-02-11 16:27:52 +0200 | [diff] [blame] | 205 | "Next nodes don't have updates.mirantis.com in sources.list: {}".\ |
| 206 | format({node for node, repo |
| 207 | in repos_by_nodes.items() |
| 208 | if not repo}) |