blob: abdd04bc08c57e6425d958abdaa9ed6ba227ab44 [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import pytest
2import json
3import utils
Hanna Arhipova1eef8312019-05-06 20:14:18 +03004import logging
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03005
6
Oleksii Zhurba23c18332019-05-09 18:53:40 -05007@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03008def test_check_package_versions(local_salt_client, nodes_in_group):
9 exclude_packages = utils.get_configuration().get("skipped_packages", [])
10 packages_versions = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
11 fun='lowpkg.list_pkgs',
12 expr_form='compound')
13 # Let's exclude cid01 and dbs01 nodes from this check
14 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
15 expr_form='compound').keys()
16 total_nodes = [i for i in packages_versions.keys() if i not in exclude_nodes]
17 if len(total_nodes) < 2:
18 pytest.skip("Nothing to compare - only 1 node")
19
20 nodes = []
21 pkts_data = []
22 packages_names = set()
23
24 for node in total_nodes:
25 if not packages_versions[node]:
26 # TODO: do not skip node
Hanna Arhipova1eef8312019-05-06 20:14:18 +030027 logging.warning("Node {} is skipped".format(node))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030028 continue
29 nodes.append(node)
30 packages_names.update(packages_versions[node].keys())
31
32 for deb in packages_names:
33 if deb in exclude_packages:
34 continue
35 diff = []
36 row = []
37 for node in nodes:
38 if not packages_versions[node]:
39 continue
40 if deb in packages_versions[node].keys():
41 diff.append(packages_versions[node][deb])
42 row.append("{}: {}".format(node, packages_versions[node][deb]))
43 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, \
50 "Several problems found: {0}".format(
51 json.dumps(pkts_data, indent=4))
52
53
Oleksii Zhurba23c18332019-05-09 18:53:40 -050054@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +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(
62 tgt='L@' + ','.join(nodes_in_group),
63 param='apt list --upgradable 2>/dev/null | grep -v Listing',
64 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 Zhurba23c18332019-05-09 18:53:40 -050076@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030077def test_check_module_versions(local_salt_client, nodes_in_group):
78 exclude_modules = utils.get_configuration().get("skipped_modules", [])
79 pre_check = local_salt_client.cmd(
80 tgt="L@"+','.join(nodes_in_group),
81 param='dpkg -l | grep "python-pip "',
82 expr_form='compound')
83 if pre_check.values().count('') > 0:
84 pytest.skip("pip is not installed on one or more nodes")
85
86 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
87 expr_form='compound').keys()
88 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
89
90 if len(total_nodes) < 2:
91 pytest.skip("Nothing to compare - only 1 node")
92 list_of_pip_packages = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
Oleksii Zhurbae01d5e82019-05-17 14:04:28 -050093 fun='pip.freeze', expr_form='compound')
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030094
95 nodes = []
96
97 pkts_data = []
98 packages_names = set()
99
100 for node in total_nodes:
101 nodes.append(node)
102 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]])
104
105 for deb in packages_names:
106 if deb in exclude_modules:
107 continue
108 diff = []
109 row = []
110 for node in nodes:
111 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]))
114 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, \
121 "Several problems found: {0}".format(
Oleksii Zhurba23c18332019-05-09 18:53:40 -0500122 json.dumps(pkts_data, indent=4))