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