blob: 2db8c7c4489e2bf37f0567b0650493a130715e1b [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", [])
8 packages_versions = local_salt_client.cmd("L@"+','.join(nodes_in_group),
9 '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
12 exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client",
13 'test.ping',
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 Zhurbaa10927b2017-09-27 22:09:23 +000024 nodes.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020025 packages_names.update(packages_versions[node].keys())
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000026
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020027 for deb in packages_names:
28 if deb in exclude_packages:
29 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000030 diff = []
31 row = []
32 for node in nodes:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020033 if deb in packages_versions[node].keys():
34 diff.append(packages_versions[node][deb])
35 row.append("{}: {}".format(node, packages_versions[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000036 else:
37 row.append("{}: No package".format(node))
38 if diff.count(diff[0]) < len(nodes):
39 row.sort()
40 row.insert(0, deb)
41 pkts_data.append(row)
42 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050043 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050044 json.dumps(pkts_data, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000045
46
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030047def test_packages_are_latest(local_salt_client, nodes_in_group):
48 config = utils.get_configuration()
49 skip = config.get("test_packages")["skip_test"]
50 if skip:
51 pytest.skip("Test for the latest packages is disabled")
52 skipped_pkg = config.get("test_packages")["skipped_packages"]
53 info_salt = local_salt_client.cmd(
54 'L@' + ','.join(nodes_in_group),
55 'cmd.run', ['apt list --upgradable 2>/dev/null | grep -v Listing'],
56 expr_form='compound')
57 for node in nodes_in_group:
58 result = []
59 if info_salt[node]:
60 upg_list = info_salt[node].split('\n')
61 for i in upg_list:
62 if i.split('/')[0] not in skipped_pkg:
63 result.append(i)
64 assert not result, "Please check not latest packages at {}:\n{}".format(
65 node, "\n".join(result))
66
67
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050068def test_check_module_versions(local_salt_client, nodes_in_group):
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020069 exclude_modules = utils.get_configuration().get("skipped_modules", [])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000070 pre_check = local_salt_client.cmd(
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050071 "L@"+','.join(nodes_in_group),
72 'cmd.run',
73 ['dpkg -l | grep "python-pip "'],
74 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000075 if pre_check.values().count('') > 0:
76 pytest.skip("pip is not installed on one or more nodes")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050077
78 exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client",
79 'test.ping',
80 expr_form='compound').keys()
81 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
82
83 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000084 pytest.skip("Nothing to compare - only 1 node")
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020085 list_of_pip_packages = local_salt_client.cmd("L@"+','.join(nodes_in_group),
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050086 'pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000087
88 nodes = []
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050089
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000090 pkts_data = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020091 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000092
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050093 for node in total_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000094 nodes.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020095 packages_names.update([x.split("=")[0] for x in list_of_pip_packages[node]])
96 list_of_pip_packages[node] = dict([x.split("==") for x in list_of_pip_packages[node]])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000097
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020098 for deb in packages_names:
99 if deb in exclude_modules:
100 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000101 diff = []
102 row = []
103 for node in nodes:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200104 if deb in list_of_pip_packages[node].keys():
105 diff.append(list_of_pip_packages[node][deb])
106 row.append("{}: {}".format(node, list_of_pip_packages[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000107 else:
108 row.append("{}: No module".format(node))
109 if diff.count(diff[0]) < len(nodes):
110 row.sort()
111 row.insert(0, deb)
112 pkts_data.append(row)
113 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -0500114 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -0500115 json.dumps(pkts_data, indent=4))