blob: 6c1ccc9ddeb241ea39c7c0620514990ba110f087 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +03003import utils
4
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00005
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05006def test_check_package_versions(local_salt_client, nodes_in_group):
Hanna Arhipova8fd295c2019-03-07 13:46:43 +02007 exclude_packages = utils.get_configuration().get("skipped_packages", [])
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -05008 packages_versions = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
9 fun='lowpkg.list_pkgs',
10 expr_form='compound')
Oleksii Zhurbadad1acc2018-03-26 14:09:38 -050011 # Let's exclude cid01 and dbs01 nodes from this check
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050012 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
13 expr_form='compound').keys()
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020014 total_nodes = [i for i in packages_versions.keys() if i not in exclude_nodes]
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050015 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000016 pytest.skip("Nothing to compare - only 1 node")
17
18 nodes = []
19 pkts_data = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020020 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000021
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050022 for node in total_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050023 if not packages_versions[node]:
24 # TODO: do not skip node
25 print "Node {} is skipped".format (node)
26 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000027 nodes.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020028 packages_names.update(packages_versions[node].keys())
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000029
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020030 for deb in packages_names:
31 if deb in exclude_packages:
32 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000033 diff = []
34 row = []
35 for node in nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050036 if not packages_versions[node]:
37 continue
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020038 if deb in packages_versions[node].keys():
39 diff.append(packages_versions[node][deb])
40 row.append("{}: {}".format(node, packages_versions[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000041 else:
42 row.append("{}: No package".format(node))
43 if diff.count(diff[0]) < len(nodes):
44 row.sort()
45 row.insert(0, deb)
46 pkts_data.append(row)
47 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050048 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050049 json.dumps(pkts_data, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000050
51
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030052def test_packages_are_latest(local_salt_client, nodes_in_group):
53 config = utils.get_configuration()
54 skip = config.get("test_packages")["skip_test"]
55 if skip:
56 pytest.skip("Test for the latest packages is disabled")
57 skipped_pkg = config.get("test_packages")["skipped_packages"]
58 info_salt = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050059 tgt='L@' + ','.join(nodes_in_group),
60 param='apt list --upgradable 2>/dev/null | grep -v Listing',
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030061 expr_form='compound')
62 for node in nodes_in_group:
63 result = []
64 if info_salt[node]:
65 upg_list = info_salt[node].split('\n')
66 for i in upg_list:
67 if i.split('/')[0] not in skipped_pkg:
68 result.append(i)
69 assert not result, "Please check not latest packages at {}:\n{}".format(
70 node, "\n".join(result))
71
72
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050073def test_check_module_versions(local_salt_client, nodes_in_group):
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020074 exclude_modules = utils.get_configuration().get("skipped_modules", [])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000075 pre_check = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050076 tgt="L@"+','.join(nodes_in_group),
77 param='dpkg -l | grep "python-pip "',
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050078 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000079 if pre_check.values().count('') > 0:
80 pytest.skip("pip is not installed on one or more nodes")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050081
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050082 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
83 expr_form='compound').keys()
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050084 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
85
86 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000087 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050088 list_of_pip_packages = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
89 param='pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000090
91 nodes = []
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050092
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000093 pkts_data = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020094 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000095
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050096 for node in total_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000097 nodes.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020098 packages_names.update([x.split("=")[0] for x in list_of_pip_packages[node]])
99 list_of_pip_packages[node] = dict([x.split("==") for x in list_of_pip_packages[node]])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000100
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200101 for deb in packages_names:
102 if deb in exclude_modules:
103 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000104 diff = []
105 row = []
106 for node in nodes:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200107 if deb in list_of_pip_packages[node].keys():
108 diff.append(list_of_pip_packages[node][deb])
109 row.append("{}: {}".format(node, list_of_pip_packages[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000110 else:
111 row.append("{}: No module".format(node))
112 if diff.count(diff[0]) < len(nodes):
113 row.sort()
114 row.insert(0, deb)
115 pkts_data.append(row)
116 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -0500117 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -0500118 json.dumps(pkts_data, indent=4))