blob: 724cc00e996e1edc7f2261bda3f19f56504e4780 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +00003import os
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00004from cvp_checks import utils
5
6
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05007def test_check_package_versions(local_salt_client, nodes_in_group):
8 output = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'lowpkg.list_pkgs', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00009
10 if len(output.keys()) < 2:
11 pytest.skip("Nothing to compare - only 1 node")
12
13 nodes = []
14 pkts_data = []
15 my_set = set()
16
17 for node in output:
18 nodes.append(node)
19 my_set.update(output[node].keys())
20
21 for deb in my_set:
22 diff = []
23 row = []
24 for node in nodes:
25 if deb in output[node].keys():
26 diff.append(output[node][deb])
27 row.append("{}: {}".format(node, output[node][deb]))
28 else:
29 row.append("{}: No package".format(node))
30 if diff.count(diff[0]) < len(nodes):
31 row.sort()
32 row.insert(0, deb)
33 pkts_data.append(row)
34 assert len(pkts_data) <= 1, \
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050035 "Several problems found: {1}".format(
36 json.dumps(pkts_data, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000037
38
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050039def test_check_module_versions(local_salt_client, nodes_in_group):
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000040 pre_check = local_salt_client.cmd(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050041 "L@"+','.join(nodes_in_group), 'cmd.run', ['dpkg -l | grep "python-pip "'], expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000042 if pre_check.values().count('') > 0:
43 pytest.skip("pip is not installed on one or more nodes")
44 if len(pre_check.keys()) < 2:
45 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050046 output = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000047
48 nodes = []
49 pkts_data = []
50 my_set = set()
51
52 for node in output:
53 nodes.append(node)
54 my_set.update([x.split("=")[0] for x in output[node]])
55 output[node] = dict([x.split("==") for x in output[node]])
56
57 for deb in my_set:
58 diff = []
59 row = []
60 for node in nodes:
61 if deb in output[node].keys():
62 diff.append(output[node][deb])
63 row.append("{}: {}".format(node, output[node][deb]))
64 else:
65 row.append("{}: No module".format(node))
66 if diff.count(diff[0]) < len(nodes):
67 row.sort()
68 row.insert(0, deb)
69 pkts_data.append(row)
70 assert len(pkts_data) <= 1, \
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050071 "Several problems found: {1}".format(
72 json.dumps(pkts_data, indent=4))