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