blob: 34cb5d85005888b69eaa65cdeccd44f876de5487 [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import pytest
2import json
3import utils
Hanna Arhipova1eef8312019-05-06 20:14:18 +03004import logging
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03005
6
Oleksii Zhurba23c18332019-05-09 18:53:40 -05007@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03008def test_check_package_versions(local_salt_client, nodes_in_group):
9 exclude_packages = utils.get_configuration().get("skipped_packages", [])
10 packages_versions = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
11 fun='lowpkg.list_pkgs',
12 expr_form='compound')
13 # Let's exclude cid01 and dbs01 nodes from this check
14 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
15 expr_form='compound').keys()
Oleksii Zhurbaa3e79ce2019-06-04 17:26:51 -050016
17 # PROD-30833
18 gtw01 = local_salt_client.pillar_get(
19 param='_param:openstack_gateway_node01_hostname') or 'gtw01'
20 cluster_domain = local_salt_client.pillar_get(
21 param='_param:cluster_domain') or '.local'
22 gtw01 += '.' + cluster_domain
23 if gtw01 in nodes_in_group:
24 os_octavia = local_salt_client.pillar_get(
25 param='_param:openstack_octavia_enabled')
26 octavia_man_cl = local_salt_client.pillar_get(
27 param='_param:octavia_manager_cluster')
28 if os_octavia and not octavia_man_cl:
29 exclude_nodes.append(gtw01)
30 logging.info("gtw01 node is skipped in test_check_package_versions")
31
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030032 total_nodes = [i for i in packages_versions.keys() if i not in exclude_nodes]
33 if len(total_nodes) < 2:
34 pytest.skip("Nothing to compare - only 1 node")
35
36 nodes = []
37 pkts_data = []
38 packages_names = set()
39
40 for node in total_nodes:
41 if not packages_versions[node]:
42 # TODO: do not skip node
Hanna Arhipova1eef8312019-05-06 20:14:18 +030043 logging.warning("Node {} is skipped".format(node))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030044 continue
45 nodes.append(node)
46 packages_names.update(packages_versions[node].keys())
47
48 for deb in packages_names:
49 if deb in exclude_packages:
50 continue
51 diff = []
52 row = []
53 for node in nodes:
54 if not packages_versions[node]:
55 continue
56 if deb in packages_versions[node].keys():
57 diff.append(packages_versions[node][deb])
58 row.append("{}: {}".format(node, packages_versions[node][deb]))
59 else:
60 row.append("{}: No package".format(node))
61 if diff.count(diff[0]) < len(nodes):
62 row.sort()
63 row.insert(0, deb)
64 pkts_data.append(row)
65 assert len(pkts_data) <= 1, \
66 "Several problems found: {0}".format(
67 json.dumps(pkts_data, indent=4))
68
69
Oleksii Zhurba23c18332019-05-09 18:53:40 -050070@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030071def test_packages_are_latest(local_salt_client, nodes_in_group):
72 config = utils.get_configuration()
73 skip = config.get("test_packages")["skip_test"]
74 if skip:
75 pytest.skip("Test for the latest packages is disabled")
76 skipped_pkg = config.get("test_packages")["skipped_packages"]
77 info_salt = local_salt_client.cmd(
78 tgt='L@' + ','.join(nodes_in_group),
79 param='apt list --upgradable 2>/dev/null | grep -v Listing',
80 expr_form='compound')
81 for node in nodes_in_group:
82 result = []
83 if info_salt[node]:
84 upg_list = info_salt[node].split('\n')
85 for i in upg_list:
86 if i.split('/')[0] not in skipped_pkg:
87 result.append(i)
88 assert not result, "Please check not latest packages at {}:\n{}".format(
89 node, "\n".join(result))
90
91
Oleksii Zhurba23c18332019-05-09 18:53:40 -050092@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030093def test_check_module_versions(local_salt_client, nodes_in_group):
94 exclude_modules = utils.get_configuration().get("skipped_modules", [])
95 pre_check = local_salt_client.cmd(
96 tgt="L@"+','.join(nodes_in_group),
97 param='dpkg -l | grep "python-pip "',
98 expr_form='compound')
99 if pre_check.values().count('') > 0:
100 pytest.skip("pip is not installed on one or more nodes")
101
102 exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
103 expr_form='compound').keys()
Oleksii Zhurbaa3e79ce2019-06-04 17:26:51 -0500104
105 # PROD-30833
106 gtw01 = local_salt_client.pillar_get(
107 param='_param:openstack_gateway_node01_hostname') or 'gtw01'
108 cluster_domain = local_salt_client.pillar_get(
109 param='_param:cluster_domain') or '.local'
110 gtw01 += '.' + cluster_domain
111 if gtw01 in nodes_in_group:
112 os_octavia = local_salt_client.pillar_get(
113 param='_param:openstack_octavia_enabled')
114 octavia_man_cl = local_salt_client.pillar_get(
115 param='_param:octavia_manager_cluster')
116 if os_octavia and not octavia_man_cl:
117 exclude_nodes.append(gtw01)
118 logging.info("gtw01 node is skipped in test_check_module_versions")
119
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +0300120 total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
121
122 if len(total_nodes) < 2:
123 pytest.skip("Nothing to compare - only 1 node")
124 list_of_pip_packages = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
Oleksii Zhurbae01d5e82019-05-17 14:04:28 -0500125 fun='pip.freeze', expr_form='compound')
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +0300126
127 nodes = []
128
129 pkts_data = []
130 packages_names = set()
131
132 for node in total_nodes:
133 nodes.append(node)
134 packages_names.update([x.split("=")[0] for x in list_of_pip_packages[node]])
135 list_of_pip_packages[node] = dict([x.split("==") for x in list_of_pip_packages[node]])
136
137 for deb in packages_names:
138 if deb in exclude_modules:
139 continue
140 diff = []
141 row = []
142 for node in nodes:
143 if deb in list_of_pip_packages[node].keys():
144 diff.append(list_of_pip_packages[node][deb])
145 row.append("{}: {}".format(node, list_of_pip_packages[node][deb]))
146 else:
147 row.append("{}: No module".format(node))
148 if diff.count(diff[0]) < len(nodes):
149 row.sort()
150 row.insert(0, deb)
151 pkts_data.append(row)
152 assert len(pkts_data) <= 1, \
153 "Several problems found: {0}".format(
Oleksii Zhurbaa3e79ce2019-06-04 17:26:51 -0500154 json.dumps(pkts_data, indent=4))