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