blob: 786fba9772caae26e670529b10ab54cea4ff1490 [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 Zhurba5b15b9b2019-05-09 18:53:40 -05006@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05007def test_check_package_versions(local_salt_client, nodes_in_group):
Hanna Arhipova8fd295c2019-03-07 13:46:43 +02008 exclude_packages = utils.get_configuration().get("skipped_packages", [])
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -05009 packages_versions = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
10 fun='lowpkg.list_pkgs',
11 expr_form='compound')
Oleksii Zhurbadad1acc2018-03-26 14:09:38 -050012 # Let's exclude cid01 and dbs01 nodes from this check
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050013 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
14 expr_form='compound').keys()
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020015 total_nodes = [i for i in packages_versions.keys() if i not in exclude_nodes]
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050016 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000017 pytest.skip("Nothing to compare - only 1 node")
18
19 nodes = []
20 pkts_data = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020021 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000022
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050023 for node in total_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050024 if not packages_versions[node]:
25 # TODO: do not skip node
26 print "Node {} is skipped".format (node)
27 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000028 nodes.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020029 packages_names.update(packages_versions[node].keys())
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000030
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020031 for deb in packages_names:
32 if deb in exclude_packages:
33 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000034 diff = []
35 row = []
36 for node in nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050037 if not packages_versions[node]:
38 continue
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020039 if deb in packages_versions[node].keys():
40 diff.append(packages_versions[node][deb])
41 row.append("{}: {}".format(node, packages_versions[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000042 else:
43 row.append("{}: No package".format(node))
44 if diff.count(diff[0]) < len(nodes):
45 row.sort()
46 row.insert(0, deb)
47 pkts_data.append(row)
48 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050049 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050050 json.dumps(pkts_data, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000051
52
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050053@pytest.mark.full
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030054def test_packages_are_latest(local_salt_client, nodes_in_group):
55 config = utils.get_configuration()
56 skip = config.get("test_packages")["skip_test"]
57 if skip:
58 pytest.skip("Test for the latest packages is disabled")
59 skipped_pkg = config.get("test_packages")["skipped_packages"]
60 info_salt = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050061 tgt='L@' + ','.join(nodes_in_group),
62 param='apt list --upgradable 2>/dev/null | grep -v Listing',
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030063 expr_form='compound')
64 for node in nodes_in_group:
65 result = []
66 if info_salt[node]:
67 upg_list = info_salt[node].split('\n')
68 for i in upg_list:
69 if i.split('/')[0] not in skipped_pkg:
70 result.append(i)
71 assert not result, "Please check not latest packages at {}:\n{}".format(
72 node, "\n".join(result))
73
74
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050075@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050076def test_check_module_versions(local_salt_client, nodes_in_group):
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020077 exclude_modules = utils.get_configuration().get("skipped_modules", [])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000078 pre_check = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050079 tgt="L@"+','.join(nodes_in_group),
80 param='dpkg -l | grep "python-pip "',
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050081 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000082 if pre_check.values().count('') > 0:
83 pytest.skip("pip is not installed on one or more nodes")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050084
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050085 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
86 expr_form='compound').keys()
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050087 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
88
89 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000090 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050091 list_of_pip_packages = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
92 param='pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000093
94 nodes = []
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050095
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000096 pkts_data = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020097 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000098
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050099 for node in total_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000100 nodes.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200101 packages_names.update([x.split("=")[0] for x in list_of_pip_packages[node]])
102 list_of_pip_packages[node] = dict([x.split("==") for x in list_of_pip_packages[node]])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000103
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200104 for deb in packages_names:
105 if deb in exclude_modules:
106 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000107 diff = []
108 row = []
109 for node in nodes:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200110 if deb in list_of_pip_packages[node].keys():
111 diff.append(list_of_pip_packages[node][deb])
112 row.append("{}: {}".format(node, list_of_pip_packages[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000113 else:
114 row.append("{}: No module".format(node))
115 if diff.count(diff[0]) < len(nodes):
116 row.sort()
117 row.insert(0, deb)
118 pkts_data.append(row)
119 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -0500120 "Several problems found: {0}".format(
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -0500121 json.dumps(pkts_data, indent=4))