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 |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 5 | import itertools |
| 6 | from functools import lru_cache |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 7 | |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 8 | |
| 9 | @lru_cache(maxsize=32) |
| 10 | def targeted_minions(target): |
| 11 | """ |
| 12 | Returns nodes associated with salt target |
| 13 | :param target: str, salt target in COMPOUND notation like I@nova:server |
| 14 | More here https://docs.saltproject.io/en/latest/topics/targeting/compound.html |
| 15 | :return: list of nodes or [] |
| 16 | """ |
| 17 | salt_client = pytest.local_salt_client |
| 18 | return list(salt_client.test_ping( |
| 19 | tgt=target, |
| 20 | expr_form='compound')) |
| 21 | |
| 22 | |
| 23 | def is_deb_in_exception(inconsistency_rule, package_name, node_hostname): |
| 24 | for salt_target, excluded_packages in inconsistency_rule.items(): |
| 25 | if package_name in excluded_packages \ |
| 26 | and node_hostname in targeted_minions(salt_target): |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 27 | return True |
| 28 | return False |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 29 | |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 30 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 31 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 32 | def test_check_package_versions(local_salt_client, nodes_in_group): |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 33 | """Validate package has same versions on all the nodes. |
| 34 | Steps: |
| 35 | 1) Collect packages for nodes_in_group |
| 36 | "salt -C '<group_of_nodes>' cmd.run 'lowpkg.list_pkgs'" |
| 37 | 2) Exclude nodes without packages and exceptions |
Ekaterina Chernova | 7ea9715 | 2019-07-29 17:09:12 +0300 | [diff] [blame] | 38 | 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] | 39 | list. Mark 'No version' if package is not found. |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 40 | If package name in the exception list or in inconsistency_rule, |
| 41 | ignore it. |
Hanna Arhipova | 035dea4 | 2021-08-19 12:24:08 +0300 | [diff] [blame] | 42 | 4) Compare items in that list - they should be equal and match the |
| 43 | amount of nodes |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 44 | |
| 45 | """ |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 46 | salt = local_salt_client |
| 47 | # defines packages specific to the nodes |
| 48 | inconsistency_rule = { |
| 49 | "I@backupninja:server": [ |
| 50 | "rsync", "sysstat", "xz-utils"], |
| 51 | "I@elasticsearch:server": [ |
| 52 | "python-elasticsearch"], |
Taras Khlivnyak | 1f9375f | 2022-02-23 10:57:11 +0200 | [diff] [blame^] | 53 | # PROD-30833, PROD-36718 |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 54 | "I@octavia:manager:controller_worker:loadbalancer_topology:SINGLE": [ |
| 55 | "netfilter-persistent", |
| 56 | "gunicorn", |
| 57 | "octavia-worker", |
| 58 | "octavia-health-manager", |
Hanna Arhipova | ae2e05b | 2021-08-18 10:47:39 +0300 | [diff] [blame] | 59 | "octavia-housekeeping", |
Hanna Arhipova | fb3bc58 | 2021-09-22 14:30:52 +0300 | [diff] [blame] | 60 | "python-castellan", |
Hanna Arhipova | ae2e05b | 2021-08-18 10:47:39 +0300 | [diff] [blame] | 61 | 'python-automaton', |
| 62 | 'python-setproctitle', |
| 63 | 'python-glanceclient', |
| 64 | 'libnss3-nssdb', |
| 65 | 'python-json-pointer', |
| 66 | 'debootstrap', |
| 67 | 'python-cotyledon', |
| 68 | 'librbd1', |
| 69 | 'qemu-block-extra:amd64', |
| 70 | 'python-diskimage-builder', |
| 71 | 'liburcu4:amd64', |
| 72 | 'python-networkx', |
| 73 | 'librados2', |
| 74 | 'kpartx', |
| 75 | 'python-taskflow', |
| 76 | 'libnss3:amd64', |
| 77 | 'libibverbs1', |
| 78 | 'python-itsdangerous', |
| 79 | 'liblttng-ust0:amd64', |
| 80 | 'python-wsme', |
| 81 | 'python-werkzeug', |
| 82 | 'liblttng-ust-ctl2:amd64', |
| 83 | 'python-gunicorn', |
| 84 | 'python-octavia', |
| 85 | 'python-warlock', |
| 86 | 'python-barbicanclient', |
| 87 | 'iptables-persistent', |
| 88 | 'python-psycopg2', |
| 89 | 'octavia-common', |
| 90 | 'python-flask', |
| 91 | 'libpq5:amd64', |
| 92 | 'python-dib-utils', |
| 93 | 'python-jsonpatch', |
| 94 | 'libnspr4:amd64', |
| 95 | 'qemu-utils', |
| 96 | 'python-pyasn1-modules', |
| 97 | 'libonig2:amd64', |
| 98 | 'jq', |
| 99 | 'libaio1:amd64', |
| 100 | 'python-kazoo', |
| 101 | 'python-ipaddr', |
Taras Khlivnyak | 1f9375f | 2022-02-23 10:57:11 +0200 | [diff] [blame^] | 102 | 'libiscsi2:amd64', |
| 103 | 'python-pyasn1', |
| 104 | 'python3-pyasn1' |
| 105 | ] |
Hanna Arhipova | 035dea4 | 2021-08-19 12:24:08 +0300 | [diff] [blame] | 106 | } |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 107 | exclude_packages = utils.get_configuration().get("skipped_packages", []) |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 108 | |
| 109 | group_name, nodes = nodes_in_group |
| 110 | packages_versions_by_nodes = salt.cmd(tgt="L@"+','.join(nodes), |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 111 | fun='lowpkg.list_pkgs', |
| 112 | expr_form='compound') |
Oleksii Zhurba | dad1acc | 2018-03-26 14:09:38 -0500 | [diff] [blame] | 113 | # Let's exclude cid01 and dbs01 nodes from this check |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 114 | exclude_nodes = targeted_minions("I@galera:master or I@gerrit:client") |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 115 | |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 116 | total_nodes = [i |
| 117 | for i in nodes |
| 118 | if i not in exclude_nodes] |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 119 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 120 | pytest.skip("Nothing to compare - only 1 node") |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 121 | |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 122 | packages_with_different_versions = dict() |
| 123 | packages_names = set(itertools.chain.from_iterable( |
| 124 | [packages_versions_by_nodes[node].keys() |
| 125 | for node in total_nodes]) |
| 126 | ) |
| 127 | |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 128 | for deb in packages_names: |
| 129 | if deb in exclude_packages: |
| 130 | continue |
Ekaterina Chernova | b480675 | 2019-07-26 16:02:18 +0300 | [diff] [blame] | 131 | |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 132 | node_and_version = [ |
| 133 | (node, packages_versions_by_nodes[node].get(deb, "No package")) |
| 134 | for node in total_nodes |
| 135 | if not is_deb_in_exception(inconsistency_rule, deb, node) |
| 136 | ] |
| 137 | |
| 138 | if set([version for node, version in node_and_version]).__len__() > 1: |
| 139 | packages_with_different_versions[deb] = [ |
Hanna Arhipova | 035dea4 | 2021-08-19 12:24:08 +0300 | [diff] [blame] | 140 | "{}: {}".format(node, version) |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 141 | for node, version in node_and_version] |
| 142 | |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 143 | assert len(packages_with_different_versions) == 0, ( |
| 144 | "Non-uniform package versions are installed on '{}' group of nodes:\n" |
| 145 | "{}".format( |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 146 | group_name, json.dumps(packages_with_different_versions, indent=4)) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 147 | ) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 148 | |
| 149 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 150 | @pytest.mark.full |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 151 | def test_packages_are_latest(local_salt_client, nodes_in_group): |
| 152 | config = utils.get_configuration() |
| 153 | skip = config.get("test_packages")["skip_test"] |
Ievgeniia Zadorozhna | 0c306fd | 2019-11-12 16:03:51 +0300 | [diff] [blame] | 154 | if skip.lower() == 'true': |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 155 | pytest.skip("Test for the latest packages is disabled") |
| 156 | skipped_pkg = config.get("test_packages")["skipped_packages"] |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 157 | group, nodes = nodes_in_group |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 158 | info_salt = local_salt_client.cmd( |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 159 | tgt='L@' + ','.join(nodes), |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 160 | param='apt list --upgradable 2>/dev/null | grep -v Listing', |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 161 | expr_form='compound') |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 162 | for node in nodes: |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 163 | result = [] |
| 164 | if info_salt[node]: |
| 165 | upg_list = info_salt[node].split('\n') |
| 166 | for i in upg_list: |
| 167 | if i.split('/')[0] not in skipped_pkg: |
| 168 | result.append(i) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 169 | assert not result, ( |
| 170 | "Packages are not of latest version on '{}' node:\n{}".format( |
| 171 | node, "\n".join(result)) |
| 172 | ) |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 173 | |
| 174 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 175 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 176 | def test_check_module_versions(local_salt_client, nodes_in_group): |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 177 | # defines modules specific to the nodes |
| 178 | inconsistency_rule = { |
| 179 | "I@elasticsearch:server": ["elasticsearch"], |
Taras Khlivnyak | 1f9375f | 2022-02-23 10:57:11 +0200 | [diff] [blame^] | 180 | # PROD-30833 |
Hanna Arhipova | ae2e05b | 2021-08-18 10:47:39 +0300 | [diff] [blame] | 181 | "I@octavia:manager:controller_worker:loadbalancer_topology:SINGLE": [ |
| 182 | 'octavia', |
| 183 | 'setproctitle', |
| 184 | 'automaton', |
| 185 | 'warlock', |
| 186 | 'python-glanceclient', |
| 187 | 'taskflow', |
| 188 | 'diskimage-builder', |
| 189 | 'pyasn1-modules', |
| 190 | 'python-barbicanclient', |
| 191 | 'WSME', |
| 192 | 'jsonpatch', |
| 193 | 'cotyledon', |
| 194 | 'dib-utils', |
| 195 | 'itsdangerous', |
| 196 | 'kazoo', |
| 197 | 'psycopg2', |
| 198 | 'Flask', |
| 199 | 'networkx', |
| 200 | 'Werkzeug', |
| 201 | 'jsonpointer', |
| 202 | 'gunicorn', |
Hanna Arhipova | fb3bc58 | 2021-09-22 14:30:52 +0300 | [diff] [blame] | 203 | 'ipaddr', |
Taras Khlivnyak | 1f9375f | 2022-02-23 10:57:11 +0200 | [diff] [blame^] | 204 | 'castellan' |
Hanna Arhipova | fb3bc58 | 2021-09-22 14:30:52 +0300 | [diff] [blame] | 205 | ] |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 206 | } |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 207 | exclude_modules = utils.get_configuration().get("skipped_modules", []) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 208 | group, nodes = nodes_in_group |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 209 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 210 | pre_check = local_salt_client.cmd( |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 211 | tgt="L@{nodes}".format(nodes=','.join(nodes)), |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 212 | param='dpkg -l | grep "python-pip "', |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 213 | expr_form='compound') |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 214 | exclude_nodes = targeted_minions("I@galera:master or I@gerrit:client") |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 215 | if list(pre_check.values()).count('') > 0: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 216 | pytest.skip("pip is not installed on one or more nodes") |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 217 | |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 218 | total_nodes = [node |
| 219 | for node in nodes |
| 220 | if node not in exclude_nodes] |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 221 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 222 | pytest.skip("Nothing to compare - only 1 node") |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 223 | list_of_pip_packages = local_salt_client.cmd( |
| 224 | tgt="L@"+','.join(nodes), |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 225 | fun='pip.list', expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 226 | |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 227 | modules_with_different_versions = dict() |
| 228 | packages_names = set(itertools.chain.from_iterable( |
| 229 | list_of_pip_packages.values() |
| 230 | )) |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 231 | |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 232 | for package in packages_names: |
| 233 | if package in exclude_modules: |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 234 | continue |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 235 | node_and_version = [ |
| 236 | (node, list_of_pip_packages[node].get(package, "No module")) |
| 237 | for node in total_nodes |
| 238 | if not is_deb_in_exception(inconsistency_rule, package, node) |
| 239 | ] |
| 240 | |
| 241 | if set([version for node, version in node_and_version]).__len__() > 1: |
| 242 | modules_with_different_versions[package] = [ |
Hanna Arhipova | 035dea4 | 2021-08-19 12:24:08 +0300 | [diff] [blame] | 243 | "{}: {}".format(node, version) |
Hanna Arhipova | e7ebae6 | 2021-08-17 20:29:38 +0300 | [diff] [blame] | 244 | for node, version in node_and_version |
| 245 | ] |
| 246 | |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 247 | assert len(modules_with_different_versions) == 0, ( |
| 248 | "Non-uniform pip modules are installed on '{}' group of nodes:\n" |
| 249 | "{}".format( |
| 250 | group, json.dumps(modules_with_different_versions, indent=4)) |
| 251 | ) |
Hanna Arhipova | 5a56ae6 | 2021-02-11 16:27:52 +0200 | [diff] [blame] | 252 | |
| 253 | |
| 254 | @pytest.mark.full |
| 255 | def test_restricted_updates_repo(local_salt_client): |
| 256 | restricted_repo_enabled = local_salt_client.pillar_get( |
| 257 | tgt="I@salt:master", |
Hanna Arhipova | 1d87dbe | 2021-02-16 19:26:27 +0200 | [diff] [blame] | 258 | param='_param:updates_mirantis_login', |
Hanna Arhipova | 5a56ae6 | 2021-02-11 16:27:52 +0200 | [diff] [blame] | 259 | expr_form='compound') |
| 260 | if not restricted_repo_enabled: |
Hanna Arhipova | 2d53841 | 2021-08-17 10:44:41 +0300 | [diff] [blame] | 261 | pytest.skip("This env doesn't require the restricted ubuntu repo") |
Hanna Arhipova | 5a56ae6 | 2021-02-11 16:27:52 +0200 | [diff] [blame] | 262 | |
| 263 | repos_by_nodes=local_salt_client.cmd( |
| 264 | tgt="*", |
| 265 | param="apt-cache policy |grep updates.mirantis.com" |
Hanna Arhipova | 035dea4 | 2021-08-19 12:24:08 +0300 | [diff] [blame] | 266 | ) |
Hanna Arhipova | 5a56ae6 | 2021-02-11 16:27:52 +0200 | [diff] [blame] | 267 | |
Hanna Arhipova | 1d87dbe | 2021-02-16 19:26:27 +0200 | [diff] [blame] | 268 | assert all(list(repos_by_nodes.values())), \ |
Hanna Arhipova | 5a56ae6 | 2021-02-11 16:27:52 +0200 | [diff] [blame] | 269 | "Next nodes don't have updates.mirantis.com in sources.list: {}".\ |
| 270 | format({node for node, repo |
| 271 | in repos_by_nodes.items() |
Hanna Arhipova | 035dea4 | 2021-08-19 12:24:08 +0300 | [diff] [blame] | 272 | if not repo}) |