blob: c132294eaaa0dd5bdaab7b9aae8af7a0a187d788 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +03003import utils
Hanna Arhipova56eab942019-05-06 20:14:18 +03004import logging
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +03005
Ekaterina Chernova7ea97152019-07-29 17:09:12 +03006def is_deb_in_exception(inconsistency_rule, package_name, error_node_list):
Ekaterina Chernovab4806752019-07-26 16:02:18 +03007 short_names_in_error_nodes = [n.split('.')[0] for n in error_node_list]
8 for node, excluded_packages in inconsistency_rule.iteritems():
9 if package_name in excluded_packages and node in short_names_in_error_nodes:
10 return True
11 return False
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000012
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050013@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050014def test_check_package_versions(local_salt_client, nodes_in_group):
Ekaterina Chernovab4806752019-07-26 16:02:18 +030015 """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 Chernova7ea97152019-07-29 17:09:12 +030020 3) Go through each package and save it with version from each node to the
Ekaterina Chernovab4806752019-07-26 16:02:18 +030021 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 Chernova7ea97152019-07-29 17:09:12 +030026 # defines packages specific to the concrete nodes
27 inconsistency_rule = {"kvm03": ["rsync", "sysstat", "xz-utils"], "log01": ["python-elasticsearch"], "ctl01": ["python-gnocchiclient", "python-ujson"]}
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020028 exclude_packages = utils.get_configuration().get("skipped_packages", [])
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020029 group, nodes = nodes_in_group
30 packages_versions = local_salt_client.cmd(tgt="L@"+','.join(nodes),
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050031 fun='lowpkg.list_pkgs',
32 expr_form='compound')
Oleksii Zhurbadad1acc2018-03-26 14:09:38 -050033 # Let's exclude cid01 and dbs01 nodes from this check
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050034 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
35 expr_form='compound').keys()
Oleksii Zhurba599801a2019-06-04 17:26:51 -050036 # 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 Kruglova34a3042019-08-20 11:45:35 +020042 if gtw01 in nodes:
43 octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes),
Oleksii Zhurba599801a2019-06-04 17:26:51 -050044 fun='pillar.get',
45 param='octavia:manager:enabled',
46 expr_form='compound')
47 gtws = [gtw for gtw in octavia.values() if gtw]
48 if len(gtws) == 1:
49 exclude_nodes.append(gtw01)
50 logging.info("gtw01 node is skipped in test_check_package_versions")
51
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020052 total_nodes = [i for i in nodes if i not in exclude_nodes]
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050053 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000054 pytest.skip("Nothing to compare - only 1 node")
Ekaterina Chernovab4806752019-07-26 16:02:18 +030055 nodes_with_packages = []
56 packages_with_different_versions = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020057 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000058
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050059 for node in total_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050060 if not packages_versions[node]:
61 # TODO: do not skip node
Hanna Arhipova56eab942019-05-06 20:14:18 +030062 logging.warning("Node {} is skipped".format(node))
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050063 continue
Ekaterina Chernovab4806752019-07-26 16:02:18 +030064 nodes_with_packages.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020065 packages_names.update(packages_versions[node].keys())
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020066 for deb in packages_names:
67 if deb in exclude_packages:
68 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000069 diff = []
70 row = []
Ekaterina Chernovab4806752019-07-26 16:02:18 +030071 for node in nodes_with_packages:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050072 if not packages_versions[node]:
73 continue
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020074 if deb in packages_versions[node].keys():
75 diff.append(packages_versions[node][deb])
76 row.append("{}: {}".format(node, packages_versions[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000077 else:
78 row.append("{}: No package".format(node))
Ekaterina Chernovab4806752019-07-26 16:02:18 +030079
80 if diff.count(diff[0]) < len(nodes_with_packages):
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020081 if not is_deb_in_exception(inconsistency_rule, deb, row):
Ekaterina Chernovab4806752019-07-26 16:02:18 +030082 row.sort()
83 row.insert(0, deb)
84 packages_with_different_versions.append(row)
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020085 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 Zhurbaa10927b2017-09-27 22:09:23 +000090
91
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050092@pytest.mark.full
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030093def test_packages_are_latest(local_salt_client, nodes_in_group):
94 config = utils.get_configuration()
95 skip = config.get("test_packages")["skip_test"]
96 if skip:
97 pytest.skip("Test for the latest packages is disabled")
98 skipped_pkg = config.get("test_packages")["skipped_packages"]
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020099 group, nodes = nodes_in_group
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +0300100 info_salt = local_salt_client.cmd(
Dmitriy Kruglova34a3042019-08-20 11:45:35 +0200101 tgt='L@' + ','.join(nodes),
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -0500102 param='apt list --upgradable 2>/dev/null | grep -v Listing',
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +0300103 expr_form='compound')
Dmitriy Kruglova34a3042019-08-20 11:45:35 +0200104 for node in nodes:
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +0300105 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 Kruglova34a3042019-08-20 11:45:35 +0200111 assert not result, (
112 "Packages are not of latest version on '{}' node:\n{}".format(
113 node, "\n".join(result))
114 )
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +0300115
116
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -0500117@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -0500118def test_check_module_versions(local_salt_client, nodes_in_group):
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300119 # defines modules specific to the concrete nodes
120 inconsistency_rule = {"ctl01": ["gnocchiclient", "ujson"], "log01": ["elasticsearch"]}
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200121 exclude_modules = utils.get_configuration().get("skipped_modules", [])
Dmitriy Kruglova34a3042019-08-20 11:45:35 +0200122 group, nodes = nodes_in_group
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000123 pre_check = local_salt_client.cmd(
Dmitriy Kruglova34a3042019-08-20 11:45:35 +0200124 tgt="L@"+','.join(nodes),
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -0500125 param='dpkg -l | grep "python-pip "',
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500126 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000127 if pre_check.values().count('') > 0:
128 pytest.skip("pip is not installed on one or more nodes")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500129
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -0500130 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
131 expr_form='compound').keys()
Oleksii Zhurba599801a2019-06-04 17:26:51 -0500132
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 Kruglova34a3042019-08-20 11:45:35 +0200139 if gtw01 in nodes:
140 octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes),
Oleksii Zhurba599801a2019-06-04 17:26:51 -0500141 fun='pillar.get',
142 param='octavia:manager:enabled',
143 expr_form='compound')
144 gtws = [gtw for gtw in octavia.values() if gtw]
145 if len(gtws) == 1:
146 exclude_nodes.append(gtw01)
147 logging.info("gtw01 node is skipped in test_check_module_versions")
148
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500149 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
150
151 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000152 pytest.skip("Nothing to compare - only 1 node")
Dmitriy Kruglova34a3042019-08-20 11:45:35 +0200153 list_of_pip_packages = local_salt_client.cmd(
154 tgt="L@"+','.join(nodes),
155 fun='pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000156
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300157 nodes_with_packages = []
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -0500158
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300159 modules_with_different_versions = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200160 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000161
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500162 for node in total_nodes:
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300163 nodes_with_packages.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200164 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 Zhurbaa10927b2017-09-27 22:09:23 +0000166
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200167 for deb in packages_names:
168 if deb in exclude_modules:
169 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000170 diff = []
171 row = []
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300172 for node in nodes_with_packages:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200173 if deb in list_of_pip_packages[node].keys():
174 diff.append(list_of_pip_packages[node][deb])
175 row.append("{}: {}".format(node, list_of_pip_packages[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000176 else:
177 row.append("{}: No module".format(node))
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300178 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 Kruglova34a3042019-08-20 11:45:35 +0200183 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 )