blob: d85e87e9fe2a2f5529d67cec69b7edb5f4f756d0 [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
7@pytest.mark.parametrize(
8 "group",
Oleksii Zhurbae0dedb52018-01-16 00:55:25 +00009 utils.node_groups.keys()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000010)
11def test_check_package_versions(local_salt_client, group):
Oleksii Zhurbae0dedb52018-01-16 00:55:25 +000012 output = local_salt_client.cmd("L@"+','.join(utils.node_groups[group]), 'lowpkg.list_pkgs', expr_form='compound')
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:
22 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, \
39 "Several problems found for {0} group: {1}".format(
40 group, json.dumps(pkts_data, indent=4))
41
42
43@pytest.mark.parametrize(
44 "group",
Oleksii Zhurbae0dedb52018-01-16 00:55:25 +000045 utils.node_groups.keys()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000046)
47def test_check_module_versions(local_salt_client, group):
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000048 pre_check = local_salt_client.cmd(
Oleksii Zhurbae0dedb52018-01-16 00:55:25 +000049 "L@"+','.join(utils.node_groups[group]), 'cmd.run', ['dpkg -l | grep "python-pip "'], expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000050 if pre_check.values().count('') > 0:
51 pytest.skip("pip is not installed on one or more nodes")
52 if len(pre_check.keys()) < 2:
53 pytest.skip("Nothing to compare - only 1 node")
Oleksii Zhurbae0dedb52018-01-16 00:55:25 +000054 output = local_salt_client.cmd("L@"+','.join(utils.node_groups[group]), 'pip.freeze', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000055
56 nodes = []
57 pkts_data = []
58 my_set = set()
59
60 for node in output:
61 nodes.append(node)
62 my_set.update([x.split("=")[0] for x in output[node]])
63 output[node] = dict([x.split("==") for x in output[node]])
64
65 for deb in my_set:
66 diff = []
67 row = []
68 for node in nodes:
69 if deb in output[node].keys():
70 diff.append(output[node][deb])
71 row.append("{}: {}".format(node, output[node][deb]))
72 else:
73 row.append("{}: No module".format(node))
74 if diff.count(diff[0]) < len(nodes):
75 row.sort()
76 row.insert(0, deb)
77 pkts_data.append(row)
78 assert len(pkts_data) <= 1, \
79 "Several problems found for {0} group: {1}".format(
80 group, json.dumps(pkts_data, indent=4))