blob: b7c206412663a3633f490fa58e211b0e19e6e8ec [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", [])
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050029 packages_versions = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
30 fun='lowpkg.list_pkgs',
31 expr_form='compound')
Oleksii Zhurbadad1acc2018-03-26 14:09:38 -050032 # Let's exclude cid01 and dbs01 nodes from this check
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050033 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
34 expr_form='compound').keys()
Oleksii Zhurba599801a2019-06-04 17:26:51 -050035 # 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 Chernovab4806752019-07-26 16:02:18 +030051 total_nodes = [i for i in nodes_in_group if i not in exclude_nodes]
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050052 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000053 pytest.skip("Nothing to compare - only 1 node")
Ekaterina Chernovab4806752019-07-26 16:02:18 +030054 nodes_with_packages = []
55 packages_with_different_versions = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020056 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000057
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050058 for node in total_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050059 if not packages_versions[node]:
60 # TODO: do not skip node
Hanna Arhipova56eab942019-05-06 20:14:18 +030061 logging.warning("Node {} is skipped".format(node))
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050062 continue
Ekaterina Chernovab4806752019-07-26 16:02:18 +030063 nodes_with_packages.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020064 packages_names.update(packages_versions[node].keys())
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020065 for deb in packages_names:
66 if deb in exclude_packages:
67 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000068 diff = []
69 row = []
Ekaterina Chernovab4806752019-07-26 16:02:18 +030070 for node in nodes_with_packages:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050071 if not packages_versions[node]:
72 continue
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020073 if deb in packages_versions[node].keys():
74 diff.append(packages_versions[node][deb])
75 row.append("{}: {}".format(node, packages_versions[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000076 else:
77 row.append("{}: No package".format(node))
Ekaterina Chernovab4806752019-07-26 16:02:18 +030078
79 if diff.count(diff[0]) < len(nodes_with_packages):
Ekaterina Chernova7ea97152019-07-29 17:09:12 +030080 if not is_deb_in_exception(inconsistency_rule, deb, row):
Ekaterina Chernovab4806752019-07-26 16:02:18 +030081 row.sort()
82 row.insert(0, deb)
83 packages_with_different_versions.append(row)
84 assert len(packages_with_different_versions) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050085 "Several problems found: {0}".format(
Ekaterina Chernovab4806752019-07-26 16:02:18 +030086 json.dumps(packages_with_different_versions, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000087
88
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050089@pytest.mark.full
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030090def 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 Zhurba4bfd2ee2019-04-10 21:56:58 -050097 tgt='L@' + ','.join(nodes_in_group),
98 param='apt list --upgradable 2>/dev/null | grep -v Listing',
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030099 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 Zhurba5b15b9b2019-05-09 18:53:40 -0500111@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -0500112def test_check_module_versions(local_salt_client, nodes_in_group):
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300113 # defines modules specific to the concrete nodes
114 inconsistency_rule = {"ctl01": ["gnocchiclient", "ujson"], "log01": ["elasticsearch"]}
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200115 exclude_modules = utils.get_configuration().get("skipped_modules", [])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000116 pre_check = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -0500117 tgt="L@"+','.join(nodes_in_group),
118 param='dpkg -l | grep "python-pip "',
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500119 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000120 if pre_check.values().count('') > 0:
121 pytest.skip("pip is not installed on one or more nodes")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500122
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -0500123 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
124 expr_form='compound').keys()
Oleksii Zhurba599801a2019-06-04 17:26:51 -0500125
126 # PROD-30833
127 gtw01 = local_salt_client.pillar_get(
128 param='_param:openstack_gateway_node01_hostname') or 'gtw01'
129 cluster_domain = local_salt_client.pillar_get(
130 param='_param:cluster_domain') or '.local'
131 gtw01 += '.' + cluster_domain
132 if gtw01 in nodes_in_group:
133 octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes_in_group),
134 fun='pillar.get',
135 param='octavia:manager:enabled',
136 expr_form='compound')
137 gtws = [gtw for gtw in octavia.values() if gtw]
138 if len(gtws) == 1:
139 exclude_nodes.append(gtw01)
140 logging.info("gtw01 node is skipped in test_check_module_versions")
141
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500142 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
143
144 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000145 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -0500146 list_of_pip_packages = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
Oleksii Zhurba075cc7a2019-05-17 14:04:28 -0500147 fun='pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000148
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300149 nodes_with_packages = []
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -0500150
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300151 modules_with_different_versions = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200152 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000153
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500154 for node in total_nodes:
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300155 nodes_with_packages.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200156 packages_names.update([x.split("=")[0] for x in list_of_pip_packages[node]])
157 list_of_pip_packages[node] = dict([x.split("==") for x in list_of_pip_packages[node]])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000158
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200159 for deb in packages_names:
160 if deb in exclude_modules:
161 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000162 diff = []
163 row = []
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300164 for node in nodes_with_packages:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200165 if deb in list_of_pip_packages[node].keys():
166 diff.append(list_of_pip_packages[node][deb])
167 row.append("{}: {}".format(node, list_of_pip_packages[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000168 else:
169 row.append("{}: No module".format(node))
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300170 if diff.count(diff[0]) < len(nodes_with_packages):
171 if not is_deb_in_exception(inconsistency_rule, deb, row):
172 row.sort()
173 row.insert(0, deb)
174 modules_with_different_versions.append(row)
175 assert len(modules_with_different_versions) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -0500176 "Several problems found: {0}".format(
Ekaterina Chernova7ea97152019-07-29 17:09:12 +0300177 json.dumps(modules_with_different_versions, indent=4))
Oleksii Zhurba599801a2019-06-04 17:26:51 -0500178