blob: 79915ec50cec1c0d9ae4b3e19b55855e29d54754 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
3from cvp_checks import utils
4
5
6@pytest.mark.parametrize(
7 "group",
8 utils.get_groups(utils.get_configuration(__file__))
9)
10def test_check_package_versions(local_salt_client, group):
11 config = utils.get_configuration(__file__)
12
13 output = local_salt_client.cmd(group, 'lowpkg.list_pkgs', expr_form='pcre')
14
15 if len(output.keys()) < 2:
16 pytest.skip("Nothing to compare - only 1 node")
17
18 nodes = []
19 pkts_data = []
20 my_set = set()
21
22 for node in output:
23 nodes.append(node)
24 my_set.update(output[node].keys())
25
26 for deb in my_set:
27 diff = []
28 row = []
29 for node in nodes:
30 if deb in output[node].keys():
31 diff.append(output[node][deb])
32 row.append("{}: {}".format(node, output[node][deb]))
33 else:
34 row.append("{}: No package".format(node))
35 if diff.count(diff[0]) < len(nodes):
36 row.sort()
37 row.insert(0, deb)
38 pkts_data.append(row)
39 assert len(pkts_data) <= 1, \
40 "Several problems found for {0} group: {1}".format(
41 group, json.dumps(pkts_data, indent=4))
42
43
44@pytest.mark.parametrize(
45 "group",
46 utils.get_groups(utils.get_configuration(__file__))
47)
48def test_check_module_versions(local_salt_client, group):
49 config = utils.get_configuration(__file__)
50
51 pre_check = local_salt_client.cmd(
52 group, 'cmd.run', ['dpkg -l | grep "python-pip "'], expr_form='pcre')
53 if pre_check.values().count('') > 0:
54 pytest.skip("pip is not installed on one or more nodes")
55 if len(pre_check.keys()) < 2:
56 pytest.skip("Nothing to compare - only 1 node")
57 output = local_salt_client.cmd(group, 'pip.freeze', expr_form='pcre')
58
59 nodes = []
60 pkts_data = []
61 my_set = set()
62
63 for node in output:
64 nodes.append(node)
65 my_set.update([x.split("=")[0] for x in output[node]])
66 output[node] = dict([x.split("==") for x in output[node]])
67
68 for deb in my_set:
69 diff = []
70 row = []
71 for node in nodes:
72 if deb in output[node].keys():
73 diff.append(output[node][deb])
74 row.append("{}: {}".format(node, output[node][deb]))
75 else:
76 row.append("{}: No module".format(node))
77 if diff.count(diff[0]) < len(nodes):
78 row.sort()
79 row.insert(0, deb)
80 pkts_data.append(row)
81 assert len(pkts_data) <= 1, \
82 "Several problems found for {0} group: {1}".format(
83 group, json.dumps(pkts_data, indent=4))