blob: e9448ee063723d85abd4e58faab6e1969098371f [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00003
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +03004import utils
5
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00006
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05007def test_check_package_versions(local_salt_client, nodes_in_group):
Oleksii Zhurba5f768c52018-08-07 17:27:57 -05008 output = 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()
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050015 total_nodes = [i for i in output.keys() if i not in exclude_nodes]
16 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 = []
21 my_set = set()
22
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050023 for node in total_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000024 nodes.append(node)
25 my_set.update(output[node].keys())
26
27 for deb in my_set:
28 diff = []
29 row = []
30 for node in nodes:
31 if deb in output[node].keys():
32 diff.append(output[node][deb])
33 row.append("{}: {}".format(node, output[node][deb]))
34 else:
35 row.append("{}: No package".format(node))
36 if diff.count(diff[0]) < len(nodes):
37 row.sort()
38 row.insert(0, deb)
39 pkts_data.append(row)
40 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050041 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050042 json.dumps(pkts_data, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000043
44
Ievgeniia Zadorozhna6baf7872019-01-25 19:09:30 +030045def test_packages_are_latest(local_salt_client, nodes_in_group):
46 config = utils.get_configuration()
47 skip = config.get("test_packages")["skip_test"]
48 if skip:
49 pytest.skip("Test for the latest packages is disabled")
50 skipped_pkg = config.get("test_packages")["skipped_packages"]
51 info_salt = local_salt_client.cmd(
52 'L@' + ','.join(nodes_in_group),
53 'cmd.run', ['apt list --upgradable 2>/dev/null | grep -v Listing'],
54 expr_form='compound')
55 for node in nodes_in_group:
56 result = []
57 if info_salt[node]:
58 upg_list = info_salt[node].split('\n')
59 for i in upg_list:
60 if i.split('/')[0] not in skipped_pkg:
61 result.append(i)
62 assert not result, "Please check not latest packages at {}:\n{}".format(
63 node, "\n".join(result))
64
65
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050066def test_check_module_versions(local_salt_client, nodes_in_group):
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000067 pre_check = local_salt_client.cmd(
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050068 "L@"+','.join(nodes_in_group),
69 'cmd.run',
70 ['dpkg -l | grep "python-pip "'],
71 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000072 if pre_check.values().count('') > 0:
73 pytest.skip("pip is not installed on one or more nodes")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050074
75 exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client",
76 'test.ping',
77 expr_form='compound').keys()
78 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
79
80 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000081 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050082 output = local_salt_client.cmd("L@"+','.join(nodes_in_group),
83 'pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000084
85 nodes = []
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050086
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000087 pkts_data = []
88 my_set = set()
89
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050090 for node in total_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000091 nodes.append(node)
92 my_set.update([x.split("=")[0] for x in output[node]])
93 output[node] = dict([x.split("==") for x in output[node]])
94
95 for deb in my_set:
96 diff = []
97 row = []
98 for node in nodes:
99 if deb in output[node].keys():
100 diff.append(output[node][deb])
101 row.append("{}: {}".format(node, output[node][deb]))
102 else:
103 row.append("{}: No module".format(node))
104 if diff.count(diff[0]) < len(nodes):
105 row.sort()
106 row.insert(0, deb)
107 pkts_data.append(row)
108 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -0500109 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -0500110 json.dumps(pkts_data, indent=4))