blob: f76c3390d54523a30a9ce67bc73dc93c02a742b4 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00003
4
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05005def test_check_package_versions(local_salt_client, nodes_in_group):
Oleksii Zhurba5f768c52018-08-07 17:27:57 -05006 output = local_salt_client.cmd("L@"+','.join(nodes_in_group),
7 'lowpkg.list_pkgs',
8 expr_form='compound')
Oleksii Zhurbadad1acc2018-03-26 14:09:38 -05009 # Let's exclude cid01 and dbs01 nodes from this check
10 exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client",
11 'test.ping',
12 expr_form='compound').keys()
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050013 total_nodes = [i for i in output.keys() if i not in exclude_nodes]
14 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000015 pytest.skip("Nothing to compare - only 1 node")
16
17 nodes = []
18 pkts_data = []
19 my_set = set()
20
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050021 for node in total_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000022 nodes.append(node)
23 my_set.update(output[node].keys())
24
25 for deb in my_set:
26 diff = []
27 row = []
28 for node in nodes:
29 if deb in output[node].keys():
30 diff.append(output[node][deb])
31 row.append("{}: {}".format(node, output[node][deb]))
32 else:
33 row.append("{}: No package".format(node))
34 if diff.count(diff[0]) < len(nodes):
35 row.sort()
36 row.insert(0, deb)
37 pkts_data.append(row)
38 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050039 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050040 json.dumps(pkts_data, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000041
42
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050043def test_check_module_versions(local_salt_client, nodes_in_group):
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000044 pre_check = local_salt_client.cmd(
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050045 "L@"+','.join(nodes_in_group),
46 'cmd.run',
47 ['dpkg -l | grep "python-pip "'],
48 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000049 if pre_check.values().count('') > 0:
50 pytest.skip("pip is not installed on one or more nodes")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050051
52 exclude_nodes = local_salt_client.cmd("I@galera:master or I@gerrit:client",
53 'test.ping',
54 expr_form='compound').keys()
55 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
56
57 if len(total_nodes) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000058 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050059 output = local_salt_client.cmd("L@"+','.join(nodes_in_group),
60 'pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000061
62 nodes = []
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050063
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000064 pkts_data = []
65 my_set = set()
66
Oleksii Zhurba5f768c52018-08-07 17:27:57 -050067 for node in total_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000068 nodes.append(node)
69 my_set.update([x.split("=")[0] for x in output[node]])
70 output[node] = dict([x.split("==") for x in output[node]])
71
72 for deb in my_set:
73 diff = []
74 row = []
75 for node in nodes:
76 if deb in output[node].keys():
77 diff.append(output[node][deb])
78 row.append("{}: {}".format(node, output[node][deb]))
79 else:
80 row.append("{}: No module".format(node))
81 if diff.count(diff[0]) < len(nodes):
82 row.sort()
83 row.insert(0, deb)
84 pkts_data.append(row)
85 assert len(pkts_data) <= 1, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050086 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050087 json.dumps(pkts_data, indent=4))