blob: 30ddb73e411c44acd34bea6cb19faadc052b2088 [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 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 Zhurbaa10927b2017-09-27 22:09:23 +000013
14 if len(output.keys()) < 2:
15 pytest.skip("Nothing to compare - only 1 node")
16
17 nodes = []
18 pkts_data = []
19 my_set = set()
20
21 for node in output:
Oleksii Zhurbadad1acc2018-03-26 14:09:38 -050022 if node in exclude_nodes:
23 continue
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 Zhurbad0ae87f2018-03-26 13:36:25 -050041 "Several problems found: {1}".format(
42 json.dumps(pkts_data, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000043
44
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050045def test_check_module_versions(local_salt_client, nodes_in_group):
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000046 pre_check = local_salt_client.cmd(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050047 "L@"+','.join(nodes_in_group), 'cmd.run', ['dpkg -l | grep "python-pip "'], expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000048 if pre_check.values().count('') > 0:
49 pytest.skip("pip is not installed on one or more nodes")
50 if len(pre_check.keys()) < 2:
51 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050052 output = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000053
54 nodes = []
55 pkts_data = []
56 my_set = set()
57
58 for node in output:
59 nodes.append(node)
60 my_set.update([x.split("=")[0] for x in output[node]])
61 output[node] = dict([x.split("==") for x in output[node]])
62
63 for deb in my_set:
64 diff = []
65 row = []
66 for node in nodes:
67 if deb in output[node].keys():
68 diff.append(output[node][deb])
69 row.append("{}: {}".format(node, output[node][deb]))
70 else:
71 row.append("{}: No module".format(node))
72 if diff.count(diff[0]) < len(nodes):
73 row.sort()
74 row.insert(0, deb)
75 pkts_data.append(row)
76 assert len(pkts_data) <= 1, \
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050077 "Several problems found: {1}".format(
78 json.dumps(pkts_data, indent=4))