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