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() |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 16 | |
| 17 | # PROD-30833 |
| 18 | gtw01 = local_salt_client.pillar_get( |
| 19 | param='_param:openstack_gateway_node01_hostname') or 'gtw01' |
| 20 | cluster_domain = local_salt_client.pillar_get( |
| 21 | param='_param:cluster_domain') or '.local' |
| 22 | gtw01 += '.' + cluster_domain |
| 23 | if gtw01 in nodes_in_group: |
| 24 | octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes_in_group), |
| 25 | fun='pillar.get', |
| 26 | param='octavia:manager:enabled', |
| 27 | expr_form='compound') |
| 28 | gtws = [gtw for gtw in octavia.values() if gtw] |
| 29 | if len(gtws) == 1: |
| 30 | exclude_nodes.append(gtw01) |
| 31 | logging.info("gtw01 node is skipped in test_check_package_versions") |
| 32 | |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 33 | 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] | 34 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 35 | pytest.skip("Nothing to compare - only 1 node") |
| 36 | |
| 37 | nodes = [] |
| 38 | pkts_data = [] |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 39 | packages_names = set() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 40 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 41 | for node in total_nodes: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 42 | if not packages_versions[node]: |
| 43 | # TODO: do not skip node |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 44 | logging.warning("Node {} is skipped".format(node)) |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 45 | continue |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 46 | nodes.append(node) |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 47 | packages_names.update(packages_versions[node].keys()) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 48 | |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 49 | for deb in packages_names: |
| 50 | if deb in exclude_packages: |
| 51 | continue |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 52 | diff = [] |
| 53 | row = [] |
| 54 | for node in nodes: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 55 | if not packages_versions[node]: |
| 56 | continue |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 57 | if deb in packages_versions[node].keys(): |
| 58 | diff.append(packages_versions[node][deb]) |
| 59 | row.append("{}: {}".format(node, packages_versions[node][deb])) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 60 | else: |
| 61 | row.append("{}: No package".format(node)) |
| 62 | if diff.count(diff[0]) < len(nodes): |
| 63 | row.sort() |
| 64 | row.insert(0, deb) |
| 65 | pkts_data.append(row) |
| 66 | assert len(pkts_data) <= 1, \ |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 67 | "Several problems found: {0}".format( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 68 | json.dumps(pkts_data, indent=4)) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 69 | |
| 70 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 71 | @pytest.mark.full |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 72 | def test_packages_are_latest(local_salt_client, nodes_in_group): |
| 73 | config = utils.get_configuration() |
| 74 | skip = config.get("test_packages")["skip_test"] |
| 75 | if skip: |
| 76 | pytest.skip("Test for the latest packages is disabled") |
| 77 | skipped_pkg = config.get("test_packages")["skipped_packages"] |
| 78 | info_salt = 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='apt list --upgradable 2>/dev/null | grep -v Listing', |
Ievgeniia Zadorozhna | 6baf787 | 2019-01-25 19:09:30 +0300 | [diff] [blame] | 81 | expr_form='compound') |
| 82 | for node in nodes_in_group: |
| 83 | result = [] |
| 84 | if info_salt[node]: |
| 85 | upg_list = info_salt[node].split('\n') |
| 86 | for i in upg_list: |
| 87 | if i.split('/')[0] not in skipped_pkg: |
| 88 | result.append(i) |
| 89 | assert not result, "Please check not latest packages at {}:\n{}".format( |
| 90 | node, "\n".join(result)) |
| 91 | |
| 92 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 93 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 94 | def test_check_module_versions(local_salt_client, nodes_in_group): |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 95 | exclude_modules = utils.get_configuration().get("skipped_modules", []) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 96 | pre_check = 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='dpkg -l | grep "python-pip "', |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 99 | expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 100 | if pre_check.values().count('') > 0: |
| 101 | pytest.skip("pip is not installed on one or more nodes") |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 102 | |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 103 | exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client", |
| 104 | expr_form='compound').keys() |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 105 | |
| 106 | # PROD-30833 |
| 107 | gtw01 = local_salt_client.pillar_get( |
| 108 | param='_param:openstack_gateway_node01_hostname') or 'gtw01' |
| 109 | cluster_domain = local_salt_client.pillar_get( |
| 110 | param='_param:cluster_domain') or '.local' |
| 111 | gtw01 += '.' + cluster_domain |
| 112 | if gtw01 in nodes_in_group: |
| 113 | octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes_in_group), |
| 114 | fun='pillar.get', |
| 115 | param='octavia:manager:enabled', |
| 116 | expr_form='compound') |
| 117 | gtws = [gtw for gtw in octavia.values() if gtw] |
| 118 | if len(gtws) == 1: |
| 119 | exclude_nodes.append(gtw01) |
| 120 | logging.info("gtw01 node is skipped in test_check_module_versions") |
| 121 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 122 | total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes] |
| 123 | |
| 124 | if len(total_nodes) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 125 | pytest.skip("Nothing to compare - only 1 node") |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 126 | 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] | 127 | fun='pip.freeze', expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 128 | |
| 129 | nodes = [] |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 130 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 131 | pkts_data = [] |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 132 | packages_names = set() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 133 | |
Oleksii Zhurba | 5f768c5 | 2018-08-07 17:27:57 -0500 | [diff] [blame] | 134 | for node in total_nodes: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 135 | nodes.append(node) |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 136 | packages_names.update([x.split("=")[0] for x in list_of_pip_packages[node]]) |
| 137 | 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] | 138 | |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 139 | for deb in packages_names: |
| 140 | if deb in exclude_modules: |
| 141 | continue |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 142 | diff = [] |
| 143 | row = [] |
| 144 | for node in nodes: |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 145 | if deb in list_of_pip_packages[node].keys(): |
| 146 | diff.append(list_of_pip_packages[node][deb]) |
| 147 | row.append("{}: {}".format(node, list_of_pip_packages[node][deb])) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 148 | else: |
| 149 | row.append("{}: No module".format(node)) |
| 150 | if diff.count(diff[0]) < len(nodes): |
| 151 | row.sort() |
| 152 | row.insert(0, deb) |
| 153 | pkts_data.append(row) |
| 154 | assert len(pkts_data) <= 1, \ |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 155 | "Several problems found: {0}".format( |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame] | 156 | json.dumps(pkts_data, indent=4)) |
| 157 | |