blob: 382576a972ee0b3050af73ef3ab0ef4ed3086424 [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
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00006
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05007@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05008def test_check_package_versions(local_salt_client, nodes_in_group):
Hanna Arhipova8fd295c2019-03-07 13:46:43 +02009 exclude_packages = utils.get_configuration().get("skipped_packages", [])
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050010 packages_versions = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
11 fun='lowpkg.list_pkgs',
12 expr_form='compound')
Oleksii Zhurbadad1acc2018-03-26 14:09:38 -050013 # Let's exclude cid01 and dbs01 nodes from this check
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050014 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
15 expr_form='compound').keys()
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020016 total_nodes = [i for i in packages_versions.keys() if i not in exclude_nodes]
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050017 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000018 pytest.skip("Nothing to compare - only 1 node")
19
20 nodes = []
21 pkts_data = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020022 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000023
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050024 for node in total_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050025 if not packages_versions[node]:
26 # TODO: do not skip node
Hanna Arhipova56eab942019-05-06 20:14:18 +030027 logging.warning("Node {} is skipped".format(node))
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050028 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000029 nodes.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020030 packages_names.update(packages_versions[node].keys())
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000031
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020032 for deb in packages_names:
33 if deb in exclude_packages:
34 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000035 diff = []
36 row = []
37 for node in nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050038 if not packages_versions[node]:
39 continue
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020040 if deb in packages_versions[node].keys():
41 diff.append(packages_versions[node][deb])
42 row.append("{}: {}".format(node, packages_versions[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000043 else:
44 row.append("{}: No package".format(node))
45 if diff.count(diff[0]) < len(nodes):
46 row.sort()
47 row.insert(0, deb)
48 pkts_data.append(row)
49 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050050 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050051 json.dumps(pkts_data, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000052
53
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050054@pytest.mark.full
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030055def test_packages_are_latest(local_salt_client, nodes_in_group):
56 config = utils.get_configuration()
57 skip = config.get("test_packages")["skip_test"]
58 if skip:
59 pytest.skip("Test for the latest packages is disabled")
60 skipped_pkg = config.get("test_packages")["skipped_packages"]
61 info_salt = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050062 tgt='L@' + ','.join(nodes_in_group),
63 param='apt list --upgradable 2>/dev/null | grep -v Listing',
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030064 expr_form='compound')
65 for node in nodes_in_group:
66 result = []
67 if info_salt[node]:
68 upg_list = info_salt[node].split('\n')
69 for i in upg_list:
70 if i.split('/')[0] not in skipped_pkg:
71 result.append(i)
72 assert not result, "Please check not latest packages at {}:\n{}".format(
73 node, "\n".join(result))
74
75
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050076@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050077def test_check_module_versions(local_salt_client, nodes_in_group):
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020078 exclude_modules = utils.get_configuration().get("skipped_modules", [])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000079 pre_check = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050080 tgt="L@"+','.join(nodes_in_group),
81 param='dpkg -l | grep "python-pip "',
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050082 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000083 if pre_check.values().count('') > 0:
84 pytest.skip("pip is not installed on one or more nodes")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050085
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050086 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
87 expr_form='compound').keys()
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050088 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
89
90 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000091 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050092 list_of_pip_packages = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
93 param='pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000094
95 nodes = []
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050096
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000097 pkts_data = []
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020098 packages_names = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000099
Oleksii Zhurba5f768c52018-08-07 17:27:57 -0500100 for node in total_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000101 nodes.append(node)
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200102 packages_names.update([x.split("=")[0] for x in list_of_pip_packages[node]])
103 list_of_pip_packages[node] = dict([x.split("==") for x in list_of_pip_packages[node]])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000104
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200105 for deb in packages_names:
106 if deb in exclude_modules:
107 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000108 diff = []
109 row = []
110 for node in nodes:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +0200111 if deb in list_of_pip_packages[node].keys():
112 diff.append(list_of_pip_packages[node][deb])
113 row.append("{}: {}".format(node, list_of_pip_packages[node][deb]))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +0000114 else:
115 row.append("{}: No module".format(node))
116 if diff.count(diff[0]) < len(nodes):
117 row.sort()
118 row.insert(0, deb)
119 pkts_data.append(row)
120 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -0500121 "Several problems found: {0}".format(
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -0500122 json.dumps(pkts_data, indent=4))