root / qa / qa_cluster.py @ 946e553b
History | View | Annotate | Download (17 kB)
1 | c68d1f43 | Michael Hanselmann | #
|
---|---|---|---|
2 | c68d1f43 | Michael Hanselmann | #
|
3 | c68d1f43 | Michael Hanselmann | |
4 | 1e7acc3b | Iustin Pop | # Copyright (C) 2007, 2010, 2011, 2012 Google Inc.
|
5 | cec9845c | Michael Hanselmann | #
|
6 | cec9845c | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | cec9845c | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | cec9845c | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | cec9845c | Michael Hanselmann | # (at your option) any later version.
|
10 | cec9845c | Michael Hanselmann | #
|
11 | cec9845c | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | cec9845c | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | cec9845c | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | cec9845c | Michael Hanselmann | # General Public License for more details.
|
15 | cec9845c | Michael Hanselmann | #
|
16 | cec9845c | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | cec9845c | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | cec9845c | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | cec9845c | Michael Hanselmann | # 02110-1301, USA.
|
20 | cec9845c | Michael Hanselmann | |
21 | cec9845c | Michael Hanselmann | |
22 | cec9845c | Michael Hanselmann | """Cluster related QA tests.
|
23 | cec9845c | Michael Hanselmann |
|
24 | cec9845c | Michael Hanselmann | """
|
25 | cec9845c | Michael Hanselmann | |
26 | cec9845c | Michael Hanselmann | import tempfile |
27 | 49ceab21 | Michael Hanselmann | import os.path |
28 | cec9845c | Michael Hanselmann | |
29 | 6d4a1656 | Michael Hanselmann | from ganeti import constants |
30 | 66d1f035 | René Nussbaumer | from ganeti import compat |
31 | cec9845c | Michael Hanselmann | from ganeti import utils |
32 | 304d9f02 | Michael Hanselmann | from ganeti import pathutils |
33 | cec9845c | Michael Hanselmann | |
34 | cec9845c | Michael Hanselmann | import qa_config |
35 | cec9845c | Michael Hanselmann | import qa_utils |
36 | cec9845c | Michael Hanselmann | import qa_error |
37 | cec9845c | Michael Hanselmann | |
38 | 66d1f035 | René Nussbaumer | from qa_utils import AssertEqual, AssertCommand, GetCommandOutput |
39 | cec9845c | Michael Hanselmann | |
40 | cec9845c | Michael Hanselmann | |
41 | c2a0947d | Iustin Pop | #: cluster verify command
|
42 | c2a0947d | Iustin Pop | _CLUSTER_VERIFY = ["gnt-cluster", "verify"] |
43 | c2a0947d | Iustin Pop | |
44 | 21bf2e2e | Andrea Spadaccini | |
45 | 830da270 | Michael Hanselmann | def _RemoveFileFromAllNodes(filename): |
46 | 830da270 | Michael Hanselmann | """Removes a file from all nodes.
|
47 | 830da270 | Michael Hanselmann |
|
48 | 830da270 | Michael Hanselmann | """
|
49 | 2f4b4f78 | Iustin Pop | for node in qa_config.get("nodes"): |
50 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", filename], node=node) |
51 | 830da270 | Michael Hanselmann | |
52 | 830da270 | Michael Hanselmann | |
53 | 830da270 | Michael Hanselmann | def _CheckFileOnAllNodes(filename, content): |
54 | 830da270 | Michael Hanselmann | """Verifies the content of the given file on all nodes.
|
55 | 830da270 | Michael Hanselmann |
|
56 | 830da270 | Michael Hanselmann | """
|
57 | 830da270 | Michael Hanselmann | cmd = utils.ShellQuoteArgs(["cat", filename])
|
58 | 2f4b4f78 | Iustin Pop | for node in qa_config.get("nodes"): |
59 | 2f4b4f78 | Iustin Pop | AssertEqual(qa_utils.GetCommandOutput(node["primary"], cmd), content)
|
60 | 830da270 | Michael Hanselmann | |
61 | 830da270 | Michael Hanselmann | |
62 | 92cb4940 | Andrea Spadaccini | # data for testing failures due to bad keys/values for disk parameters
|
63 | 92cb4940 | Andrea Spadaccini | _FAIL_PARAMS = ["nonexistent:resync-rate=1",
|
64 | 92cb4940 | Andrea Spadaccini | "drbd:nonexistent=1",
|
65 | 92cb4940 | Andrea Spadaccini | "drbd:resync-rate=invalid",
|
66 | 92cb4940 | Andrea Spadaccini | ] |
67 | 92cb4940 | Andrea Spadaccini | |
68 | 92cb4940 | Andrea Spadaccini | |
69 | 92cb4940 | Andrea Spadaccini | def TestClusterInitDisk(): |
70 | 92cb4940 | Andrea Spadaccini | """gnt-cluster init -D"""
|
71 | 92cb4940 | Andrea Spadaccini | name = qa_config.get("name")
|
72 | 92cb4940 | Andrea Spadaccini | for param in _FAIL_PARAMS: |
73 | 92cb4940 | Andrea Spadaccini | AssertCommand(["gnt-cluster", "init", "-D", param, name], fail=True) |
74 | 92cb4940 | Andrea Spadaccini | |
75 | 92cb4940 | Andrea Spadaccini | |
76 | 725ec2f1 | René Nussbaumer | def TestClusterInit(rapi_user, rapi_secret): |
77 | cec9845c | Michael Hanselmann | """gnt-cluster init"""
|
78 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
79 | cec9845c | Michael Hanselmann | |
80 | 304d9f02 | Michael Hanselmann | rapi_dir = os.path.dirname(pathutils.RAPI_USERS_FILE) |
81 | 49ceab21 | Michael Hanselmann | |
82 | 725ec2f1 | René Nussbaumer | # First create the RAPI credentials
|
83 | a62d1901 | Michael Hanselmann | fh = tempfile.NamedTemporaryFile() |
84 | a62d1901 | Michael Hanselmann | try:
|
85 | a62d1901 | Michael Hanselmann | fh.write("%s %s write\n" % (rapi_user, rapi_secret))
|
86 | a62d1901 | Michael Hanselmann | fh.flush() |
87 | a62d1901 | Michael Hanselmann | |
88 | a62d1901 | Michael Hanselmann | tmpru = qa_utils.UploadFile(master["primary"], fh.name)
|
89 | a62d1901 | Michael Hanselmann | try:
|
90 | 49ceab21 | Michael Hanselmann | AssertCommand(["mkdir", "-p", rapi_dir]) |
91 | 304d9f02 | Michael Hanselmann | AssertCommand(["mv", tmpru, pathutils.RAPI_USERS_FILE])
|
92 | a62d1901 | Michael Hanselmann | finally:
|
93 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", tmpru]) |
94 | a62d1901 | Michael Hanselmann | finally:
|
95 | a62d1901 | Michael Hanselmann | fh.close() |
96 | a62d1901 | Michael Hanselmann | |
97 | a62d1901 | Michael Hanselmann | # Initialize cluster
|
98 | e7b6183b | Michael Hanselmann | cmd = [ |
99 | e7b6183b | Michael Hanselmann | "gnt-cluster", "init", |
100 | e7b6183b | Michael Hanselmann | "--primary-ip-version=%d" % qa_config.get("primary_ip_version", 4), |
101 | 59c1d41e | Michael Hanselmann | "--enabled-hypervisors=%s" % ",".join(qa_config.GetEnabledHypervisors()), |
102 | e7b6183b | Michael Hanselmann | ] |
103 | 20286f7c | René Nussbaumer | |
104 | 20286f7c | René Nussbaumer | for spec_type in ("mem-size", "disk-size", "disk-count", "cpu-count", |
105 | 20286f7c | René Nussbaumer | "nic-count"):
|
106 | 20286f7c | René Nussbaumer | for spec_val in ("min", "max", "std"): |
107 | 20286f7c | René Nussbaumer | spec = qa_config.get("ispec_%s_%s" %
|
108 | 20286f7c | René Nussbaumer | (spec_type.replace('-', '_'), spec_val), None) |
109 | 20286f7c | René Nussbaumer | if spec:
|
110 | 20286f7c | René Nussbaumer | cmd.append("--specs-%s=%s=%d" % (spec_type, spec_val, spec))
|
111 | 9486f6ae | Manuel Franceschini | |
112 | d0c8c01d | Iustin Pop | if master.get("secondary", None): |
113 | d0c8c01d | Iustin Pop | cmd.append("--secondary-ip=%s" % master["secondary"]) |
114 | cec9845c | Michael Hanselmann | |
115 | d0c8c01d | Iustin Pop | bridge = qa_config.get("bridge", None) |
116 | cec9845c | Michael Hanselmann | if bridge:
|
117 | d0c8c01d | Iustin Pop | cmd.append("--bridge=%s" % bridge)
|
118 | d0c8c01d | Iustin Pop | cmd.append("--master-netdev=%s" % bridge)
|
119 | cec9845c | Michael Hanselmann | |
120 | 13d2e231 | Andrea Spadaccini | cmd.append(qa_config.get("name"))
|
121 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
122 | cec9845c | Michael Hanselmann | |
123 | 5abecc1c | Iustin Pop | cmd = ["gnt-cluster", "modify"] |
124 | 13d2e231 | Andrea Spadaccini | |
125 | 5abecc1c | Iustin Pop | # hypervisor parameter modifications
|
126 | 5abecc1c | Iustin Pop | hvp = qa_config.get("hypervisor-parameters", {})
|
127 | 5abecc1c | Iustin Pop | for k, v in hvp.items(): |
128 | 5abecc1c | Iustin Pop | cmd.extend(["-H", "%s:%s" % (k, v)]) |
129 | 5abecc1c | Iustin Pop | # backend parameter modifications
|
130 | 5abecc1c | Iustin Pop | bep = qa_config.get("backend-parameters", "") |
131 | 5abecc1c | Iustin Pop | if bep:
|
132 | 5abecc1c | Iustin Pop | cmd.extend(["-B", bep])
|
133 | 5abecc1c | Iustin Pop | |
134 | 5abecc1c | Iustin Pop | if len(cmd) > 2: |
135 | 5abecc1c | Iustin Pop | AssertCommand(cmd) |
136 | 5abecc1c | Iustin Pop | |
137 | 5abecc1c | Iustin Pop | # OS parameters
|
138 | 5abecc1c | Iustin Pop | osp = qa_config.get("os-parameters", {})
|
139 | 5abecc1c | Iustin Pop | for k, v in osp.items(): |
140 | 5abecc1c | Iustin Pop | AssertCommand(["gnt-os", "modify", "-O", v, k]) |
141 | 5abecc1c | Iustin Pop | |
142 | 5abecc1c | Iustin Pop | # OS hypervisor parameters
|
143 | 5abecc1c | Iustin Pop | os_hvp = qa_config.get("os-hvp", {})
|
144 | 5abecc1c | Iustin Pop | for os_name in os_hvp: |
145 | 5abecc1c | Iustin Pop | for hv, hvp in os_hvp[os_name].items(): |
146 | 5abecc1c | Iustin Pop | AssertCommand(["gnt-os", "modify", "-H", "%s:%s" % (hv, hvp), os_name]) |
147 | 5abecc1c | Iustin Pop | |
148 | cec9845c | Michael Hanselmann | |
149 | caea3b32 | Iustin Pop | def TestClusterRename(): |
150 | caea3b32 | Iustin Pop | """gnt-cluster rename"""
|
151 | d0c8c01d | Iustin Pop | cmd = ["gnt-cluster", "rename", "-f"] |
152 | caea3b32 | Iustin Pop | |
153 | d0c8c01d | Iustin Pop | original_name = qa_config.get("name")
|
154 | d0c8c01d | Iustin Pop | rename_target = qa_config.get("rename", None) |
155 | caea3b32 | Iustin Pop | if rename_target is None: |
156 | caea3b32 | Iustin Pop | print qa_utils.FormatError('"rename" entry is missing') |
157 | caea3b32 | Iustin Pop | return
|
158 | caea3b32 | Iustin Pop | |
159 | 2f4b4f78 | Iustin Pop | for data in [ |
160 | 2f4b4f78 | Iustin Pop | cmd + [rename_target], |
161 | c2a0947d | Iustin Pop | _CLUSTER_VERIFY, |
162 | 2f4b4f78 | Iustin Pop | cmd + [original_name], |
163 | c2a0947d | Iustin Pop | _CLUSTER_VERIFY, |
164 | 2f4b4f78 | Iustin Pop | ]: |
165 | 2f4b4f78 | Iustin Pop | AssertCommand(data) |
166 | caea3b32 | Iustin Pop | |
167 | caea3b32 | Iustin Pop | |
168 | 69df9d2b | Iustin Pop | def TestClusterOob(): |
169 | 69df9d2b | Iustin Pop | """out-of-band framework"""
|
170 | f55312bd | René Nussbaumer | oob_path_exists = "/tmp/ganeti-qa-oob-does-exist-%s" % utils.NewUUID()
|
171 | f55312bd | René Nussbaumer | |
172 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY) |
173 | f55312bd | René Nussbaumer | AssertCommand(["gnt-cluster", "modify", "--node-parameters", |
174 | f55312bd | René Nussbaumer | "oob_program=/tmp/ganeti-qa-oob-does-not-exist-%s" %
|
175 | f55312bd | René Nussbaumer | utils.NewUUID()]) |
176 | f55312bd | René Nussbaumer | |
177 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY, fail=True)
|
178 | f55312bd | René Nussbaumer | |
179 | 69df9d2b | Iustin Pop | AssertCommand(["touch", oob_path_exists])
|
180 | 69df9d2b | Iustin Pop | AssertCommand(["chmod", "0400", oob_path_exists]) |
181 | 69df9d2b | Iustin Pop | AssertCommand(["gnt-cluster", "copyfile", oob_path_exists]) |
182 | f55312bd | René Nussbaumer | |
183 | f55312bd | René Nussbaumer | try:
|
184 | f55312bd | René Nussbaumer | AssertCommand(["gnt-cluster", "modify", "--node-parameters", |
185 | f55312bd | René Nussbaumer | "oob_program=%s" % oob_path_exists])
|
186 | f55312bd | René Nussbaumer | |
187 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY, fail=True)
|
188 | f55312bd | René Nussbaumer | |
189 | 69df9d2b | Iustin Pop | AssertCommand(["chmod", "0500", oob_path_exists]) |
190 | 69df9d2b | Iustin Pop | AssertCommand(["gnt-cluster", "copyfile", oob_path_exists]) |
191 | f55312bd | René Nussbaumer | |
192 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY) |
193 | f55312bd | René Nussbaumer | finally:
|
194 | 69df9d2b | Iustin Pop | AssertCommand(["gnt-cluster", "command", "rm", oob_path_exists]) |
195 | f55312bd | René Nussbaumer | |
196 | f55312bd | René Nussbaumer | AssertCommand(["gnt-cluster", "modify", "--node-parameters", |
197 | f55312bd | René Nussbaumer | "oob_program="])
|
198 | 69df9d2b | Iustin Pop | |
199 | 69df9d2b | Iustin Pop | |
200 | 66d1f035 | René Nussbaumer | def TestClusterEpo(): |
201 | 66d1f035 | René Nussbaumer | """gnt-cluster epo"""
|
202 | 66d1f035 | René Nussbaumer | master = qa_config.GetMasterNode() |
203 | 66d1f035 | René Nussbaumer | |
204 | 66d1f035 | René Nussbaumer | # Assert that OOB is unavailable for all nodes
|
205 | 66d1f035 | René Nussbaumer | result_output = GetCommandOutput(master["primary"],
|
206 | 58ea8d17 | Michael Hanselmann | "gnt-node list --verbose --no-headers -o"
|
207 | 66d1f035 | René Nussbaumer | " powered")
|
208 | 66d1f035 | René Nussbaumer | AssertEqual(compat.all(powered == "(unavail)"
|
209 | 66d1f035 | René Nussbaumer | for powered in result_output.splitlines()), True) |
210 | 66d1f035 | René Nussbaumer | |
211 | 66d1f035 | René Nussbaumer | # Conflicting
|
212 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "--groups", "--all"], fail=True) |
213 | 66d1f035 | René Nussbaumer | # --all doesn't expect arguments
|
214 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "--all", "some_arg"], fail=True) |
215 | 66d1f035 | René Nussbaumer | |
216 | 66d1f035 | René Nussbaumer | # Unless --all is given master is not allowed to be in the list
|
217 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "-f", master["primary"]], fail=True) |
218 | 66d1f035 | René Nussbaumer | |
219 | 66d1f035 | René Nussbaumer | # This shouldn't fail
|
220 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "-f", "--all"]) |
221 | 66d1f035 | René Nussbaumer | |
222 | 66d1f035 | René Nussbaumer | # All instances should have been stopped now
|
223 | 66d1f035 | René Nussbaumer | result_output = GetCommandOutput(master["primary"],
|
224 | 58ea8d17 | Michael Hanselmann | "gnt-instance list --no-headers -o status")
|
225 | 3e0ed18c | René Nussbaumer | # ERROR_down because the instance is stopped but not recorded as such
|
226 | 3e0ed18c | René Nussbaumer | AssertEqual(compat.all(status == "ERROR_down"
|
227 | 66d1f035 | René Nussbaumer | for status in result_output.splitlines()), True) |
228 | 66d1f035 | René Nussbaumer | |
229 | 66d1f035 | René Nussbaumer | # Now start everything again
|
230 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "--on", "-f", "--all"]) |
231 | 66d1f035 | René Nussbaumer | |
232 | 66d1f035 | René Nussbaumer | # All instances should have been started now
|
233 | 66d1f035 | René Nussbaumer | result_output = GetCommandOutput(master["primary"],
|
234 | 58ea8d17 | Michael Hanselmann | "gnt-instance list --no-headers -o status")
|
235 | 66d1f035 | René Nussbaumer | AssertEqual(compat.all(status == "running"
|
236 | 66d1f035 | René Nussbaumer | for status in result_output.splitlines()), True) |
237 | 66d1f035 | René Nussbaumer | |
238 | 66d1f035 | René Nussbaumer | |
239 | 69df9d2b | Iustin Pop | def TestClusterVerify(): |
240 | 69df9d2b | Iustin Pop | """gnt-cluster verify"""
|
241 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY) |
242 | c6953b6e | Iustin Pop | AssertCommand(["gnt-cluster", "verify-disks"]) |
243 | cec9845c | Michael Hanselmann | |
244 | 1377433b | Michael Hanselmann | |
245 | 1377433b | Michael Hanselmann | def TestJobqueue(): |
246 | 1377433b | Michael Hanselmann | """gnt-debug test-jobqueue"""
|
247 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-debug", "test-jobqueue"]) |
248 | 1377433b | Michael Hanselmann | |
249 | 1377433b | Michael Hanselmann | |
250 | 5a85b99e | Michael Hanselmann | def TestDelay(node): |
251 | 5a85b99e | Michael Hanselmann | """gnt-debug delay"""
|
252 | 5a85b99e | Michael Hanselmann | AssertCommand(["gnt-debug", "delay", "1"]) |
253 | 5a85b99e | Michael Hanselmann | AssertCommand(["gnt-debug", "delay", "--no-master", "1"]) |
254 | 5a85b99e | Michael Hanselmann | AssertCommand(["gnt-debug", "delay", "--no-master", |
255 | 5a85b99e | Michael Hanselmann | "-n", node["primary"], "1"]) |
256 | 5a85b99e | Michael Hanselmann | |
257 | 5a85b99e | Michael Hanselmann | |
258 | 452913ed | Iustin Pop | def TestClusterReservedLvs(): |
259 | 452913ed | Iustin Pop | """gnt-cluster reserved lvs"""
|
260 | 2f4b4f78 | Iustin Pop | for fail, cmd in [ |
261 | c2a0947d | Iustin Pop | (False, _CLUSTER_VERIFY),
|
262 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "--reserved-lvs", ""]), |
263 | 2f4b4f78 | Iustin Pop | (False, ["lvcreate", "-L1G", "-nqa-test", "xenvg"]), |
264 | 21bf2e2e | Andrea Spadaccini | (True, _CLUSTER_VERIFY),
|
265 | 84d7e26b | Dmitry Chernyak | (False, ["gnt-cluster", "modify", "--reserved-lvs", |
266 | 84d7e26b | Dmitry Chernyak | "xenvg/qa-test,.*/other-test"]),
|
267 | c2a0947d | Iustin Pop | (False, _CLUSTER_VERIFY),
|
268 | 84d7e26b | Dmitry Chernyak | (False, ["gnt-cluster", "modify", "--reserved-lvs", ".*/qa-.*"]), |
269 | c2a0947d | Iustin Pop | (False, _CLUSTER_VERIFY),
|
270 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "--reserved-lvs", ""]), |
271 | 21bf2e2e | Andrea Spadaccini | (True, _CLUSTER_VERIFY),
|
272 | 2f4b4f78 | Iustin Pop | (False, ["lvremove", "-f", "xenvg/qa-test"]), |
273 | c2a0947d | Iustin Pop | (False, _CLUSTER_VERIFY),
|
274 | 452913ed | Iustin Pop | ]: |
275 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, fail=fail) |
276 | 452913ed | Iustin Pop | |
277 | cec9845c | Michael Hanselmann | |
278 | 1e7acc3b | Iustin Pop | def TestClusterModifyEmpty(): |
279 | 1e7acc3b | Iustin Pop | """gnt-cluster modify"""
|
280 | 1e7acc3b | Iustin Pop | AssertCommand(["gnt-cluster", "modify"], fail=True) |
281 | 1e7acc3b | Iustin Pop | |
282 | 1e7acc3b | Iustin Pop | |
283 | 92cb4940 | Andrea Spadaccini | def TestClusterModifyDisk(): |
284 | 92cb4940 | Andrea Spadaccini | """gnt-cluster modify -D"""
|
285 | 92cb4940 | Andrea Spadaccini | for param in _FAIL_PARAMS: |
286 | 92cb4940 | Andrea Spadaccini | AssertCommand(["gnt-cluster", "modify", "-D", param], fail=True) |
287 | 92cb4940 | Andrea Spadaccini | |
288 | 92cb4940 | Andrea Spadaccini | |
289 | 9738ca94 | Iustin Pop | def TestClusterModifyBe(): |
290 | 9738ca94 | Iustin Pop | """gnt-cluster modify -B"""
|
291 | 2f4b4f78 | Iustin Pop | for fail, cmd in [ |
292 | 8ccbbe4b | Guido Trotter | # max/min mem
|
293 | 8ccbbe4b | Guido Trotter | (False, ["gnt-cluster", "modify", "-B", "maxmem=256"]), |
294 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *maxmem: 256$'"]), |
295 | 8ccbbe4b | Guido Trotter | (False, ["gnt-cluster", "modify", "-B", "minmem=256"]), |
296 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *minmem: 256$'"]), |
297 | 8ccbbe4b | Guido Trotter | (True, ["gnt-cluster", "modify", "-B", "maxmem=a"]), |
298 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *maxmem: 256$'"]), |
299 | 8ccbbe4b | Guido Trotter | (True, ["gnt-cluster", "modify", "-B", "minmem=a"]), |
300 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *minmem: 256$'"]), |
301 | 8ccbbe4b | Guido Trotter | (False, ["gnt-cluster", "modify", "-B", "maxmem=128,minmem=128"]), |
302 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *maxmem: 128$'"]), |
303 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *minmem: 128$'"]), |
304 | 9738ca94 | Iustin Pop | # vcpus
|
305 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "-B", "vcpus=4"]), |
306 | 2f4b4f78 | Iustin Pop | (False, ["sh", "-c", "gnt-cluster info|grep '^ *vcpus: 4$'"]), |
307 | 21bf2e2e | Andrea Spadaccini | (True, ["gnt-cluster", "modify", "-B", "vcpus=a"]), |
308 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "-B", "vcpus=1"]), |
309 | 2f4b4f78 | Iustin Pop | (False, ["sh", "-c", "gnt-cluster info|grep '^ *vcpus: 1$'"]), |
310 | 9738ca94 | Iustin Pop | # auto_balance
|
311 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "-B", "auto_balance=False"]), |
312 | 2f4b4f78 | Iustin Pop | (False, ["sh", "-c", "gnt-cluster info|grep '^ *auto_balance: False$'"]), |
313 | 21bf2e2e | Andrea Spadaccini | (True, ["gnt-cluster", "modify", "-B", "auto_balance=1"]), |
314 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "-B", "auto_balance=True"]), |
315 | 2f4b4f78 | Iustin Pop | (False, ["sh", "-c", "gnt-cluster info|grep '^ *auto_balance: True$'"]), |
316 | 9738ca94 | Iustin Pop | ]: |
317 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, fail=fail) |
318 | 9738ca94 | Iustin Pop | |
319 | 5abecc1c | Iustin Pop | # redo the original-requested BE parameters, if any
|
320 | 5abecc1c | Iustin Pop | bep = qa_config.get("backend-parameters", "") |
321 | 5abecc1c | Iustin Pop | if bep:
|
322 | 5abecc1c | Iustin Pop | AssertCommand(["gnt-cluster", "modify", "-B", bep]) |
323 | 9738ca94 | Iustin Pop | |
324 | 21bf2e2e | Andrea Spadaccini | |
325 | cec9845c | Michael Hanselmann | def TestClusterInfo(): |
326 | cec9845c | Michael Hanselmann | """gnt-cluster info"""
|
327 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "info"]) |
328 | 283f9d4c | Michael Hanselmann | |
329 | 283f9d4c | Michael Hanselmann | |
330 | 3e8b5a9c | Iustin Pop | def TestClusterRedistConf(): |
331 | 3e8b5a9c | Iustin Pop | """gnt-cluster redist-conf"""
|
332 | 3e8b5a9c | Iustin Pop | AssertCommand(["gnt-cluster", "redist-conf"]) |
333 | 3e8b5a9c | Iustin Pop | |
334 | 3e8b5a9c | Iustin Pop | |
335 | 283f9d4c | Michael Hanselmann | def TestClusterGetmaster(): |
336 | 283f9d4c | Michael Hanselmann | """gnt-cluster getmaster"""
|
337 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "getmaster"]) |
338 | 283f9d4c | Michael Hanselmann | |
339 | 283f9d4c | Michael Hanselmann | |
340 | 283f9d4c | Michael Hanselmann | def TestClusterVersion(): |
341 | 283f9d4c | Michael Hanselmann | """gnt-cluster version"""
|
342 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "version"]) |
343 | cec9845c | Michael Hanselmann | |
344 | cec9845c | Michael Hanselmann | |
345 | 6d4a1656 | Michael Hanselmann | def TestClusterRenewCrypto(): |
346 | 6d4a1656 | Michael Hanselmann | """gnt-cluster renew-crypto"""
|
347 | 6d4a1656 | Michael Hanselmann | master = qa_config.GetMasterNode() |
348 | 6d4a1656 | Michael Hanselmann | |
349 | 6d4a1656 | Michael Hanselmann | # Conflicting options
|
350 | 6d4a1656 | Michael Hanselmann | cmd = ["gnt-cluster", "renew-crypto", "--force", |
351 | 3db3eb2a | Michael Hanselmann | "--new-cluster-certificate", "--new-confd-hmac-key"] |
352 | 3db3eb2a | Michael Hanselmann | conflicting = [ |
353 | 3db3eb2a | Michael Hanselmann | ["--new-rapi-certificate", "--rapi-certificate=/dev/null"], |
354 | 3db3eb2a | Michael Hanselmann | ["--new-cluster-domain-secret", "--cluster-domain-secret=/dev/null"], |
355 | 3db3eb2a | Michael Hanselmann | ] |
356 | 3db3eb2a | Michael Hanselmann | for i in conflicting: |
357 | 21bf2e2e | Andrea Spadaccini | AssertCommand(cmd + i, fail=True)
|
358 | 6d4a1656 | Michael Hanselmann | |
359 | 6d4a1656 | Michael Hanselmann | # Invalid RAPI certificate
|
360 | 6d4a1656 | Michael Hanselmann | cmd = ["gnt-cluster", "renew-crypto", "--force", |
361 | 6d4a1656 | Michael Hanselmann | "--rapi-certificate=/dev/null"]
|
362 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, fail=True)
|
363 | 6d4a1656 | Michael Hanselmann | |
364 | 502f5236 | Michael Hanselmann | rapi_cert_backup = qa_utils.BackupFile(master["primary"],
|
365 | 304d9f02 | Michael Hanselmann | pathutils.RAPI_CERT_FILE) |
366 | 502f5236 | Michael Hanselmann | try:
|
367 | 502f5236 | Michael Hanselmann | # Custom RAPI certificate
|
368 | 502f5236 | Michael Hanselmann | fh = tempfile.NamedTemporaryFile() |
369 | 6d4a1656 | Michael Hanselmann | |
370 | 502f5236 | Michael Hanselmann | # Ensure certificate doesn't cause "gnt-cluster verify" to complain
|
371 | 502f5236 | Michael Hanselmann | validity = constants.SSL_CERT_EXPIRATION_WARN * 3
|
372 | 6d4a1656 | Michael Hanselmann | |
373 | 5e26633b | Michael Hanselmann | utils.GenerateSelfSignedSslCert(fh.name, validity=validity) |
374 | 6d4a1656 | Michael Hanselmann | |
375 | 502f5236 | Michael Hanselmann | tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
|
376 | 502f5236 | Michael Hanselmann | try:
|
377 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
378 | 2f4b4f78 | Iustin Pop | "--rapi-certificate=%s" % tmpcert])
|
379 | 502f5236 | Michael Hanselmann | finally:
|
380 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", tmpcert]) |
381 | 502f5236 | Michael Hanselmann | |
382 | 5e26633b | Michael Hanselmann | # Custom cluster domain secret
|
383 | 5e26633b | Michael Hanselmann | cds_fh = tempfile.NamedTemporaryFile() |
384 | 5e26633b | Michael Hanselmann | cds_fh.write(utils.GenerateSecret()) |
385 | 5e26633b | Michael Hanselmann | cds_fh.write("\n")
|
386 | 5e26633b | Michael Hanselmann | cds_fh.flush() |
387 | 5e26633b | Michael Hanselmann | |
388 | 5e26633b | Michael Hanselmann | tmpcds = qa_utils.UploadFile(master["primary"], cds_fh.name)
|
389 | 5e26633b | Michael Hanselmann | try:
|
390 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
391 | 2f4b4f78 | Iustin Pop | "--cluster-domain-secret=%s" % tmpcds])
|
392 | 5e26633b | Michael Hanselmann | finally:
|
393 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", tmpcds]) |
394 | 5e26633b | Michael Hanselmann | |
395 | 502f5236 | Michael Hanselmann | # Normal case
|
396 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
397 | 2f4b4f78 | Iustin Pop | "--new-cluster-certificate", "--new-confd-hmac-key", |
398 | 2f4b4f78 | Iustin Pop | "--new-rapi-certificate", "--new-cluster-domain-secret"]) |
399 | 3db3eb2a | Michael Hanselmann | |
400 | 502f5236 | Michael Hanselmann | # Restore RAPI certificate
|
401 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
402 | 2f4b4f78 | Iustin Pop | "--rapi-certificate=%s" % rapi_cert_backup])
|
403 | 3db3eb2a | Michael Hanselmann | finally:
|
404 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", rapi_cert_backup]) |
405 | 3db3eb2a | Michael Hanselmann | |
406 | 6d4a1656 | Michael Hanselmann | |
407 | cec9845c | Michael Hanselmann | def TestClusterBurnin(): |
408 | cec9845c | Michael Hanselmann | """Burnin"""
|
409 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
410 | cec9845c | Michael Hanselmann | |
411 | d0c8c01d | Iustin Pop | options = qa_config.get("options", {})
|
412 | d0c8c01d | Iustin Pop | disk_template = options.get("burnin-disk-template", "drbd") |
413 | d0c8c01d | Iustin Pop | parallel = options.get("burnin-in-parallel", False) |
414 | d0c8c01d | Iustin Pop | check_inst = options.get("burnin-check-instances", False) |
415 | d0c8c01d | Iustin Pop | do_rename = options.get("burnin-rename", "") |
416 | d0c8c01d | Iustin Pop | do_reboot = options.get("burnin-reboot", True) |
417 | 1d103c02 | Iustin Pop | reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
|
418 | 23103544 | Michael Hanselmann | |
419 | cec9845c | Michael Hanselmann | # Get as many instances as we need
|
420 | cec9845c | Michael Hanselmann | instances = [] |
421 | cec9845c | Michael Hanselmann | try:
|
422 | 23103544 | Michael Hanselmann | try:
|
423 | d0c8c01d | Iustin Pop | num = qa_config.get("options", {}).get("burnin-instances", 1) |
424 | f1501b3f | Michael Hanselmann | for _ in range(0, num): |
425 | 23103544 | Michael Hanselmann | instances.append(qa_config.AcquireInstance()) |
426 | 23103544 | Michael Hanselmann | except qa_error.OutOfInstancesError:
|
427 | 23103544 | Michael Hanselmann | print "Not enough instances, continuing anyway." |
428 | cec9845c | Michael Hanselmann | |
429 | 23103544 | Michael Hanselmann | if len(instances) < 1: |
430 | 23103544 | Michael Hanselmann | raise qa_error.Error("Burnin needs at least one instance") |
431 | cec9845c | Michael Hanselmann | |
432 | d0c8c01d | Iustin Pop | script = qa_utils.UploadFile(master["primary"], "../tools/burnin") |
433 | cec9845c | Michael Hanselmann | try:
|
434 | 23103544 | Michael Hanselmann | # Run burnin
|
435 | cec9845c | Michael Hanselmann | cmd = [script, |
436 | d0c8c01d | Iustin Pop | "--os=%s" % qa_config.get("os"), |
437 | f356202a | Guido Trotter | "--minmem-size=%s" % qa_config.get(constants.BE_MINMEM),
|
438 | f356202a | Guido Trotter | "--maxmem-size=%s" % qa_config.get(constants.BE_MAXMEM),
|
439 | d0c8c01d | Iustin Pop | "--disk-size=%s" % ",".join(qa_config.get("disk")), |
440 | d0c8c01d | Iustin Pop | "--disk-growth=%s" % ",".join(qa_config.get("disk-growth")), |
441 | d0c8c01d | Iustin Pop | "--disk-template=%s" % disk_template]
|
442 | 0b0a150a | Iustin Pop | if parallel:
|
443 | d0c8c01d | Iustin Pop | cmd.append("--parallel")
|
444 | d0c8c01d | Iustin Pop | cmd.append("--early-release")
|
445 | 0b0a150a | Iustin Pop | if check_inst:
|
446 | d0c8c01d | Iustin Pop | cmd.append("--http-check")
|
447 | 4dc76b24 | Iustin Pop | if do_rename:
|
448 | d0c8c01d | Iustin Pop | cmd.append("--rename=%s" % do_rename)
|
449 | 58598264 | Iustin Pop | if not do_reboot: |
450 | d0c8c01d | Iustin Pop | cmd.append("--no-reboot")
|
451 | 1d103c02 | Iustin Pop | else:
|
452 | d0c8c01d | Iustin Pop | cmd.append("--reboot-types=%s" % ",".join(reboot_types)) |
453 | d0c8c01d | Iustin Pop | cmd += [inst["name"] for inst in instances] |
454 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
455 | cec9845c | Michael Hanselmann | finally:
|
456 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", script]) |
457 | 2f4b4f78 | Iustin Pop | |
458 | cec9845c | Michael Hanselmann | finally:
|
459 | cec9845c | Michael Hanselmann | for inst in instances: |
460 | cec9845c | Michael Hanselmann | qa_config.ReleaseInstance(inst) |
461 | cec9845c | Michael Hanselmann | |
462 | cec9845c | Michael Hanselmann | |
463 | cec9845c | Michael Hanselmann | def TestClusterMasterFailover(): |
464 | c28502b1 | Iustin Pop | """gnt-cluster master-failover"""
|
465 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
466 | cec9845c | Michael Hanselmann | failovermaster = qa_config.AcquireNode(exclude=master) |
467 | cec9845c | Michael Hanselmann | |
468 | 2f4b4f78 | Iustin Pop | cmd = ["gnt-cluster", "master-failover"] |
469 | 2f4b4f78 | Iustin Pop | try:
|
470 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, node=failovermaster) |
471 | ff699aa9 | Michael Hanselmann | # Back to original master node
|
472 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, node=master) |
473 | cec9845c | Michael Hanselmann | finally:
|
474 | cec9845c | Michael Hanselmann | qa_config.ReleaseNode(failovermaster) |
475 | cec9845c | Michael Hanselmann | |
476 | cec9845c | Michael Hanselmann | |
477 | ff699aa9 | Michael Hanselmann | def TestClusterMasterFailoverWithDrainedQueue(): |
478 | ff699aa9 | Michael Hanselmann | """gnt-cluster master-failover with drained queue"""
|
479 | 304d9f02 | Michael Hanselmann | drain_check = ["test", "-f", pathutils.JOB_QUEUE_DRAIN_FILE] |
480 | ff699aa9 | Michael Hanselmann | |
481 | ff699aa9 | Michael Hanselmann | master = qa_config.GetMasterNode() |
482 | ff699aa9 | Michael Hanselmann | failovermaster = qa_config.AcquireNode(exclude=master) |
483 | ff699aa9 | Michael Hanselmann | |
484 | ff699aa9 | Michael Hanselmann | # Ensure queue is not drained
|
485 | ff699aa9 | Michael Hanselmann | for node in [master, failovermaster]: |
486 | ff699aa9 | Michael Hanselmann | AssertCommand(drain_check, node=node, fail=True)
|
487 | ff699aa9 | Michael Hanselmann | |
488 | ff699aa9 | Michael Hanselmann | # Drain queue on failover master
|
489 | 304d9f02 | Michael Hanselmann | AssertCommand(["touch", pathutils.JOB_QUEUE_DRAIN_FILE], node=failovermaster)
|
490 | ff699aa9 | Michael Hanselmann | |
491 | ff699aa9 | Michael Hanselmann | cmd = ["gnt-cluster", "master-failover"] |
492 | ff699aa9 | Michael Hanselmann | try:
|
493 | ff699aa9 | Michael Hanselmann | AssertCommand(drain_check, node=failovermaster) |
494 | ff699aa9 | Michael Hanselmann | AssertCommand(cmd, node=failovermaster) |
495 | ff699aa9 | Michael Hanselmann | AssertCommand(drain_check, fail=True)
|
496 | ff699aa9 | Michael Hanselmann | AssertCommand(drain_check, node=failovermaster, fail=True)
|
497 | ff699aa9 | Michael Hanselmann | |
498 | ff699aa9 | Michael Hanselmann | # Back to original master node
|
499 | ff699aa9 | Michael Hanselmann | AssertCommand(cmd, node=master) |
500 | ff699aa9 | Michael Hanselmann | finally:
|
501 | ff699aa9 | Michael Hanselmann | qa_config.ReleaseNode(failovermaster) |
502 | ff699aa9 | Michael Hanselmann | |
503 | ff699aa9 | Michael Hanselmann | AssertCommand(drain_check, fail=True)
|
504 | ff699aa9 | Michael Hanselmann | AssertCommand(drain_check, node=failovermaster, fail=True)
|
505 | ff699aa9 | Michael Hanselmann | |
506 | ff699aa9 | Michael Hanselmann | |
507 | cec9845c | Michael Hanselmann | def TestClusterCopyfile(): |
508 | cec9845c | Michael Hanselmann | """gnt-cluster copyfile"""
|
509 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
510 | cec9845c | Michael Hanselmann | |
511 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
512 | 830da270 | Michael Hanselmann | |
513 | cec9845c | Michael Hanselmann | # Create temporary file
|
514 | cec9845c | Michael Hanselmann | f = tempfile.NamedTemporaryFile() |
515 | 830da270 | Michael Hanselmann | f.write(uniqueid) |
516 | cec9845c | Michael Hanselmann | f.flush() |
517 | cec9845c | Michael Hanselmann | f.seek(0)
|
518 | cec9845c | Michael Hanselmann | |
519 | cec9845c | Michael Hanselmann | # Upload file to master node
|
520 | d0c8c01d | Iustin Pop | testname = qa_utils.UploadFile(master["primary"], f.name)
|
521 | cec9845c | Michael Hanselmann | try:
|
522 | cec9845c | Michael Hanselmann | # Copy file to all nodes
|
523 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "copyfile", testname]) |
524 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(testname, uniqueid) |
525 | cec9845c | Michael Hanselmann | finally:
|
526 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(testname) |
527 | 830da270 | Michael Hanselmann | |
528 | 830da270 | Michael Hanselmann | |
529 | 830da270 | Michael Hanselmann | def TestClusterCommand(): |
530 | 830da270 | Michael Hanselmann | """gnt-cluster command"""
|
531 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
532 | 24818e8f | Michael Hanselmann | rfile = "/tmp/gnt%s" % utils.NewUUID()
|
533 | d0c8c01d | Iustin Pop | rcmd = utils.ShellQuoteArgs(["echo", "-n", uniqueid]) |
534 | d0c8c01d | Iustin Pop | cmd = utils.ShellQuoteArgs(["gnt-cluster", "command", |
535 | 830da270 | Michael Hanselmann | "%s >%s" % (rcmd, rfile)])
|
536 | 830da270 | Michael Hanselmann | |
537 | 830da270 | Michael Hanselmann | try:
|
538 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
539 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(rfile, uniqueid) |
540 | 830da270 | Michael Hanselmann | finally:
|
541 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(rfile) |
542 | cec9845c | Michael Hanselmann | |
543 | cec9845c | Michael Hanselmann | |
544 | cec9845c | Michael Hanselmann | def TestClusterDestroy(): |
545 | cec9845c | Michael Hanselmann | """gnt-cluster destroy"""
|
546 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "destroy", "--yes-do-it"]) |
547 | 65a884ef | Iustin Pop | |
548 | 65a884ef | Iustin Pop | |
549 | 65a884ef | Iustin Pop | def TestClusterRepairDiskSizes(): |
550 | 65a884ef | Iustin Pop | """gnt-cluster repair-disk-sizes"""
|
551 | 65a884ef | Iustin Pop | AssertCommand(["gnt-cluster", "repair-disk-sizes"]) |