root / qa / qa_cluster.py @ 2129c5ff
History | View | Annotate | Download (43.7 kB)
1 | c68d1f43 | Michael Hanselmann | #
|
---|---|---|---|
2 | c68d1f43 | Michael Hanselmann | #
|
3 | c68d1f43 | Michael Hanselmann | |
4 | 587f8ff6 | Bernardo Dal Seno | # Copyright (C) 2007, 2010, 2011, 2012, 2013 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 | 587f8ff6 | Bernardo Dal Seno | import re |
27 | cec9845c | Michael Hanselmann | import tempfile |
28 | 49ceab21 | Michael Hanselmann | import os.path |
29 | cec9845c | Michael Hanselmann | |
30 | b8669a69 | Jose A. Lopes | from ganeti import _constants |
31 | 6d4a1656 | Michael Hanselmann | from ganeti import constants |
32 | 66d1f035 | René Nussbaumer | from ganeti import compat |
33 | cec9845c | Michael Hanselmann | from ganeti import utils |
34 | 304d9f02 | Michael Hanselmann | from ganeti import pathutils |
35 | cec9845c | Michael Hanselmann | |
36 | cec9845c | Michael Hanselmann | import qa_config |
37 | e4889779 | Thomas Thrainer | import qa_daemon |
38 | cec9845c | Michael Hanselmann | import qa_utils |
39 | cec9845c | Michael Hanselmann | import qa_error |
40 | 462f0faa | Helga Velroyen | import qa_instance |
41 | cec9845c | Michael Hanselmann | |
42 | 66d1f035 | René Nussbaumer | from qa_utils import AssertEqual, AssertCommand, GetCommandOutput |
43 | cec9845c | Michael Hanselmann | |
44 | cec9845c | Michael Hanselmann | |
45 | 23610ff8 | Bernardo Dal Seno | # Prefix for LVM volumes created by QA code during tests
|
46 | 23610ff8 | Bernardo Dal Seno | _QA_LV_PREFIX = "qa-"
|
47 | 23610ff8 | Bernardo Dal Seno | |
48 | c2a0947d | Iustin Pop | #: cluster verify command
|
49 | c2a0947d | Iustin Pop | _CLUSTER_VERIFY = ["gnt-cluster", "verify"] |
50 | c2a0947d | Iustin Pop | |
51 | 21bf2e2e | Andrea Spadaccini | |
52 | 830da270 | Michael Hanselmann | def _RemoveFileFromAllNodes(filename): |
53 | 830da270 | Michael Hanselmann | """Removes a file from all nodes.
|
54 | 830da270 | Michael Hanselmann |
|
55 | 830da270 | Michael Hanselmann | """
|
56 | 2f4b4f78 | Iustin Pop | for node in qa_config.get("nodes"): |
57 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", filename], node=node) |
58 | 830da270 | Michael Hanselmann | |
59 | 830da270 | Michael Hanselmann | |
60 | 830da270 | Michael Hanselmann | def _CheckFileOnAllNodes(filename, content): |
61 | 830da270 | Michael Hanselmann | """Verifies the content of the given file on all nodes.
|
62 | 830da270 | Michael Hanselmann |
|
63 | 830da270 | Michael Hanselmann | """
|
64 | 830da270 | Michael Hanselmann | cmd = utils.ShellQuoteArgs(["cat", filename])
|
65 | 2f4b4f78 | Iustin Pop | for node in qa_config.get("nodes"): |
66 | aecba21e | Michael Hanselmann | AssertEqual(qa_utils.GetCommandOutput(node.primary, cmd), content) |
67 | 830da270 | Michael Hanselmann | |
68 | 830da270 | Michael Hanselmann | |
69 | 0e79564a | Bernardo Dal Seno | def _GetClusterField(field_path): |
70 | 0e79564a | Bernardo Dal Seno | """Get the value of a cluster field.
|
71 | 17cfeee9 | Bernardo Dal Seno |
|
72 | 0e79564a | Bernardo Dal Seno | @type field_path: list of strings
|
73 | 0e79564a | Bernardo Dal Seno | @param field_path: Names of the groups/fields to navigate to get the desired
|
74 | 0e79564a | Bernardo Dal Seno | value, e.g. C{["Default node parameters", "oob_program"]}
|
75 | 0e79564a | Bernardo Dal Seno | @return: The effective value of the field (the actual type depends on the
|
76 | 0e79564a | Bernardo Dal Seno | chosen field)
|
77 | 17cfeee9 | Bernardo Dal Seno |
|
78 | 17cfeee9 | Bernardo Dal Seno | """
|
79 | 0e79564a | Bernardo Dal Seno | assert isinstance(field_path, list) |
80 | 0e79564a | Bernardo Dal Seno | assert field_path
|
81 | 0e79564a | Bernardo Dal Seno | ret = qa_utils.GetObjectInfo(["gnt-cluster", "info"]) |
82 | 0e79564a | Bernardo Dal Seno | for key in field_path: |
83 | 0e79564a | Bernardo Dal Seno | ret = ret[key] |
84 | 0e79564a | Bernardo Dal Seno | return ret
|
85 | 17cfeee9 | Bernardo Dal Seno | |
86 | 17cfeee9 | Bernardo Dal Seno | |
87 | 587f8ff6 | Bernardo Dal Seno | # Cluster-verify errors (date, "ERROR", then error code)
|
88 | ab4832d1 | Bernardo Dal Seno | _CVERROR_RE = re.compile(r"^[\w\s:]+\s+- (ERROR|WARNING):([A-Z0-9_-]+):")
|
89 | 587f8ff6 | Bernardo Dal Seno | |
90 | 587f8ff6 | Bernardo Dal Seno | |
91 | 587f8ff6 | Bernardo Dal Seno | def _GetCVErrorCodes(cvout): |
92 | ab4832d1 | Bernardo Dal Seno | errs = set()
|
93 | ab4832d1 | Bernardo Dal Seno | warns = set()
|
94 | 587f8ff6 | Bernardo Dal Seno | for l in cvout.splitlines(): |
95 | 587f8ff6 | Bernardo Dal Seno | m = _CVERROR_RE.match(l) |
96 | 587f8ff6 | Bernardo Dal Seno | if m:
|
97 | ab4832d1 | Bernardo Dal Seno | etype = m.group(1)
|
98 | ab4832d1 | Bernardo Dal Seno | ecode = m.group(2)
|
99 | ab4832d1 | Bernardo Dal Seno | if etype == "ERROR": |
100 | ab4832d1 | Bernardo Dal Seno | errs.add(ecode) |
101 | ab4832d1 | Bernardo Dal Seno | elif etype == "WARNING": |
102 | ab4832d1 | Bernardo Dal Seno | warns.add(ecode) |
103 | ab4832d1 | Bernardo Dal Seno | return (errs, warns)
|
104 | 587f8ff6 | Bernardo Dal Seno | |
105 | 587f8ff6 | Bernardo Dal Seno | |
106 | ab4832d1 | Bernardo Dal Seno | def _CheckVerifyErrors(actual, expected, etype): |
107 | ab4832d1 | Bernardo Dal Seno | exp_codes = compat.UniqueFrozenset(e for (_, e, _) in expected) |
108 | ab4832d1 | Bernardo Dal Seno | if not actual.issuperset(exp_codes): |
109 | ab4832d1 | Bernardo Dal Seno | missing = exp_codes.difference(actual) |
110 | ab4832d1 | Bernardo Dal Seno | raise qa_error.Error("Cluster-verify didn't return these expected" |
111 | ab4832d1 | Bernardo Dal Seno | " %ss: %s" % (etype, utils.CommaJoin(missing)))
|
112 | ab4832d1 | Bernardo Dal Seno | |
113 | ab4832d1 | Bernardo Dal Seno | |
114 | ab4832d1 | Bernardo Dal Seno | def AssertClusterVerify(fail=False, errors=None, warnings=None): |
115 | 587f8ff6 | Bernardo Dal Seno | """Run cluster-verify and check the result
|
116 | 587f8ff6 | Bernardo Dal Seno |
|
117 | 587f8ff6 | Bernardo Dal Seno | @type fail: bool
|
118 | 587f8ff6 | Bernardo Dal Seno | @param fail: if cluster-verify is expected to fail instead of succeeding
|
119 | 587f8ff6 | Bernardo Dal Seno | @type errors: list of tuples
|
120 | 587f8ff6 | Bernardo Dal Seno | @param errors: List of CV_XXX errors that are expected; if specified, all the
|
121 | 587f8ff6 | Bernardo Dal Seno | errors listed must appear in cluster-verify output. A non-empty value
|
122 | 587f8ff6 | Bernardo Dal Seno | implies C{fail=True}.
|
123 | ab4832d1 | Bernardo Dal Seno | @type warnings: list of tuples
|
124 | ab4832d1 | Bernardo Dal Seno | @param warnings: Same as C{errors} but for warnings.
|
125 | 587f8ff6 | Bernardo Dal Seno |
|
126 | 587f8ff6 | Bernardo Dal Seno | """
|
127 | 587f8ff6 | Bernardo Dal Seno | cvcmd = "gnt-cluster verify"
|
128 | 587f8ff6 | Bernardo Dal Seno | mnode = qa_config.GetMasterNode() |
129 | ab4832d1 | Bernardo Dal Seno | if errors or warnings: |
130 | aecba21e | Michael Hanselmann | cvout = GetCommandOutput(mnode.primary, cvcmd + " --error-codes",
|
131 | ab4832d1 | Bernardo Dal Seno | fail=(fail or errors))
|
132 | ab4832d1 | Bernardo Dal Seno | (act_errs, act_warns) = _GetCVErrorCodes(cvout) |
133 | ab4832d1 | Bernardo Dal Seno | if errors:
|
134 | ab4832d1 | Bernardo Dal Seno | _CheckVerifyErrors(act_errs, errors, "error")
|
135 | ab4832d1 | Bernardo Dal Seno | if warnings:
|
136 | ab4832d1 | Bernardo Dal Seno | _CheckVerifyErrors(act_warns, warnings, "warning")
|
137 | 587f8ff6 | Bernardo Dal Seno | else:
|
138 | 587f8ff6 | Bernardo Dal Seno | AssertCommand(cvcmd, fail=fail, node=mnode) |
139 | 587f8ff6 | Bernardo Dal Seno | |
140 | 587f8ff6 | Bernardo Dal Seno | |
141 | 92cb4940 | Andrea Spadaccini | # data for testing failures due to bad keys/values for disk parameters
|
142 | 92cb4940 | Andrea Spadaccini | _FAIL_PARAMS = ["nonexistent:resync-rate=1",
|
143 | 92cb4940 | Andrea Spadaccini | "drbd:nonexistent=1",
|
144 | 92cb4940 | Andrea Spadaccini | "drbd:resync-rate=invalid",
|
145 | 92cb4940 | Andrea Spadaccini | ] |
146 | 92cb4940 | Andrea Spadaccini | |
147 | 92cb4940 | Andrea Spadaccini | |
148 | 92cb4940 | Andrea Spadaccini | def TestClusterInitDisk(): |
149 | 92cb4940 | Andrea Spadaccini | """gnt-cluster init -D"""
|
150 | 92cb4940 | Andrea Spadaccini | name = qa_config.get("name")
|
151 | 92cb4940 | Andrea Spadaccini | for param in _FAIL_PARAMS: |
152 | 92cb4940 | Andrea Spadaccini | AssertCommand(["gnt-cluster", "init", "-D", param, name], fail=True) |
153 | 92cb4940 | Andrea Spadaccini | |
154 | 92cb4940 | Andrea Spadaccini | |
155 | 725ec2f1 | René Nussbaumer | def TestClusterInit(rapi_user, rapi_secret): |
156 | cec9845c | Michael Hanselmann | """gnt-cluster init"""
|
157 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
158 | cec9845c | Michael Hanselmann | |
159 | 734fd6b4 | Michael Hanselmann | rapi_users_path = qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE) |
160 | 734fd6b4 | Michael Hanselmann | rapi_dir = os.path.dirname(rapi_users_path) |
161 | 49ceab21 | Michael Hanselmann | |
162 | 725ec2f1 | René Nussbaumer | # First create the RAPI credentials
|
163 | a62d1901 | Michael Hanselmann | fh = tempfile.NamedTemporaryFile() |
164 | a62d1901 | Michael Hanselmann | try:
|
165 | a62d1901 | Michael Hanselmann | fh.write("%s %s write\n" % (rapi_user, rapi_secret))
|
166 | a62d1901 | Michael Hanselmann | fh.flush() |
167 | a62d1901 | Michael Hanselmann | |
168 | aecba21e | Michael Hanselmann | tmpru = qa_utils.UploadFile(master.primary, fh.name) |
169 | a62d1901 | Michael Hanselmann | try:
|
170 | 49ceab21 | Michael Hanselmann | AssertCommand(["mkdir", "-p", rapi_dir]) |
171 | 734fd6b4 | Michael Hanselmann | AssertCommand(["mv", tmpru, rapi_users_path])
|
172 | a62d1901 | Michael Hanselmann | finally:
|
173 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", tmpru]) |
174 | a62d1901 | Michael Hanselmann | finally:
|
175 | a62d1901 | Michael Hanselmann | fh.close() |
176 | a62d1901 | Michael Hanselmann | |
177 | a62d1901 | Michael Hanselmann | # Initialize cluster
|
178 | 3039e2dc | Helga Velroyen | enabled_disk_templates = qa_config.GetEnabledDiskTemplates() |
179 | e7b6183b | Michael Hanselmann | cmd = [ |
180 | e7b6183b | Michael Hanselmann | "gnt-cluster", "init", |
181 | e7b6183b | Michael Hanselmann | "--primary-ip-version=%d" % qa_config.get("primary_ip_version", 4), |
182 | 59c1d41e | Michael Hanselmann | "--enabled-hypervisors=%s" % ",".join(qa_config.GetEnabledHypervisors()), |
183 | 2dae8d64 | Helga Velroyen | "--enabled-disk-templates=%s" %
|
184 | 3039e2dc | Helga Velroyen | ",".join(enabled_disk_templates),
|
185 | e7b6183b | Michael Hanselmann | ] |
186 | 3039e2dc | Helga Velroyen | if constants.DT_FILE in enabled_disk_templates: |
187 | 3039e2dc | Helga Velroyen | cmd.append( |
188 | 3039e2dc | Helga Velroyen | "--file-storage-dir=%s" %
|
189 | b24b52d9 | Helga Velroyen | qa_config.get("default-file-storage-dir",
|
190 | b24b52d9 | Helga Velroyen | pathutils.DEFAULT_FILE_STORAGE_DIR)) |
191 | 20286f7c | René Nussbaumer | |
192 | 20286f7c | René Nussbaumer | for spec_type in ("mem-size", "disk-size", "disk-count", "cpu-count", |
193 | 20286f7c | René Nussbaumer | "nic-count"):
|
194 | 20286f7c | René Nussbaumer | for spec_val in ("min", "max", "std"): |
195 | 20286f7c | René Nussbaumer | spec = qa_config.get("ispec_%s_%s" %
|
196 | 3601d488 | Michael Hanselmann | (spec_type.replace("-", "_"), spec_val), None) |
197 | 00650761 | Michael Hanselmann | if spec is not None: |
198 | 20286f7c | René Nussbaumer | cmd.append("--specs-%s=%s=%d" % (spec_type, spec_val, spec))
|
199 | 9486f6ae | Manuel Franceschini | |
200 | aecba21e | Michael Hanselmann | if master.secondary:
|
201 | aecba21e | Michael Hanselmann | cmd.append("--secondary-ip=%s" % master.secondary)
|
202 | cec9845c | Michael Hanselmann | |
203 | 912737ba | Helga Velroyen | if utils.IsLvmEnabled(qa_config.GetEnabledDiskTemplates()):
|
204 | 912737ba | Helga Velroyen | vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
|
205 | 912737ba | Helga Velroyen | if vgname:
|
206 | 912737ba | Helga Velroyen | cmd.append("--vg-name=%s" % vgname)
|
207 | 912737ba | Helga Velroyen | else:
|
208 | 912737ba | Helga Velroyen | raise qa_error.Error("Please specify a volume group if you enable" |
209 | 912737ba | Helga Velroyen | " lvm-based disk templates in the QA.")
|
210 | 23610ff8 | Bernardo Dal Seno | |
211 | 3601d488 | Michael Hanselmann | master_netdev = qa_config.get("master-netdev", None) |
212 | 3601d488 | Michael Hanselmann | if master_netdev:
|
213 | 3601d488 | Michael Hanselmann | cmd.append("--master-netdev=%s" % master_netdev)
|
214 | 3601d488 | Michael Hanselmann | |
215 | 3601d488 | Michael Hanselmann | nicparams = qa_config.get("default-nicparams", None) |
216 | 3601d488 | Michael Hanselmann | if nicparams:
|
217 | 3601d488 | Michael Hanselmann | cmd.append("--nic-parameters=%s" %
|
218 | 3601d488 | Michael Hanselmann | ",".join(utils.FormatKeyValue(nicparams)))
|
219 | cec9845c | Michael Hanselmann | |
220 | 6a0f22e1 | Bernardo Dal Seno | # Cluster value of the exclusive-storage node parameter
|
221 | 6a0f22e1 | Bernardo Dal Seno | e_s = qa_config.get("exclusive-storage")
|
222 | 6a0f22e1 | Bernardo Dal Seno | if e_s is not None: |
223 | 6a0f22e1 | Bernardo Dal Seno | cmd.extend(["--node-parameters", "exclusive_storage=%s" % e_s]) |
224 | 6a0f22e1 | Bernardo Dal Seno | else:
|
225 | 6a0f22e1 | Bernardo Dal Seno | e_s = False
|
226 | 6a0f22e1 | Bernardo Dal Seno | qa_config.SetExclusiveStorage(e_s) |
227 | 6a0f22e1 | Bernardo Dal Seno | |
228 | becf9d5c | Michael Hanselmann | extra_args = qa_config.get("cluster-init-args")
|
229 | 2c88200b | Helga Velroyen | |
230 | becf9d5c | Michael Hanselmann | if extra_args:
|
231 | 2c88200b | Helga Velroyen | # This option was removed in 2.10, but in order to not break QA of older
|
232 | 2c88200b | Helga Velroyen | # branches we remove it from the extra_args if it is in there.
|
233 | 2c88200b | Helga Velroyen | opt_drbd_storage = "--no-drbd-storage"
|
234 | 2c88200b | Helga Velroyen | if opt_drbd_storage in extra_args: |
235 | 2c88200b | Helga Velroyen | extra_args.remove(opt_drbd_storage) |
236 | becf9d5c | Michael Hanselmann | cmd.extend(extra_args) |
237 | becf9d5c | Michael Hanselmann | |
238 | 13d2e231 | Andrea Spadaccini | cmd.append(qa_config.get("name"))
|
239 | becf9d5c | Michael Hanselmann | |
240 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
241 | cec9845c | Michael Hanselmann | |
242 | 5abecc1c | Iustin Pop | cmd = ["gnt-cluster", "modify"] |
243 | 13d2e231 | Andrea Spadaccini | |
244 | 5abecc1c | Iustin Pop | # hypervisor parameter modifications
|
245 | 5abecc1c | Iustin Pop | hvp = qa_config.get("hypervisor-parameters", {})
|
246 | 5abecc1c | Iustin Pop | for k, v in hvp.items(): |
247 | 5abecc1c | Iustin Pop | cmd.extend(["-H", "%s:%s" % (k, v)]) |
248 | 5abecc1c | Iustin Pop | # backend parameter modifications
|
249 | 5abecc1c | Iustin Pop | bep = qa_config.get("backend-parameters", "") |
250 | 5abecc1c | Iustin Pop | if bep:
|
251 | 5abecc1c | Iustin Pop | cmd.extend(["-B", bep])
|
252 | 5abecc1c | Iustin Pop | |
253 | 5abecc1c | Iustin Pop | if len(cmd) > 2: |
254 | 5abecc1c | Iustin Pop | AssertCommand(cmd) |
255 | 5abecc1c | Iustin Pop | |
256 | 5abecc1c | Iustin Pop | # OS parameters
|
257 | 5abecc1c | Iustin Pop | osp = qa_config.get("os-parameters", {})
|
258 | 5abecc1c | Iustin Pop | for k, v in osp.items(): |
259 | 5abecc1c | Iustin Pop | AssertCommand(["gnt-os", "modify", "-O", v, k]) |
260 | 5abecc1c | Iustin Pop | |
261 | 5abecc1c | Iustin Pop | # OS hypervisor parameters
|
262 | 5abecc1c | Iustin Pop | os_hvp = qa_config.get("os-hvp", {})
|
263 | 5abecc1c | Iustin Pop | for os_name in os_hvp: |
264 | 5abecc1c | Iustin Pop | for hv, hvp in os_hvp[os_name].items(): |
265 | 5abecc1c | Iustin Pop | AssertCommand(["gnt-os", "modify", "-H", "%s:%s" % (hv, hvp), os_name]) |
266 | 5abecc1c | Iustin Pop | |
267 | cec9845c | Michael Hanselmann | |
268 | caea3b32 | Iustin Pop | def TestClusterRename(): |
269 | caea3b32 | Iustin Pop | """gnt-cluster rename"""
|
270 | d0c8c01d | Iustin Pop | cmd = ["gnt-cluster", "rename", "-f"] |
271 | caea3b32 | Iustin Pop | |
272 | d0c8c01d | Iustin Pop | original_name = qa_config.get("name")
|
273 | d0c8c01d | Iustin Pop | rename_target = qa_config.get("rename", None) |
274 | caea3b32 | Iustin Pop | if rename_target is None: |
275 | caea3b32 | Iustin Pop | print qa_utils.FormatError('"rename" entry is missing') |
276 | caea3b32 | Iustin Pop | return
|
277 | caea3b32 | Iustin Pop | |
278 | 2f4b4f78 | Iustin Pop | for data in [ |
279 | 2f4b4f78 | Iustin Pop | cmd + [rename_target], |
280 | c2a0947d | Iustin Pop | _CLUSTER_VERIFY, |
281 | 2f4b4f78 | Iustin Pop | cmd + [original_name], |
282 | c2a0947d | Iustin Pop | _CLUSTER_VERIFY, |
283 | 2f4b4f78 | Iustin Pop | ]: |
284 | 2f4b4f78 | Iustin Pop | AssertCommand(data) |
285 | caea3b32 | Iustin Pop | |
286 | caea3b32 | Iustin Pop | |
287 | 69df9d2b | Iustin Pop | def TestClusterOob(): |
288 | 69df9d2b | Iustin Pop | """out-of-band framework"""
|
289 | f55312bd | René Nussbaumer | oob_path_exists = "/tmp/ganeti-qa-oob-does-exist-%s" % utils.NewUUID()
|
290 | f55312bd | René Nussbaumer | |
291 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY) |
292 | f55312bd | René Nussbaumer | AssertCommand(["gnt-cluster", "modify", "--node-parameters", |
293 | f55312bd | René Nussbaumer | "oob_program=/tmp/ganeti-qa-oob-does-not-exist-%s" %
|
294 | f55312bd | René Nussbaumer | utils.NewUUID()]) |
295 | f55312bd | René Nussbaumer | |
296 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY, fail=True)
|
297 | f55312bd | René Nussbaumer | |
298 | 69df9d2b | Iustin Pop | AssertCommand(["touch", oob_path_exists])
|
299 | 69df9d2b | Iustin Pop | AssertCommand(["chmod", "0400", oob_path_exists]) |
300 | 69df9d2b | Iustin Pop | AssertCommand(["gnt-cluster", "copyfile", oob_path_exists]) |
301 | f55312bd | René Nussbaumer | |
302 | f55312bd | René Nussbaumer | try:
|
303 | f55312bd | René Nussbaumer | AssertCommand(["gnt-cluster", "modify", "--node-parameters", |
304 | f55312bd | René Nussbaumer | "oob_program=%s" % oob_path_exists])
|
305 | f55312bd | René Nussbaumer | |
306 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY, fail=True)
|
307 | f55312bd | René Nussbaumer | |
308 | 69df9d2b | Iustin Pop | AssertCommand(["chmod", "0500", oob_path_exists]) |
309 | 69df9d2b | Iustin Pop | AssertCommand(["gnt-cluster", "copyfile", oob_path_exists]) |
310 | f55312bd | René Nussbaumer | |
311 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY) |
312 | f55312bd | René Nussbaumer | finally:
|
313 | 69df9d2b | Iustin Pop | AssertCommand(["gnt-cluster", "command", "rm", oob_path_exists]) |
314 | f55312bd | René Nussbaumer | |
315 | f55312bd | René Nussbaumer | AssertCommand(["gnt-cluster", "modify", "--node-parameters", |
316 | f55312bd | René Nussbaumer | "oob_program="])
|
317 | 69df9d2b | Iustin Pop | |
318 | 69df9d2b | Iustin Pop | |
319 | 66d1f035 | René Nussbaumer | def TestClusterEpo(): |
320 | 66d1f035 | René Nussbaumer | """gnt-cluster epo"""
|
321 | 66d1f035 | René Nussbaumer | master = qa_config.GetMasterNode() |
322 | 66d1f035 | René Nussbaumer | |
323 | 66d1f035 | René Nussbaumer | # Assert that OOB is unavailable for all nodes
|
324 | aecba21e | Michael Hanselmann | result_output = GetCommandOutput(master.primary, |
325 | 58ea8d17 | Michael Hanselmann | "gnt-node list --verbose --no-headers -o"
|
326 | 66d1f035 | René Nussbaumer | " powered")
|
327 | 66d1f035 | René Nussbaumer | AssertEqual(compat.all(powered == "(unavail)"
|
328 | 66d1f035 | René Nussbaumer | for powered in result_output.splitlines()), True) |
329 | 66d1f035 | René Nussbaumer | |
330 | 66d1f035 | René Nussbaumer | # Conflicting
|
331 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "--groups", "--all"], fail=True) |
332 | 66d1f035 | René Nussbaumer | # --all doesn't expect arguments
|
333 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "--all", "some_arg"], fail=True) |
334 | 66d1f035 | René Nussbaumer | |
335 | 66d1f035 | René Nussbaumer | # Unless --all is given master is not allowed to be in the list
|
336 | aecba21e | Michael Hanselmann | AssertCommand(["gnt-cluster", "epo", "-f", master.primary], fail=True) |
337 | 66d1f035 | René Nussbaumer | |
338 | 66d1f035 | René Nussbaumer | # This shouldn't fail
|
339 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "-f", "--all"]) |
340 | 66d1f035 | René Nussbaumer | |
341 | 66d1f035 | René Nussbaumer | # All instances should have been stopped now
|
342 | aecba21e | Michael Hanselmann | result_output = GetCommandOutput(master.primary, |
343 | 58ea8d17 | Michael Hanselmann | "gnt-instance list --no-headers -o status")
|
344 | 3e0ed18c | René Nussbaumer | # ERROR_down because the instance is stopped but not recorded as such
|
345 | 3e0ed18c | René Nussbaumer | AssertEqual(compat.all(status == "ERROR_down"
|
346 | 66d1f035 | René Nussbaumer | for status in result_output.splitlines()), True) |
347 | 66d1f035 | René Nussbaumer | |
348 | 66d1f035 | René Nussbaumer | # Now start everything again
|
349 | 66d1f035 | René Nussbaumer | AssertCommand(["gnt-cluster", "epo", "--on", "-f", "--all"]) |
350 | 66d1f035 | René Nussbaumer | |
351 | 66d1f035 | René Nussbaumer | # All instances should have been started now
|
352 | aecba21e | Michael Hanselmann | result_output = GetCommandOutput(master.primary, |
353 | 58ea8d17 | Michael Hanselmann | "gnt-instance list --no-headers -o status")
|
354 | 66d1f035 | René Nussbaumer | AssertEqual(compat.all(status == "running"
|
355 | 66d1f035 | René Nussbaumer | for status in result_output.splitlines()), True) |
356 | 66d1f035 | René Nussbaumer | |
357 | 66d1f035 | René Nussbaumer | |
358 | 69df9d2b | Iustin Pop | def TestClusterVerify(): |
359 | 69df9d2b | Iustin Pop | """gnt-cluster verify"""
|
360 | c2a0947d | Iustin Pop | AssertCommand(_CLUSTER_VERIFY) |
361 | c6953b6e | Iustin Pop | AssertCommand(["gnt-cluster", "verify-disks"]) |
362 | cec9845c | Michael Hanselmann | |
363 | 1377433b | Michael Hanselmann | |
364 | 7af293d7 | Thomas Thrainer | def TestClusterVerifyDisksBrokenDRBD(instance, inst_nodes): |
365 | 7af293d7 | Thomas Thrainer | """gnt-cluster verify-disks with broken DRBD"""
|
366 | e4889779 | Thomas Thrainer | qa_daemon.TestPauseWatcher() |
367 | 7af293d7 | Thomas Thrainer | |
368 | e4889779 | Thomas Thrainer | try:
|
369 | e4889779 | Thomas Thrainer | info = qa_instance.GetInstanceInfo(instance.name) |
370 | e4889779 | Thomas Thrainer | snode = inst_nodes[1]
|
371 | e4889779 | Thomas Thrainer | for idx, minor in enumerate(info["drbd-minors"][snode.primary]): |
372 | e4889779 | Thomas Thrainer | if idx % 2 == 0: |
373 | e4889779 | Thomas Thrainer | break_drbd_cmd = \ |
374 | e4889779 | Thomas Thrainer | "(drbdsetup %d down >/dev/null 2>&1;" \
|
375 | e4889779 | Thomas Thrainer | " drbdsetup down resource%d >/dev/null 2>&1) || /bin/true" % \
|
376 | e4889779 | Thomas Thrainer | (minor, minor) |
377 | e4889779 | Thomas Thrainer | else:
|
378 | e4889779 | Thomas Thrainer | break_drbd_cmd = \ |
379 | e4889779 | Thomas Thrainer | "(drbdsetup %d detach >/dev/null 2>&1;" \
|
380 | e4889779 | Thomas Thrainer | " drbdsetup detach %d >/dev/null 2>&1) || /bin/true" % \
|
381 | e4889779 | Thomas Thrainer | (minor, minor) |
382 | e4889779 | Thomas Thrainer | AssertCommand(break_drbd_cmd, node=snode) |
383 | e4889779 | Thomas Thrainer | |
384 | e4889779 | Thomas Thrainer | verify_output = GetCommandOutput(qa_config.GetMasterNode().primary, |
385 | e4889779 | Thomas Thrainer | "gnt-cluster verify-disks")
|
386 | e4889779 | Thomas Thrainer | activation_msg = "Activating disks for instance '%s'" % instance.name
|
387 | e4889779 | Thomas Thrainer | if activation_msg not in verify_output: |
388 | e4889779 | Thomas Thrainer | raise qa_error.Error("gnt-cluster verify-disks did not activate broken" |
389 | e4889779 | Thomas Thrainer | " DRBD disks:\n%s" % verify_output)
|
390 | e4889779 | Thomas Thrainer | |
391 | e4889779 | Thomas Thrainer | verify_output = GetCommandOutput(qa_config.GetMasterNode().primary, |
392 | e4889779 | Thomas Thrainer | "gnt-cluster verify-disks")
|
393 | e4889779 | Thomas Thrainer | if activation_msg in verify_output: |
394 | e4889779 | Thomas Thrainer | raise qa_error.Error("gnt-cluster verify-disks wants to activate broken" |
395 | e4889779 | Thomas Thrainer | " DRBD disks on second attempt:\n%s" % verify_output)
|
396 | e4889779 | Thomas Thrainer | |
397 | e4889779 | Thomas Thrainer | AssertCommand(_CLUSTER_VERIFY) |
398 | e4889779 | Thomas Thrainer | finally:
|
399 | e4889779 | Thomas Thrainer | qa_daemon.TestResumeWatcher() |
400 | 7af293d7 | Thomas Thrainer | |
401 | 7af293d7 | Thomas Thrainer | |
402 | 1377433b | Michael Hanselmann | def TestJobqueue(): |
403 | 1377433b | Michael Hanselmann | """gnt-debug test-jobqueue"""
|
404 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-debug", "test-jobqueue"]) |
405 | 1377433b | Michael Hanselmann | |
406 | 1377433b | Michael Hanselmann | |
407 | 5a85b99e | Michael Hanselmann | def TestDelay(node): |
408 | 5a85b99e | Michael Hanselmann | """gnt-debug delay"""
|
409 | 5a85b99e | Michael Hanselmann | AssertCommand(["gnt-debug", "delay", "1"]) |
410 | 5a85b99e | Michael Hanselmann | AssertCommand(["gnt-debug", "delay", "--no-master", "1"]) |
411 | 5a85b99e | Michael Hanselmann | AssertCommand(["gnt-debug", "delay", "--no-master", |
412 | aecba21e | Michael Hanselmann | "-n", node.primary, "1"]) |
413 | 5a85b99e | Michael Hanselmann | |
414 | 5a85b99e | Michael Hanselmann | |
415 | 452913ed | Iustin Pop | def TestClusterReservedLvs(): |
416 | 452913ed | Iustin Pop | """gnt-cluster reserved lvs"""
|
417 | bab4f56a | Helga Velroyen | # if no lvm-based templates are supported, skip the test
|
418 | bab4f56a | Helga Velroyen | if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG): |
419 | bab4f56a | Helga Velroyen | return
|
420 | 23610ff8 | Bernardo Dal Seno | vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
|
421 | 23610ff8 | Bernardo Dal Seno | lvname = _QA_LV_PREFIX + "test"
|
422 | 23610ff8 | Bernardo Dal Seno | lvfullname = "/".join([vgname, lvname])
|
423 | 2f4b4f78 | Iustin Pop | for fail, cmd in [ |
424 | c2a0947d | Iustin Pop | (False, _CLUSTER_VERIFY),
|
425 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "--reserved-lvs", ""]), |
426 | 23610ff8 | Bernardo Dal Seno | (False, ["lvcreate", "-L1G", "-n", lvname, vgname]), |
427 | 21bf2e2e | Andrea Spadaccini | (True, _CLUSTER_VERIFY),
|
428 | 84d7e26b | Dmitry Chernyak | (False, ["gnt-cluster", "modify", "--reserved-lvs", |
429 | 23610ff8 | Bernardo Dal Seno | "%s,.*/other-test" % lvfullname]),
|
430 | c2a0947d | Iustin Pop | (False, _CLUSTER_VERIFY),
|
431 | 23610ff8 | Bernardo Dal Seno | (False, ["gnt-cluster", "modify", "--reserved-lvs", |
432 | 23610ff8 | Bernardo Dal Seno | ".*/%s.*" % _QA_LV_PREFIX]),
|
433 | c2a0947d | Iustin Pop | (False, _CLUSTER_VERIFY),
|
434 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "--reserved-lvs", ""]), |
435 | 21bf2e2e | Andrea Spadaccini | (True, _CLUSTER_VERIFY),
|
436 | 23610ff8 | Bernardo Dal Seno | (False, ["lvremove", "-f", lvfullname]), |
437 | c2a0947d | Iustin Pop | (False, _CLUSTER_VERIFY),
|
438 | 452913ed | Iustin Pop | ]: |
439 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, fail=fail) |
440 | 452913ed | Iustin Pop | |
441 | cec9845c | Michael Hanselmann | |
442 | 1e7acc3b | Iustin Pop | def TestClusterModifyEmpty(): |
443 | 1e7acc3b | Iustin Pop | """gnt-cluster modify"""
|
444 | 1e7acc3b | Iustin Pop | AssertCommand(["gnt-cluster", "modify"], fail=True) |
445 | 1e7acc3b | Iustin Pop | |
446 | 1e7acc3b | Iustin Pop | |
447 | 92cb4940 | Andrea Spadaccini | def TestClusterModifyDisk(): |
448 | 92cb4940 | Andrea Spadaccini | """gnt-cluster modify -D"""
|
449 | 92cb4940 | Andrea Spadaccini | for param in _FAIL_PARAMS: |
450 | 92cb4940 | Andrea Spadaccini | AssertCommand(["gnt-cluster", "modify", "-D", param], fail=True) |
451 | 92cb4940 | Andrea Spadaccini | |
452 | 92cb4940 | Andrea Spadaccini | |
453 | b24b52d9 | Helga Velroyen | def _GetOtherEnabledDiskTemplate(undesired_disk_templates, |
454 | b24b52d9 | Helga Velroyen | enabled_disk_templates): |
455 | b24b52d9 | Helga Velroyen | """Returns one template that is not in the undesired set.
|
456 | b24b52d9 | Helga Velroyen |
|
457 | b24b52d9 | Helga Velroyen | @type undesired_disk_templates: list of string
|
458 | b24b52d9 | Helga Velroyen | @param undesired_disk_templates: a list of disk templates that we want to
|
459 | b24b52d9 | Helga Velroyen | exclude when drawing one disk template from the list of enabled
|
460 | b24b52d9 | Helga Velroyen | disk templates
|
461 | b24b52d9 | Helga Velroyen | @type enabled_disk_templates: list of string
|
462 | b24b52d9 | Helga Velroyen | @param enabled_disk_templates: list of enabled disk templates (in QA)
|
463 | b24b52d9 | Helga Velroyen |
|
464 | b24b52d9 | Helga Velroyen | """
|
465 | b24b52d9 | Helga Velroyen | desired_templates = list(set(enabled_disk_templates) |
466 | b24b52d9 | Helga Velroyen | - set(undesired_disk_templates))
|
467 | b24b52d9 | Helga Velroyen | if desired_templates:
|
468 | b24b52d9 | Helga Velroyen | template = desired_templates[0]
|
469 | b24b52d9 | Helga Velroyen | else:
|
470 | b24b52d9 | Helga Velroyen | # If no desired disk template is available for QA, choose 'diskless' and
|
471 | b24b52d9 | Helga Velroyen | # hope for the best.
|
472 | b24b52d9 | Helga Velroyen | template = constants.ST_DISKLESS |
473 | b24b52d9 | Helga Velroyen | |
474 | b24b52d9 | Helga Velroyen | return template
|
475 | b24b52d9 | Helga Velroyen | |
476 | b24b52d9 | Helga Velroyen | |
477 | b24b52d9 | Helga Velroyen | def TestClusterModifyFileBasedStorageDir( |
478 | b24b52d9 | Helga Velroyen | file_disk_template, dir_config_key, default_dir, option_name): |
479 | b24b52d9 | Helga Velroyen | """Tests gnt-cluster modify wrt to file-based directory options.
|
480 | b24b52d9 | Helga Velroyen |
|
481 | b24b52d9 | Helga Velroyen | @type file_disk_template: string
|
482 | b24b52d9 | Helga Velroyen | @param file_disk_template: file-based disk template
|
483 | b24b52d9 | Helga Velroyen | @type dir_config_key: string
|
484 | b24b52d9 | Helga Velroyen | @param dir_config_key: key for the QA config to retrieve the default
|
485 | b24b52d9 | Helga Velroyen | directory value
|
486 | b24b52d9 | Helga Velroyen | @type default_dir: string
|
487 | b24b52d9 | Helga Velroyen | @param default_dir: default directory, if the QA config does not specify
|
488 | b24b52d9 | Helga Velroyen | it
|
489 | b24b52d9 | Helga Velroyen | @type option_name: string
|
490 | b24b52d9 | Helga Velroyen | @param option_name: name of the option of 'gnt-cluster modify' to
|
491 | b24b52d9 | Helga Velroyen | change the directory
|
492 | b24b52d9 | Helga Velroyen |
|
493 | b24b52d9 | Helga Velroyen | """
|
494 | b24b52d9 | Helga Velroyen | enabled_disk_templates = qa_config.GetEnabledDiskTemplates() |
495 | a09639d1 | Santi Raffa | assert file_disk_template in constants.DTS_FILEBASED |
496 | b24b52d9 | Helga Velroyen | if not qa_config.IsTemplateSupported(file_disk_template): |
497 | b24b52d9 | Helga Velroyen | return
|
498 | b24b52d9 | Helga Velroyen | |
499 | b24b52d9 | Helga Velroyen | # Get some non-file-based disk template to disable file storage
|
500 | b24b52d9 | Helga Velroyen | other_disk_template = _GetOtherEnabledDiskTemplate( |
501 | b24b52d9 | Helga Velroyen | utils.storage.GetDiskTemplatesOfStorageType(constants.ST_FILE), |
502 | b24b52d9 | Helga Velroyen | enabled_disk_templates) |
503 | b24b52d9 | Helga Velroyen | |
504 | b24b52d9 | Helga Velroyen | file_storage_dir = qa_config.get(dir_config_key, default_dir) |
505 | b24b52d9 | Helga Velroyen | invalid_file_storage_dir = "/boot/"
|
506 | b24b52d9 | Helga Velroyen | |
507 | b24b52d9 | Helga Velroyen | for fail, cmd in [ |
508 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "modify", |
509 | e0e44476 | Michele Tartara | "--enabled-disk-templates=%s" % file_disk_template,
|
510 | e0e44476 | Michele Tartara | "--ipolicy-disk-templates=%s" % file_disk_template]),
|
511 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "modify", |
512 | e0e44476 | Michele Tartara | "--%s=%s" % (option_name, file_storage_dir)]),
|
513 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "modify", |
514 | e0e44476 | Michele Tartara | "--%s=%s" % (option_name, invalid_file_storage_dir)]),
|
515 | b24b52d9 | Helga Velroyen | # file storage dir is set to an inacceptable path, thus verify
|
516 | b24b52d9 | Helga Velroyen | # should fail
|
517 | b24b52d9 | Helga Velroyen | (True, ["gnt-cluster", "verify"]), |
518 | b24b52d9 | Helga Velroyen | # unsetting the storage dir while file storage is enabled
|
519 | b24b52d9 | Helga Velroyen | # should fail
|
520 | b24b52d9 | Helga Velroyen | (True, ["gnt-cluster", "modify", |
521 | b24b52d9 | Helga Velroyen | "--%s=" % option_name]),
|
522 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "modify", |
523 | e0e44476 | Michele Tartara | "--%s=%s" % (option_name, file_storage_dir)]),
|
524 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "modify", |
525 | e0e44476 | Michele Tartara | "--enabled-disk-templates=%s" % other_disk_template,
|
526 | e0e44476 | Michele Tartara | "--ipolicy-disk-templates=%s" % other_disk_template]),
|
527 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "modify", |
528 | e0e44476 | Michele Tartara | "--%s=%s" % (option_name, invalid_file_storage_dir)]),
|
529 | b24b52d9 | Helga Velroyen | # file storage is set to an inacceptable path, but file storage
|
530 | b24b52d9 | Helga Velroyen | # is disabled, thus verify should not fail
|
531 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "verify"]), |
532 | b24b52d9 | Helga Velroyen | # unsetting the file storage dir while file storage is not enabled
|
533 | b24b52d9 | Helga Velroyen | # should be fine
|
534 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "modify", |
535 | e0e44476 | Michele Tartara | "--%s=" % option_name]),
|
536 | b24b52d9 | Helga Velroyen | # resetting everything to sane values
|
537 | b24b52d9 | Helga Velroyen | (False, ["gnt-cluster", "modify", |
538 | e0e44476 | Michele Tartara | "--%s=%s" % (option_name, file_storage_dir),
|
539 | e0e44476 | Michele Tartara | "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates), |
540 | e0e44476 | Michele Tartara | "--ipolicy-disk-templates=%s" % ",".join(enabled_disk_templates)]) |
541 | b24b52d9 | Helga Velroyen | ]: |
542 | b24b52d9 | Helga Velroyen | AssertCommand(cmd, fail=fail) |
543 | b24b52d9 | Helga Velroyen | |
544 | b24b52d9 | Helga Velroyen | |
545 | b24b52d9 | Helga Velroyen | def TestClusterModifyFileStorageDir(): |
546 | b24b52d9 | Helga Velroyen | """gnt-cluster modify --file-storage-dir=..."""
|
547 | b24b52d9 | Helga Velroyen | TestClusterModifyFileBasedStorageDir( |
548 | b24b52d9 | Helga Velroyen | constants.DT_FILE, "default-file-storage-dir",
|
549 | b24b52d9 | Helga Velroyen | pathutils.DEFAULT_FILE_STORAGE_DIR, |
550 | b24b52d9 | Helga Velroyen | "file-storage-dir")
|
551 | b24b52d9 | Helga Velroyen | |
552 | b24b52d9 | Helga Velroyen | |
553 | b24b52d9 | Helga Velroyen | def TestClusterModifySharedFileStorageDir(): |
554 | b24b52d9 | Helga Velroyen | """gnt-cluster modify --shared-file-storage-dir=..."""
|
555 | b24b52d9 | Helga Velroyen | TestClusterModifyFileBasedStorageDir( |
556 | b24b52d9 | Helga Velroyen | constants.DT_SHARED_FILE, "default-shared-file-storage-dir",
|
557 | b24b52d9 | Helga Velroyen | pathutils.DEFAULT_SHARED_FILE_STORAGE_DIR, |
558 | b24b52d9 | Helga Velroyen | "shared-file-storage-dir")
|
559 | b24b52d9 | Helga Velroyen | |
560 | b24b52d9 | Helga Velroyen | |
561 | 2dae8d64 | Helga Velroyen | def TestClusterModifyDiskTemplates(): |
562 | 2dae8d64 | Helga Velroyen | """gnt-cluster modify --enabled-disk-templates=..."""
|
563 | 462f0faa | Helga Velroyen | enabled_disk_templates = qa_config.GetEnabledDiskTemplates() |
564 | 2dae8d64 | Helga Velroyen | default_disk_template = qa_config.GetDefaultDiskTemplate() |
565 | 462f0faa | Helga Velroyen | |
566 | a25f44a4 | Helga Velroyen | _TestClusterModifyDiskTemplatesArguments(default_disk_template) |
567 | a25f44a4 | Helga Velroyen | _TestClusterModifyDiskTemplatesDrbdHelper(enabled_disk_templates) |
568 | 912737ba | Helga Velroyen | _TestClusterModifyDiskTemplatesVgName(enabled_disk_templates) |
569 | 462f0faa | Helga Velroyen | |
570 | 462f0faa | Helga Velroyen | _RestoreEnabledDiskTemplates() |
571 | 462f0faa | Helga Velroyen | nodes = qa_config.AcquireManyNodes(2)
|
572 | 462f0faa | Helga Velroyen | |
573 | 462f0faa | Helga Velroyen | instance_template = enabled_disk_templates[0]
|
574 | 462f0faa | Helga Velroyen | instance = qa_instance.CreateInstanceByDiskTemplate(nodes, instance_template) |
575 | 462f0faa | Helga Velroyen | |
576 | 462f0faa | Helga Velroyen | _TestClusterModifyUsedDiskTemplate(instance_template, |
577 | 462f0faa | Helga Velroyen | enabled_disk_templates) |
578 | 462f0faa | Helga Velroyen | |
579 | 462f0faa | Helga Velroyen | qa_instance.TestInstanceRemove(instance) |
580 | 462f0faa | Helga Velroyen | _RestoreEnabledDiskTemplates() |
581 | 462f0faa | Helga Velroyen | |
582 | 462f0faa | Helga Velroyen | |
583 | 462f0faa | Helga Velroyen | def _RestoreEnabledDiskTemplates(): |
584 | 462f0faa | Helga Velroyen | """Sets the list of enabled disk templates back to the list of enabled disk
|
585 | 462f0faa | Helga Velroyen | templates from the QA configuration. This can be used to make sure that
|
586 | 462f0faa | Helga Velroyen | the tests that modify the list of disk templates do not interfere with
|
587 | 462f0faa | Helga Velroyen | other tests.
|
588 | 462f0faa | Helga Velroyen |
|
589 | 462f0faa | Helga Velroyen | """
|
590 | eb161df2 | Helga Velroyen | enabled_disk_templates = qa_config.GetEnabledDiskTemplates() |
591 | eb161df2 | Helga Velroyen | cmd = ["gnt-cluster", "modify", |
592 | eb161df2 | Helga Velroyen | "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates), |
593 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % ",".join(enabled_disk_templates), |
594 | eb161df2 | Helga Velroyen | ] |
595 | d101b7be | Thomas Thrainer | |
596 | d101b7be | Thomas Thrainer | if utils.IsLvmEnabled(qa_config.GetEnabledDiskTemplates()):
|
597 | d101b7be | Thomas Thrainer | vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
|
598 | d101b7be | Thomas Thrainer | cmd.append("--vg-name=%s" % vgname)
|
599 | d101b7be | Thomas Thrainer | |
600 | d101b7be | Thomas Thrainer | AssertCommand(cmd, fail=False)
|
601 | 462f0faa | Helga Velroyen | |
602 | 462f0faa | Helga Velroyen | |
603 | a25f44a4 | Helga Velroyen | def _TestClusterModifyDiskTemplatesDrbdHelper(enabled_disk_templates): |
604 | a25f44a4 | Helga Velroyen | """Tests argument handling of 'gnt-cluster modify' with respect to
|
605 | a25f44a4 | Helga Velroyen | the parameter '--drbd-usermode-helper'. This test is independent
|
606 | a25f44a4 | Helga Velroyen | of instances.
|
607 | a25f44a4 | Helga Velroyen |
|
608 | a25f44a4 | Helga Velroyen | """
|
609 | a25f44a4 | Helga Velroyen | _RestoreEnabledDiskTemplates() |
610 | a25f44a4 | Helga Velroyen | |
611 | a25f44a4 | Helga Velroyen | if constants.DT_DRBD8 not in enabled_disk_templates: |
612 | a25f44a4 | Helga Velroyen | return
|
613 | a25f44a4 | Helga Velroyen | if constants.DT_PLAIN not in enabled_disk_templates: |
614 | a25f44a4 | Helga Velroyen | return
|
615 | a25f44a4 | Helga Velroyen | |
616 | a25f44a4 | Helga Velroyen | drbd_usermode_helper = qa_config.get("drbd-usermode-helper", "/bin/true") |
617 | a25f44a4 | Helga Velroyen | bogus_usermode_helper = "/tmp/pinkbunny"
|
618 | 317a3fdb | Michele Tartara | for command, fail in [ |
619 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
620 | 317a3fdb | Michele Tartara | "--enabled-disk-templates=%s" % constants.DT_DRBD8,
|
621 | 317a3fdb | Michele Tartara | "--ipolicy-disk-templates=%s" % constants.DT_DRBD8], False), |
622 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
623 | 317a3fdb | Michele Tartara | "--drbd-usermode-helper=%s" % drbd_usermode_helper], False), |
624 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
625 | 317a3fdb | Michele Tartara | "--drbd-usermode-helper=%s" % bogus_usermode_helper], True), |
626 | 317a3fdb | Michele Tartara | # unsetting helper when DRBD is enabled should not work
|
627 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
628 | 317a3fdb | Michele Tartara | "--drbd-usermode-helper="], True), |
629 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
630 | 317a3fdb | Michele Tartara | "--enabled-disk-templates=%s" % constants.DT_PLAIN,
|
631 | 317a3fdb | Michele Tartara | "--ipolicy-disk-templates=%s" % constants.DT_PLAIN], False), |
632 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
633 | 317a3fdb | Michele Tartara | "--drbd-usermode-helper="], False), |
634 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
635 | 317a3fdb | Michele Tartara | "--drbd-usermode-helper=%s" % drbd_usermode_helper], False), |
636 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
637 | 317a3fdb | Michele Tartara | "--drbd-usermode-helper=%s" % drbd_usermode_helper,
|
638 | 317a3fdb | Michele Tartara | "--enabled-disk-templates=%s" % constants.DT_DRBD8,
|
639 | 317a3fdb | Michele Tartara | "--ipolicy-disk-templates=%s" % constants.DT_DRBD8], False), |
640 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
641 | 317a3fdb | Michele Tartara | "--drbd-usermode-helper=",
|
642 | 317a3fdb | Michele Tartara | "--enabled-disk-templates=%s" % constants.DT_PLAIN,
|
643 | 317a3fdb | Michele Tartara | "--ipolicy-disk-templates=%s" % constants.DT_PLAIN], False), |
644 | 317a3fdb | Michele Tartara | (["gnt-cluster", "modify", |
645 | 317a3fdb | Michele Tartara | "--drbd-usermode-helper=%s" % drbd_usermode_helper,
|
646 | 317a3fdb | Michele Tartara | "--enabled-disk-templates=%s" % constants.DT_DRBD8,
|
647 | 317a3fdb | Michele Tartara | "--ipolicy-disk-templates=%s" % constants.DT_DRBD8], False), |
648 | 317a3fdb | Michele Tartara | ]: |
649 | a25f44a4 | Helga Velroyen | AssertCommand(command, fail=fail) |
650 | a25f44a4 | Helga Velroyen | _RestoreEnabledDiskTemplates() |
651 | a25f44a4 | Helga Velroyen | |
652 | a25f44a4 | Helga Velroyen | |
653 | a25f44a4 | Helga Velroyen | def _TestClusterModifyDiskTemplatesArguments(default_disk_template): |
654 | 462f0faa | Helga Velroyen | """Tests argument handling of 'gnt-cluster modify' with respect to
|
655 | 462f0faa | Helga Velroyen | the parameter '--enabled-disk-templates'. This test is independent
|
656 | 462f0faa | Helga Velroyen | of instances.
|
657 | 462f0faa | Helga Velroyen |
|
658 | 462f0faa | Helga Velroyen | """
|
659 | 912737ba | Helga Velroyen | _RestoreEnabledDiskTemplates() |
660 | 462f0faa | Helga Velroyen | |
661 | 2dae8d64 | Helga Velroyen | # bogus templates
|
662 | dacd8ba4 | Helga Velroyen | AssertCommand(["gnt-cluster", "modify", |
663 | 2dae8d64 | Helga Velroyen | "--enabled-disk-templates=pinkbunny"],
|
664 | dacd8ba4 | Helga Velroyen | fail=True)
|
665 | 462f0faa | Helga Velroyen | |
666 | dacd8ba4 | Helga Velroyen | # duplicate entries do no harm
|
667 | dacd8ba4 | Helga Velroyen | AssertCommand( |
668 | dacd8ba4 | Helga Velroyen | ["gnt-cluster", "modify", |
669 | 2dae8d64 | Helga Velroyen | "--enabled-disk-templates=%s,%s" %
|
670 | eb161df2 | Helga Velroyen | (default_disk_template, default_disk_template), |
671 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % default_disk_template],
|
672 | dacd8ba4 | Helga Velroyen | fail=False)
|
673 | 462f0faa | Helga Velroyen | |
674 | 912737ba | Helga Velroyen | |
675 | 912737ba | Helga Velroyen | def _TestClusterModifyDiskTemplatesVgName(enabled_disk_templates): |
676 | 912737ba | Helga Velroyen | """Tests argument handling of 'gnt-cluster modify' with respect to
|
677 | 912737ba | Helga Velroyen | the parameter '--enabled-disk-templates' and '--vg-name'. This test is
|
678 | 912737ba | Helga Velroyen | independent of instances.
|
679 | 912737ba | Helga Velroyen |
|
680 | 912737ba | Helga Velroyen | """
|
681 | 912737ba | Helga Velroyen | if not utils.IsLvmEnabled(enabled_disk_templates): |
682 | 912737ba | Helga Velroyen | # These tests only make sense if lvm is enabled for QA
|
683 | 912737ba | Helga Velroyen | return
|
684 | 912737ba | Helga Velroyen | |
685 | 912737ba | Helga Velroyen | # determine an LVM and a non-LVM disk template for the tests
|
686 | d48c944b | Helga Velroyen | non_lvm_template = _GetOtherEnabledDiskTemplate(constants.DTS_LVM, |
687 | b24b52d9 | Helga Velroyen | enabled_disk_templates) |
688 | d48c944b | Helga Velroyen | lvm_template = list(set(enabled_disk_templates) & constants.DTS_LVM)[0] |
689 | 912737ba | Helga Velroyen | |
690 | 912737ba | Helga Velroyen | vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
|
691 | 912737ba | Helga Velroyen | |
692 | 912737ba | Helga Velroyen | # Clean start: unset volume group name, disable lvm storage
|
693 | 912737ba | Helga Velroyen | AssertCommand( |
694 | 912737ba | Helga Velroyen | ["gnt-cluster", "modify", |
695 | 912737ba | Helga Velroyen | "--enabled-disk-templates=%s" % non_lvm_template,
|
696 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % non_lvm_template,
|
697 | 912737ba | Helga Velroyen | "--vg-name="],
|
698 | 912737ba | Helga Velroyen | fail=False)
|
699 | 912737ba | Helga Velroyen | |
700 | 912737ba | Helga Velroyen | # Try to enable lvm, when no volume group is given
|
701 | 912737ba | Helga Velroyen | AssertCommand( |
702 | 912737ba | Helga Velroyen | ["gnt-cluster", "modify", |
703 | eb161df2 | Helga Velroyen | "--enabled-disk-templates=%s" % lvm_template,
|
704 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % lvm_template],
|
705 | 912737ba | Helga Velroyen | fail=True)
|
706 | 912737ba | Helga Velroyen | |
707 | 912737ba | Helga Velroyen | # Set volume group, with lvm still disabled: just a warning
|
708 | 912737ba | Helga Velroyen | AssertCommand(["gnt-cluster", "modify", "--vg-name=%s" % vgname], fail=False) |
709 | 912737ba | Helga Velroyen | |
710 | 912737ba | Helga Velroyen | # Try unsetting vg name and enabling lvm at the same time
|
711 | 912737ba | Helga Velroyen | AssertCommand( |
712 | 912737ba | Helga Velroyen | ["gnt-cluster", "modify", |
713 | 912737ba | Helga Velroyen | "--enabled-disk-templates=%s" % lvm_template,
|
714 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % lvm_template,
|
715 | 912737ba | Helga Velroyen | "--vg-name="],
|
716 | 912737ba | Helga Velroyen | fail=True)
|
717 | 912737ba | Helga Velroyen | |
718 | 912737ba | Helga Velroyen | # Enable lvm with vg name present
|
719 | 912737ba | Helga Velroyen | AssertCommand( |
720 | 912737ba | Helga Velroyen | ["gnt-cluster", "modify", |
721 | eb161df2 | Helga Velroyen | "--enabled-disk-templates=%s" % lvm_template,
|
722 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % lvm_template],
|
723 | 912737ba | Helga Velroyen | fail=False)
|
724 | 912737ba | Helga Velroyen | |
725 | 912737ba | Helga Velroyen | # Try unsetting vg name with lvm still enabled
|
726 | 912737ba | Helga Velroyen | AssertCommand(["gnt-cluster", "modify", "--vg-name="], fail=True) |
727 | 912737ba | Helga Velroyen | |
728 | 912737ba | Helga Velroyen | # Disable lvm with vg name still set
|
729 | 912737ba | Helga Velroyen | AssertCommand( |
730 | eb161df2 | Helga Velroyen | ["gnt-cluster", "modify", |
731 | eb161df2 | Helga Velroyen | "--enabled-disk-templates=%s" % non_lvm_template,
|
732 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % non_lvm_template,
|
733 | eb161df2 | Helga Velroyen | ], |
734 | 912737ba | Helga Velroyen | fail=False)
|
735 | 912737ba | Helga Velroyen | |
736 | 912737ba | Helga Velroyen | # Try unsetting vg name with lvm disabled
|
737 | 912737ba | Helga Velroyen | AssertCommand(["gnt-cluster", "modify", "--vg-name="], fail=False) |
738 | 912737ba | Helga Velroyen | |
739 | 912737ba | Helga Velroyen | # Set vg name and enable lvm at the same time
|
740 | 912737ba | Helga Velroyen | AssertCommand( |
741 | 912737ba | Helga Velroyen | ["gnt-cluster", "modify", |
742 | 912737ba | Helga Velroyen | "--enabled-disk-templates=%s" % lvm_template,
|
743 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % lvm_template,
|
744 | 912737ba | Helga Velroyen | "--vg-name=%s" % vgname],
|
745 | 912737ba | Helga Velroyen | fail=False)
|
746 | 912737ba | Helga Velroyen | |
747 | 912737ba | Helga Velroyen | # Unset vg name and disable lvm at the same time
|
748 | 912737ba | Helga Velroyen | AssertCommand( |
749 | 912737ba | Helga Velroyen | ["gnt-cluster", "modify", |
750 | 912737ba | Helga Velroyen | "--enabled-disk-templates=%s" % non_lvm_template,
|
751 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % non_lvm_template,
|
752 | 912737ba | Helga Velroyen | "--vg-name="],
|
753 | 912737ba | Helga Velroyen | fail=False)
|
754 | 912737ba | Helga Velroyen | |
755 | 912737ba | Helga Velroyen | _RestoreEnabledDiskTemplates() |
756 | 912737ba | Helga Velroyen | |
757 | 462f0faa | Helga Velroyen | |
758 | 462f0faa | Helga Velroyen | def _TestClusterModifyUsedDiskTemplate(instance_template, |
759 | 462f0faa | Helga Velroyen | enabled_disk_templates): |
760 | 462f0faa | Helga Velroyen | """Tests that disk templates that are currently in use by instances cannot
|
761 | 462f0faa | Helga Velroyen | be disabled on the cluster.
|
762 | 462f0faa | Helga Velroyen |
|
763 | 462f0faa | Helga Velroyen | """
|
764 | 462f0faa | Helga Velroyen | # If the list of enabled disk templates contains only one template
|
765 | 462f0faa | Helga Velroyen | # we need to add some other templates, because the list of enabled disk
|
766 | 462f0faa | Helga Velroyen | # templates can only be set to a non-empty list.
|
767 | 462f0faa | Helga Velroyen | new_disk_templates = list(set(enabled_disk_templates) |
768 | 462f0faa | Helga Velroyen | - set([instance_template]))
|
769 | 462f0faa | Helga Velroyen | if not new_disk_templates: |
770 | d101b7be | Thomas Thrainer | new_disk_templates = list(set([constants.DT_DISKLESS, constants.DT_BLOCK]) |
771 | 462f0faa | Helga Velroyen | - set([instance_template]))
|
772 | 462f0faa | Helga Velroyen | AssertCommand( |
773 | 462f0faa | Helga Velroyen | ["gnt-cluster", "modify", |
774 | eb161df2 | Helga Velroyen | "--enabled-disk-templates=%s" % ",".join(new_disk_templates), |
775 | eb161df2 | Helga Velroyen | "--ipolicy-disk-templates=%s" % ",".join(new_disk_templates)], |
776 | 462f0faa | Helga Velroyen | fail=True)
|
777 | 462f0faa | Helga Velroyen | |
778 | 462f0faa | Helga Velroyen | |
779 | 9738ca94 | Iustin Pop | def TestClusterModifyBe(): |
780 | 9738ca94 | Iustin Pop | """gnt-cluster modify -B"""
|
781 | 2f4b4f78 | Iustin Pop | for fail, cmd in [ |
782 | 8ccbbe4b | Guido Trotter | # max/min mem
|
783 | 8ccbbe4b | Guido Trotter | (False, ["gnt-cluster", "modify", "-B", "maxmem=256"]), |
784 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *maxmem: 256$'"]), |
785 | 8ccbbe4b | Guido Trotter | (False, ["gnt-cluster", "modify", "-B", "minmem=256"]), |
786 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *minmem: 256$'"]), |
787 | 8ccbbe4b | Guido Trotter | (True, ["gnt-cluster", "modify", "-B", "maxmem=a"]), |
788 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *maxmem: 256$'"]), |
789 | 8ccbbe4b | Guido Trotter | (True, ["gnt-cluster", "modify", "-B", "minmem=a"]), |
790 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *minmem: 256$'"]), |
791 | 8ccbbe4b | Guido Trotter | (False, ["gnt-cluster", "modify", "-B", "maxmem=128,minmem=128"]), |
792 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *maxmem: 128$'"]), |
793 | 8ccbbe4b | Guido Trotter | (False, ["sh", "-c", "gnt-cluster info|grep '^ *minmem: 128$'"]), |
794 | 9738ca94 | Iustin Pop | # vcpus
|
795 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "-B", "vcpus=4"]), |
796 | 2f4b4f78 | Iustin Pop | (False, ["sh", "-c", "gnt-cluster info|grep '^ *vcpus: 4$'"]), |
797 | 21bf2e2e | Andrea Spadaccini | (True, ["gnt-cluster", "modify", "-B", "vcpus=a"]), |
798 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "-B", "vcpus=1"]), |
799 | 2f4b4f78 | Iustin Pop | (False, ["sh", "-c", "gnt-cluster info|grep '^ *vcpus: 1$'"]), |
800 | 9738ca94 | Iustin Pop | # auto_balance
|
801 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "-B", "auto_balance=False"]), |
802 | 2f4b4f78 | Iustin Pop | (False, ["sh", "-c", "gnt-cluster info|grep '^ *auto_balance: False$'"]), |
803 | 21bf2e2e | Andrea Spadaccini | (True, ["gnt-cluster", "modify", "-B", "auto_balance=1"]), |
804 | 2f4b4f78 | Iustin Pop | (False, ["gnt-cluster", "modify", "-B", "auto_balance=True"]), |
805 | 2f4b4f78 | Iustin Pop | (False, ["sh", "-c", "gnt-cluster info|grep '^ *auto_balance: True$'"]), |
806 | 9738ca94 | Iustin Pop | ]: |
807 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, fail=fail) |
808 | 9738ca94 | Iustin Pop | |
809 | 5abecc1c | Iustin Pop | # redo the original-requested BE parameters, if any
|
810 | 5abecc1c | Iustin Pop | bep = qa_config.get("backend-parameters", "") |
811 | 5abecc1c | Iustin Pop | if bep:
|
812 | 5abecc1c | Iustin Pop | AssertCommand(["gnt-cluster", "modify", "-B", bep]) |
813 | 9738ca94 | Iustin Pop | |
814 | 21bf2e2e | Andrea Spadaccini | |
815 | b3f3aa3d | Bernardo Dal Seno | def _GetClusterIPolicy(): |
816 | b3f3aa3d | Bernardo Dal Seno | """Return the run-time values of the cluster-level instance policy.
|
817 | b3f3aa3d | Bernardo Dal Seno |
|
818 | b3f3aa3d | Bernardo Dal Seno | @rtype: tuple
|
819 | b3f3aa3d | Bernardo Dal Seno | @return: (policy, specs), where:
|
820 | b3f3aa3d | Bernardo Dal Seno | - policy is a dictionary of the policy values, instance specs excluded
|
821 | 7c8ae421 | Bernardo Dal Seno | - specs is a dictionary containing only the specs, using the internal
|
822 | 7c8ae421 | Bernardo Dal Seno | format (see L{constants.IPOLICY_DEFAULTS} for an example)
|
823 | b3f3aa3d | Bernardo Dal Seno |
|
824 | b3f3aa3d | Bernardo Dal Seno | """
|
825 | 0e79564a | Bernardo Dal Seno | info = qa_utils.GetObjectInfo(["gnt-cluster", "info"]) |
826 | 0e79564a | Bernardo Dal Seno | policy = info["Instance policy - limits for instances"]
|
827 | 63e08b25 | Bernardo Dal Seno | (ret_policy, ret_specs) = qa_utils.ParseIPolicy(policy) |
828 | 0e79564a | Bernardo Dal Seno | |
829 | b3f3aa3d | Bernardo Dal Seno | # Sanity checks
|
830 | 7c8ae421 | Bernardo Dal Seno | assert "minmax" in ret_specs and "std" in ret_specs |
831 | 7c8ae421 | Bernardo Dal Seno | assert len(ret_specs["minmax"]) > 0 |
832 | 0e79564a | Bernardo Dal Seno | assert len(ret_policy) > 0 |
833 | 0e79564a | Bernardo Dal Seno | return (ret_policy, ret_specs)
|
834 | b3f3aa3d | Bernardo Dal Seno | |
835 | b3f3aa3d | Bernardo Dal Seno | |
836 | b3f3aa3d | Bernardo Dal Seno | def TestClusterModifyIPolicy(): |
837 | b3f3aa3d | Bernardo Dal Seno | """gnt-cluster modify --ipolicy-*"""
|
838 | b3f3aa3d | Bernardo Dal Seno | basecmd = ["gnt-cluster", "modify"] |
839 | b3f3aa3d | Bernardo Dal Seno | (old_policy, old_specs) = _GetClusterIPolicy() |
840 | b3f3aa3d | Bernardo Dal Seno | for par in ["vcpu-ratio", "spindle-ratio"]: |
841 | b3f3aa3d | Bernardo Dal Seno | curr_val = float(old_policy[par])
|
842 | b3f3aa3d | Bernardo Dal Seno | test_values = [ |
843 | b3f3aa3d | Bernardo Dal Seno | (True, 1.0), |
844 | b3f3aa3d | Bernardo Dal Seno | (True, 1.5), |
845 | b3f3aa3d | Bernardo Dal Seno | (True, 2), |
846 | b3f3aa3d | Bernardo Dal Seno | (False, "a"), |
847 | b3f3aa3d | Bernardo Dal Seno | # Restore the old value
|
848 | b3f3aa3d | Bernardo Dal Seno | (True, curr_val),
|
849 | b3f3aa3d | Bernardo Dal Seno | ] |
850 | b3f3aa3d | Bernardo Dal Seno | for (good, val) in test_values: |
851 | b3f3aa3d | Bernardo Dal Seno | cmd = basecmd + ["--ipolicy-%s=%s" % (par, val)]
|
852 | b3f3aa3d | Bernardo Dal Seno | AssertCommand(cmd, fail=not good)
|
853 | b3f3aa3d | Bernardo Dal Seno | if good:
|
854 | b3f3aa3d | Bernardo Dal Seno | curr_val = val |
855 | b3f3aa3d | Bernardo Dal Seno | # Check the affected parameter
|
856 | b3f3aa3d | Bernardo Dal Seno | (eff_policy, eff_specs) = _GetClusterIPolicy() |
857 | b3f3aa3d | Bernardo Dal Seno | AssertEqual(float(eff_policy[par]), curr_val)
|
858 | b3f3aa3d | Bernardo Dal Seno | # Check everything else
|
859 | b3f3aa3d | Bernardo Dal Seno | AssertEqual(eff_specs, old_specs) |
860 | b3f3aa3d | Bernardo Dal Seno | for p in eff_policy.keys(): |
861 | b3f3aa3d | Bernardo Dal Seno | if p == par:
|
862 | b3f3aa3d | Bernardo Dal Seno | continue
|
863 | b3f3aa3d | Bernardo Dal Seno | AssertEqual(eff_policy[p], old_policy[p]) |
864 | b3f3aa3d | Bernardo Dal Seno | |
865 | ae3ab08b | Helga Velroyen | # Allowing disk templates via ipolicy requires them to be
|
866 | ae3ab08b | Helga Velroyen | # enabled on the cluster.
|
867 | ae3ab08b | Helga Velroyen | if not (qa_config.IsTemplateSupported(constants.DT_PLAIN) |
868 | ae3ab08b | Helga Velroyen | and qa_config.IsTemplateSupported(constants.DT_DRBD8)):
|
869 | ae3ab08b | Helga Velroyen | return
|
870 | b3f3aa3d | Bernardo Dal Seno | # Disk templates are treated slightly differently
|
871 | b3f3aa3d | Bernardo Dal Seno | par = "disk-templates"
|
872 | 9db0b351 | Bernardo Dal Seno | disp_str = "allowed disk templates"
|
873 | b3f3aa3d | Bernardo Dal Seno | curr_val = old_policy[disp_str] |
874 | b3f3aa3d | Bernardo Dal Seno | test_values = [ |
875 | b3f3aa3d | Bernardo Dal Seno | (True, constants.DT_PLAIN),
|
876 | b3f3aa3d | Bernardo Dal Seno | (True, "%s,%s" % (constants.DT_PLAIN, constants.DT_DRBD8)), |
877 | b3f3aa3d | Bernardo Dal Seno | (False, "thisisnotadisktemplate"), |
878 | b3f3aa3d | Bernardo Dal Seno | (False, ""), |
879 | b3f3aa3d | Bernardo Dal Seno | # Restore the old value
|
880 | b3f3aa3d | Bernardo Dal Seno | (True, curr_val.replace(" ", "")), |
881 | b3f3aa3d | Bernardo Dal Seno | ] |
882 | b3f3aa3d | Bernardo Dal Seno | for (good, val) in test_values: |
883 | b3f3aa3d | Bernardo Dal Seno | cmd = basecmd + ["--ipolicy-%s=%s" % (par, val)]
|
884 | b3f3aa3d | Bernardo Dal Seno | AssertCommand(cmd, fail=not good)
|
885 | b3f3aa3d | Bernardo Dal Seno | if good:
|
886 | b3f3aa3d | Bernardo Dal Seno | curr_val = val |
887 | b3f3aa3d | Bernardo Dal Seno | # Check the affected parameter
|
888 | b3f3aa3d | Bernardo Dal Seno | (eff_policy, eff_specs) = _GetClusterIPolicy() |
889 | b3f3aa3d | Bernardo Dal Seno | AssertEqual(eff_policy[disp_str].replace(" ", ""), curr_val) |
890 | b3f3aa3d | Bernardo Dal Seno | # Check everything else
|
891 | b3f3aa3d | Bernardo Dal Seno | AssertEqual(eff_specs, old_specs) |
892 | b3f3aa3d | Bernardo Dal Seno | for p in eff_policy.keys(): |
893 | b3f3aa3d | Bernardo Dal Seno | if p == disp_str:
|
894 | b3f3aa3d | Bernardo Dal Seno | continue
|
895 | b3f3aa3d | Bernardo Dal Seno | AssertEqual(eff_policy[p], old_policy[p]) |
896 | b3f3aa3d | Bernardo Dal Seno | |
897 | b3f3aa3d | Bernardo Dal Seno | |
898 | ec996117 | Bernardo Dal Seno | def TestClusterSetISpecs(new_specs=None, diff_specs=None, fail=False, |
899 | ec996117 | Bernardo Dal Seno | old_values=None):
|
900 | b3f3aa3d | Bernardo Dal Seno | """Change instance specs.
|
901 | b3f3aa3d | Bernardo Dal Seno |
|
902 | ec996117 | Bernardo Dal Seno | At most one of new_specs or diff_specs can be specified.
|
903 | ec996117 | Bernardo Dal Seno |
|
904 | ec996117 | Bernardo Dal Seno | @type new_specs: dict
|
905 | ec996117 | Bernardo Dal Seno | @param new_specs: new complete specs, in the same format returned by
|
906 | ec996117 | Bernardo Dal Seno | L{_GetClusterIPolicy}
|
907 | ec996117 | Bernardo Dal Seno | @type diff_specs: dict
|
908 | 7c8ae421 | Bernardo Dal Seno | @param diff_specs: partial specs, it can be an incomplete specifications, but
|
909 | 7c8ae421 | Bernardo Dal Seno | if min/max specs are specified, their number must match the number of the
|
910 | 7c8ae421 | Bernardo Dal Seno | existing specs
|
911 | b3f3aa3d | Bernardo Dal Seno | @type fail: bool
|
912 | b3f3aa3d | Bernardo Dal Seno | @param fail: if the change is expected to fail
|
913 | b3f3aa3d | Bernardo Dal Seno | @type old_values: tuple
|
914 | b3f3aa3d | Bernardo Dal Seno | @param old_values: (old_policy, old_specs), as returned by
|
915 | ec996117 | Bernardo Dal Seno | L{_GetClusterIPolicy}
|
916 | b3f3aa3d | Bernardo Dal Seno | @return: same as L{_GetClusterIPolicy}
|
917 | b3f3aa3d | Bernardo Dal Seno |
|
918 | b3f3aa3d | Bernardo Dal Seno | """
|
919 | 63e08b25 | Bernardo Dal Seno | build_cmd = lambda opts: ["gnt-cluster", "modify"] + opts |
920 | ec996117 | Bernardo Dal Seno | return qa_utils.TestSetISpecs(
|
921 | ec996117 | Bernardo Dal Seno | new_specs=new_specs, diff_specs=diff_specs, |
922 | ec996117 | Bernardo Dal Seno | get_policy_fn=_GetClusterIPolicy, build_cmd_fn=build_cmd, |
923 | ec996117 | Bernardo Dal Seno | fail=fail, old_values=old_values) |
924 | b3f3aa3d | Bernardo Dal Seno | |
925 | b3f3aa3d | Bernardo Dal Seno | |
926 | b3f3aa3d | Bernardo Dal Seno | def TestClusterModifyISpecs(): |
927 | b3f3aa3d | Bernardo Dal Seno | """gnt-cluster modify --specs-*"""
|
928 | cb178a1e | Bernardo Dal Seno | params = ["memory-size", "disk-size", "disk-count", "cpu-count", "nic-count"] |
929 | b3f3aa3d | Bernardo Dal Seno | (cur_policy, cur_specs) = _GetClusterIPolicy() |
930 | 7c8ae421 | Bernardo Dal Seno | # This test assumes that there is only one min/max bound
|
931 | 7c8ae421 | Bernardo Dal Seno | assert len(cur_specs[constants.ISPECS_MINMAX]) == 1 |
932 | b3f3aa3d | Bernardo Dal Seno | for par in params: |
933 | b3f3aa3d | Bernardo Dal Seno | test_values = [ |
934 | b3f3aa3d | Bernardo Dal Seno | (True, 0, 4, 12), |
935 | b3f3aa3d | Bernardo Dal Seno | (True, 4, 4, 12), |
936 | b3f3aa3d | Bernardo Dal Seno | (True, 4, 12, 12), |
937 | b3f3aa3d | Bernardo Dal Seno | (True, 4, 4, 4), |
938 | b3f3aa3d | Bernardo Dal Seno | (False, 4, 0, 12), |
939 | b3f3aa3d | Bernardo Dal Seno | (False, 4, 16, 12), |
940 | b3f3aa3d | Bernardo Dal Seno | (False, 4, 4, 0), |
941 | b3f3aa3d | Bernardo Dal Seno | (False, 12, 4, 4), |
942 | b3f3aa3d | Bernardo Dal Seno | (False, 12, 4, 0), |
943 | b3f3aa3d | Bernardo Dal Seno | (False, "a", 4, 12), |
944 | b3f3aa3d | Bernardo Dal Seno | (False, 0, "a", 12), |
945 | b3f3aa3d | Bernardo Dal Seno | (False, 0, 4, "a"), |
946 | b3f3aa3d | Bernardo Dal Seno | # This is to restore the old values
|
947 | b3f3aa3d | Bernardo Dal Seno | (True,
|
948 | 7c8ae421 | Bernardo Dal Seno | cur_specs[constants.ISPECS_MINMAX][0][constants.ISPECS_MIN][par],
|
949 | 7c8ae421 | Bernardo Dal Seno | cur_specs[constants.ISPECS_STD][par], |
950 | 7c8ae421 | Bernardo Dal Seno | cur_specs[constants.ISPECS_MINMAX][0][constants.ISPECS_MAX][par])
|
951 | b3f3aa3d | Bernardo Dal Seno | ] |
952 | b3f3aa3d | Bernardo Dal Seno | for (good, mn, st, mx) in test_values: |
953 | ec996117 | Bernardo Dal Seno | new_vals = { |
954 | 7c8ae421 | Bernardo Dal Seno | constants.ISPECS_MINMAX: [{ |
955 | 7c8ae421 | Bernardo Dal Seno | constants.ISPECS_MIN: {par: mn}, |
956 | 7c8ae421 | Bernardo Dal Seno | constants.ISPECS_MAX: {par: mx} |
957 | 7c8ae421 | Bernardo Dal Seno | }], |
958 | 7c8ae421 | Bernardo Dal Seno | constants.ISPECS_STD: {par: st} |
959 | ec996117 | Bernardo Dal Seno | } |
960 | b3f3aa3d | Bernardo Dal Seno | cur_state = (cur_policy, cur_specs) |
961 | b3f3aa3d | Bernardo Dal Seno | # We update cur_specs, as we've copied the values to restore already
|
962 | ec996117 | Bernardo Dal Seno | (cur_policy, cur_specs) = TestClusterSetISpecs( |
963 | ec996117 | Bernardo Dal Seno | diff_specs=new_vals, fail=not good, old_values=cur_state)
|
964 | b3f3aa3d | Bernardo Dal Seno | |
965 | b5a93c73 | Bernardo Dal Seno | # Get the ipolicy command
|
966 | b5a93c73 | Bernardo Dal Seno | mnode = qa_config.GetMasterNode() |
967 | b5a93c73 | Bernardo Dal Seno | initcmd = GetCommandOutput(mnode.primary, "gnt-cluster show-ispecs-cmd")
|
968 | b5a93c73 | Bernardo Dal Seno | modcmd = ["gnt-cluster", "modify"] |
969 | b5a93c73 | Bernardo Dal Seno | opts = initcmd.split() |
970 | b5a93c73 | Bernardo Dal Seno | assert opts[0:2] == ["gnt-cluster", "init"] |
971 | b5a93c73 | Bernardo Dal Seno | for k in range(2, len(opts) - 1): |
972 | b5a93c73 | Bernardo Dal Seno | if opts[k].startswith("--ipolicy-"): |
973 | b5a93c73 | Bernardo Dal Seno | assert k + 2 <= len(opts) |
974 | b5a93c73 | Bernardo Dal Seno | modcmd.extend(opts[k:k + 2])
|
975 | b5a93c73 | Bernardo Dal Seno | # Re-apply the ipolicy (this should be a no-op)
|
976 | b5a93c73 | Bernardo Dal Seno | AssertCommand(modcmd) |
977 | b5a93c73 | Bernardo Dal Seno | new_initcmd = GetCommandOutput(mnode.primary, "gnt-cluster show-ispecs-cmd")
|
978 | b5a93c73 | Bernardo Dal Seno | AssertEqual(initcmd, new_initcmd) |
979 | b3f3aa3d | Bernardo Dal Seno | |
980 | b3f3aa3d | Bernardo Dal Seno | |
981 | cec9845c | Michael Hanselmann | def TestClusterInfo(): |
982 | cec9845c | Michael Hanselmann | """gnt-cluster info"""
|
983 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "info"]) |
984 | 283f9d4c | Michael Hanselmann | |
985 | 283f9d4c | Michael Hanselmann | |
986 | 3e8b5a9c | Iustin Pop | def TestClusterRedistConf(): |
987 | 3e8b5a9c | Iustin Pop | """gnt-cluster redist-conf"""
|
988 | 3e8b5a9c | Iustin Pop | AssertCommand(["gnt-cluster", "redist-conf"]) |
989 | 3e8b5a9c | Iustin Pop | |
990 | 3e8b5a9c | Iustin Pop | |
991 | 283f9d4c | Michael Hanselmann | def TestClusterGetmaster(): |
992 | 283f9d4c | Michael Hanselmann | """gnt-cluster getmaster"""
|
993 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "getmaster"]) |
994 | 283f9d4c | Michael Hanselmann | |
995 | 283f9d4c | Michael Hanselmann | |
996 | 283f9d4c | Michael Hanselmann | def TestClusterVersion(): |
997 | 283f9d4c | Michael Hanselmann | """gnt-cluster version"""
|
998 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "version"]) |
999 | cec9845c | Michael Hanselmann | |
1000 | cec9845c | Michael Hanselmann | |
1001 | 6d4a1656 | Michael Hanselmann | def TestClusterRenewCrypto(): |
1002 | 6d4a1656 | Michael Hanselmann | """gnt-cluster renew-crypto"""
|
1003 | 6d4a1656 | Michael Hanselmann | master = qa_config.GetMasterNode() |
1004 | 6d4a1656 | Michael Hanselmann | |
1005 | 6d4a1656 | Michael Hanselmann | # Conflicting options
|
1006 | 6d4a1656 | Michael Hanselmann | cmd = ["gnt-cluster", "renew-crypto", "--force", |
1007 | 3db3eb2a | Michael Hanselmann | "--new-cluster-certificate", "--new-confd-hmac-key"] |
1008 | 3db3eb2a | Michael Hanselmann | conflicting = [ |
1009 | 3db3eb2a | Michael Hanselmann | ["--new-rapi-certificate", "--rapi-certificate=/dev/null"], |
1010 | 3db3eb2a | Michael Hanselmann | ["--new-cluster-domain-secret", "--cluster-domain-secret=/dev/null"], |
1011 | 3db3eb2a | Michael Hanselmann | ] |
1012 | 3db3eb2a | Michael Hanselmann | for i in conflicting: |
1013 | 21bf2e2e | Andrea Spadaccini | AssertCommand(cmd + i, fail=True)
|
1014 | 6d4a1656 | Michael Hanselmann | |
1015 | 6d4a1656 | Michael Hanselmann | # Invalid RAPI certificate
|
1016 | 6d4a1656 | Michael Hanselmann | cmd = ["gnt-cluster", "renew-crypto", "--force", |
1017 | 6d4a1656 | Michael Hanselmann | "--rapi-certificate=/dev/null"]
|
1018 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, fail=True)
|
1019 | 6d4a1656 | Michael Hanselmann | |
1020 | aecba21e | Michael Hanselmann | rapi_cert_backup = qa_utils.BackupFile(master.primary, |
1021 | 304d9f02 | Michael Hanselmann | pathutils.RAPI_CERT_FILE) |
1022 | 502f5236 | Michael Hanselmann | try:
|
1023 | 502f5236 | Michael Hanselmann | # Custom RAPI certificate
|
1024 | 502f5236 | Michael Hanselmann | fh = tempfile.NamedTemporaryFile() |
1025 | 6d4a1656 | Michael Hanselmann | |
1026 | 502f5236 | Michael Hanselmann | # Ensure certificate doesn't cause "gnt-cluster verify" to complain
|
1027 | 502f5236 | Michael Hanselmann | validity = constants.SSL_CERT_EXPIRATION_WARN * 3
|
1028 | 6d4a1656 | Michael Hanselmann | |
1029 | 5e26633b | Michael Hanselmann | utils.GenerateSelfSignedSslCert(fh.name, validity=validity) |
1030 | 6d4a1656 | Michael Hanselmann | |
1031 | aecba21e | Michael Hanselmann | tmpcert = qa_utils.UploadFile(master.primary, fh.name) |
1032 | 502f5236 | Michael Hanselmann | try:
|
1033 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
1034 | 2f4b4f78 | Iustin Pop | "--rapi-certificate=%s" % tmpcert])
|
1035 | 502f5236 | Michael Hanselmann | finally:
|
1036 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", tmpcert]) |
1037 | 502f5236 | Michael Hanselmann | |
1038 | 5e26633b | Michael Hanselmann | # Custom cluster domain secret
|
1039 | 5e26633b | Michael Hanselmann | cds_fh = tempfile.NamedTemporaryFile() |
1040 | 5e26633b | Michael Hanselmann | cds_fh.write(utils.GenerateSecret()) |
1041 | 5e26633b | Michael Hanselmann | cds_fh.write("\n")
|
1042 | 5e26633b | Michael Hanselmann | cds_fh.flush() |
1043 | 5e26633b | Michael Hanselmann | |
1044 | aecba21e | Michael Hanselmann | tmpcds = qa_utils.UploadFile(master.primary, cds_fh.name) |
1045 | 5e26633b | Michael Hanselmann | try:
|
1046 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
1047 | 2f4b4f78 | Iustin Pop | "--cluster-domain-secret=%s" % tmpcds])
|
1048 | 5e26633b | Michael Hanselmann | finally:
|
1049 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", tmpcds]) |
1050 | 5e26633b | Michael Hanselmann | |
1051 | 502f5236 | Michael Hanselmann | # Normal case
|
1052 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
1053 | 2f4b4f78 | Iustin Pop | "--new-cluster-certificate", "--new-confd-hmac-key", |
1054 | 2f4b4f78 | Iustin Pop | "--new-rapi-certificate", "--new-cluster-domain-secret"]) |
1055 | 3db3eb2a | Michael Hanselmann | |
1056 | 502f5236 | Michael Hanselmann | # Restore RAPI certificate
|
1057 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
1058 | 2f4b4f78 | Iustin Pop | "--rapi-certificate=%s" % rapi_cert_backup])
|
1059 | 3db3eb2a | Michael Hanselmann | finally:
|
1060 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", rapi_cert_backup]) |
1061 | 3db3eb2a | Michael Hanselmann | |
1062 | 6d4a1656 | Michael Hanselmann | |
1063 | cec9845c | Michael Hanselmann | def TestClusterBurnin(): |
1064 | cec9845c | Michael Hanselmann | """Burnin"""
|
1065 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
1066 | cec9845c | Michael Hanselmann | |
1067 | d0c8c01d | Iustin Pop | options = qa_config.get("options", {})
|
1068 | 68c8c3df | Michael Hanselmann | disk_template = options.get("burnin-disk-template", constants.DT_DRBD8)
|
1069 | d0c8c01d | Iustin Pop | parallel = options.get("burnin-in-parallel", False) |
1070 | d0c8c01d | Iustin Pop | check_inst = options.get("burnin-check-instances", False) |
1071 | d0c8c01d | Iustin Pop | do_rename = options.get("burnin-rename", "") |
1072 | d0c8c01d | Iustin Pop | do_reboot = options.get("burnin-reboot", True) |
1073 | 1d103c02 | Iustin Pop | reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
|
1074 | 23103544 | Michael Hanselmann | |
1075 | cec9845c | Michael Hanselmann | # Get as many instances as we need
|
1076 | cec9845c | Michael Hanselmann | instances = [] |
1077 | cec9845c | Michael Hanselmann | try:
|
1078 | 23103544 | Michael Hanselmann | try:
|
1079 | d0c8c01d | Iustin Pop | num = qa_config.get("options", {}).get("burnin-instances", 1) |
1080 | f1501b3f | Michael Hanselmann | for _ in range(0, num): |
1081 | 23103544 | Michael Hanselmann | instances.append(qa_config.AcquireInstance()) |
1082 | 23103544 | Michael Hanselmann | except qa_error.OutOfInstancesError:
|
1083 | 23103544 | Michael Hanselmann | print "Not enough instances, continuing anyway." |
1084 | cec9845c | Michael Hanselmann | |
1085 | 23103544 | Michael Hanselmann | if len(instances) < 1: |
1086 | 23103544 | Michael Hanselmann | raise qa_error.Error("Burnin needs at least one instance") |
1087 | cec9845c | Michael Hanselmann | |
1088 | aecba21e | Michael Hanselmann | script = qa_utils.UploadFile(master.primary, "../tools/burnin")
|
1089 | cec9845c | Michael Hanselmann | try:
|
1090 | 090128b6 | Christos Stavrakakis | disks = qa_config.GetDiskOptions() |
1091 | 23103544 | Michael Hanselmann | # Run burnin
|
1092 | 5d9d1aff | Klaus Aehlig | cmd = ["env",
|
1093 | b8669a69 | Jose A. Lopes | "PYTHONPATH=%s" % _constants.VERSIONEDSHAREDIR,
|
1094 | 5d9d1aff | Klaus Aehlig | script, |
1095 | d0c8c01d | Iustin Pop | "--os=%s" % qa_config.get("os"), |
1096 | f356202a | Guido Trotter | "--minmem-size=%s" % qa_config.get(constants.BE_MINMEM),
|
1097 | f356202a | Guido Trotter | "--maxmem-size=%s" % qa_config.get(constants.BE_MAXMEM),
|
1098 | 090128b6 | Christos Stavrakakis | "--disk-size=%s" % ",".join([d.get("size") for d in disks]), |
1099 | 090128b6 | Christos Stavrakakis | "--disk-growth=%s" % ",".join([d.get("growth") for d in disks]), |
1100 | d0c8c01d | Iustin Pop | "--disk-template=%s" % disk_template]
|
1101 | 0b0a150a | Iustin Pop | if parallel:
|
1102 | d0c8c01d | Iustin Pop | cmd.append("--parallel")
|
1103 | d0c8c01d | Iustin Pop | cmd.append("--early-release")
|
1104 | 0b0a150a | Iustin Pop | if check_inst:
|
1105 | d0c8c01d | Iustin Pop | cmd.append("--http-check")
|
1106 | 4dc76b24 | Iustin Pop | if do_rename:
|
1107 | d0c8c01d | Iustin Pop | cmd.append("--rename=%s" % do_rename)
|
1108 | 58598264 | Iustin Pop | if not do_reboot: |
1109 | d0c8c01d | Iustin Pop | cmd.append("--no-reboot")
|
1110 | 1d103c02 | Iustin Pop | else:
|
1111 | d0c8c01d | Iustin Pop | cmd.append("--reboot-types=%s" % ",".join(reboot_types)) |
1112 | b5f33afa | Michael Hanselmann | cmd += [inst.name for inst in instances] |
1113 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
1114 | cec9845c | Michael Hanselmann | finally:
|
1115 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", script]) |
1116 | 2f4b4f78 | Iustin Pop | |
1117 | cec9845c | Michael Hanselmann | finally:
|
1118 | cec9845c | Michael Hanselmann | for inst in instances: |
1119 | 6f88e076 | Michael Hanselmann | inst.Release() |
1120 | cec9845c | Michael Hanselmann | |
1121 | cec9845c | Michael Hanselmann | |
1122 | cec9845c | Michael Hanselmann | def TestClusterMasterFailover(): |
1123 | c28502b1 | Iustin Pop | """gnt-cluster master-failover"""
|
1124 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
1125 | cec9845c | Michael Hanselmann | failovermaster = qa_config.AcquireNode(exclude=master) |
1126 | cec9845c | Michael Hanselmann | |
1127 | 2f4b4f78 | Iustin Pop | cmd = ["gnt-cluster", "master-failover"] |
1128 | c9e52e4c | Helga Velroyen | node_list_cmd = ["gnt-node", "list"] |
1129 | 2f4b4f78 | Iustin Pop | try:
|
1130 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, node=failovermaster) |
1131 | c9e52e4c | Helga Velroyen | AssertCommand(node_list_cmd, node=failovermaster) |
1132 | ff699aa9 | Michael Hanselmann | # Back to original master node
|
1133 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd, node=master) |
1134 | c9e52e4c | Helga Velroyen | AssertCommand(node_list_cmd, node=master) |
1135 | cec9845c | Michael Hanselmann | finally:
|
1136 | 565cb4bf | Michael Hanselmann | failovermaster.Release() |
1137 | cec9845c | Michael Hanselmann | |
1138 | cec9845c | Michael Hanselmann | |
1139 | aa104b5e | Klaus Aehlig | def TestUpgrade(): |
1140 | aa104b5e | Klaus Aehlig | """Test gnt-cluster upgrade.
|
1141 | aa104b5e | Klaus Aehlig |
|
1142 | aa104b5e | Klaus Aehlig | This tests the 'gnt-cluster upgrade' command by flipping
|
1143 | aa104b5e | Klaus Aehlig | between the current and a different version of Ganeti.
|
1144 | aa104b5e | Klaus Aehlig | To also recover subtile points in the configuration up/down
|
1145 | aa104b5e | Klaus Aehlig | grades, instances are left over both upgrades.
|
1146 | aa104b5e | Klaus Aehlig |
|
1147 | aa104b5e | Klaus Aehlig | """
|
1148 | aa104b5e | Klaus Aehlig | this_version = qa_config.get("dir-version")
|
1149 | aa104b5e | Klaus Aehlig | other_version = qa_config.get("other-dir-version")
|
1150 | aa104b5e | Klaus Aehlig | if this_version is None or other_version is None: |
1151 | aa104b5e | Klaus Aehlig | print qa_utils.FormatInfo("Test not run, as versions not specified") |
1152 | aa104b5e | Klaus Aehlig | return
|
1153 | aa104b5e | Klaus Aehlig | |
1154 | aa104b5e | Klaus Aehlig | inst_creates = [] |
1155 | aa104b5e | Klaus Aehlig | upgrade_instances = qa_config.get("upgrade-instances", [])
|
1156 | aa104b5e | Klaus Aehlig | live_instances = [] |
1157 | aa104b5e | Klaus Aehlig | for (test_name, templ, cf, n) in qa_instance.available_instance_tests: |
1158 | aa104b5e | Klaus Aehlig | if (qa_config.TestEnabled(test_name) and |
1159 | aa104b5e | Klaus Aehlig | qa_config.IsTemplateSupported(templ) and
|
1160 | aa104b5e | Klaus Aehlig | templ in upgrade_instances):
|
1161 | aa104b5e | Klaus Aehlig | inst_creates.append((cf, n)) |
1162 | 9c3dcbbf | Klaus Aehlig | |
1163 | aa104b5e | Klaus Aehlig | for (cf, n) in inst_creates: |
1164 | aa104b5e | Klaus Aehlig | nodes = qa_config.AcquireManyNodes(n) |
1165 | aa104b5e | Klaus Aehlig | live_instances.append(cf(nodes)) |
1166 | aa104b5e | Klaus Aehlig | |
1167 | aa104b5e | Klaus Aehlig | AssertCommand(["gnt-cluster", "upgrade", "--to", other_version]) |
1168 | aa104b5e | Klaus Aehlig | AssertCommand(["gnt-cluster", "verify"]) |
1169 | aa104b5e | Klaus Aehlig | |
1170 | aa104b5e | Klaus Aehlig | for instance in live_instances: |
1171 | aa104b5e | Klaus Aehlig | qa_instance.TestInstanceRemove(instance) |
1172 | aa104b5e | Klaus Aehlig | instance.Release() |
1173 | aa104b5e | Klaus Aehlig | live_instances = [] |
1174 | aa104b5e | Klaus Aehlig | for (cf, n) in inst_creates: |
1175 | aa104b5e | Klaus Aehlig | nodes = qa_config.AcquireManyNodes(n) |
1176 | aa104b5e | Klaus Aehlig | live_instances.append(cf(nodes)) |
1177 | aa104b5e | Klaus Aehlig | |
1178 | aa104b5e | Klaus Aehlig | AssertCommand(["gnt-cluster", "upgrade", "--to", this_version]) |
1179 | aa104b5e | Klaus Aehlig | AssertCommand(["gnt-cluster", "verify"]) |
1180 | aa104b5e | Klaus Aehlig | |
1181 | aa104b5e | Klaus Aehlig | for instance in live_instances: |
1182 | aa104b5e | Klaus Aehlig | qa_instance.TestInstanceRemove(instance) |
1183 | aa104b5e | Klaus Aehlig | instance.Release() |
1184 | aa104b5e | Klaus Aehlig | |
1185 | d80e2abe | Santi Raffa | |
1186 | 2df92990 | Michael Hanselmann | def _NodeQueueDrainFile(node): |
1187 | 2df92990 | Michael Hanselmann | """Returns path to queue drain file for a node.
|
1188 | 2df92990 | Michael Hanselmann |
|
1189 | 2df92990 | Michael Hanselmann | """
|
1190 | 2df92990 | Michael Hanselmann | return qa_utils.MakeNodePath(node, pathutils.JOB_QUEUE_DRAIN_FILE)
|
1191 | 2df92990 | Michael Hanselmann | |
1192 | 2df92990 | Michael Hanselmann | |
1193 | 2df92990 | Michael Hanselmann | def _AssertDrainFile(node, **kwargs): |
1194 | 2df92990 | Michael Hanselmann | """Checks for the queue drain file.
|
1195 | 2df92990 | Michael Hanselmann |
|
1196 | 2df92990 | Michael Hanselmann | """
|
1197 | 2df92990 | Michael Hanselmann | AssertCommand(["test", "-f", _NodeQueueDrainFile(node)], node=node, **kwargs) |
1198 | 2df92990 | Michael Hanselmann | |
1199 | 2df92990 | Michael Hanselmann | |
1200 | ff699aa9 | Michael Hanselmann | def TestClusterMasterFailoverWithDrainedQueue(): |
1201 | ff699aa9 | Michael Hanselmann | """gnt-cluster master-failover with drained queue"""
|
1202 | ff699aa9 | Michael Hanselmann | master = qa_config.GetMasterNode() |
1203 | ff699aa9 | Michael Hanselmann | failovermaster = qa_config.AcquireNode(exclude=master) |
1204 | ff699aa9 | Michael Hanselmann | |
1205 | ff699aa9 | Michael Hanselmann | # Ensure queue is not drained
|
1206 | ff699aa9 | Michael Hanselmann | for node in [master, failovermaster]: |
1207 | 2df92990 | Michael Hanselmann | _AssertDrainFile(node, fail=True)
|
1208 | ff699aa9 | Michael Hanselmann | |
1209 | ff699aa9 | Michael Hanselmann | # Drain queue on failover master
|
1210 | 2df92990 | Michael Hanselmann | AssertCommand(["touch", _NodeQueueDrainFile(failovermaster)],
|
1211 | 2df92990 | Michael Hanselmann | node=failovermaster) |
1212 | ff699aa9 | Michael Hanselmann | |
1213 | ff699aa9 | Michael Hanselmann | cmd = ["gnt-cluster", "master-failover"] |
1214 | ff699aa9 | Michael Hanselmann | try:
|
1215 | 2df92990 | Michael Hanselmann | _AssertDrainFile(failovermaster) |
1216 | ff699aa9 | Michael Hanselmann | AssertCommand(cmd, node=failovermaster) |
1217 | 2df92990 | Michael Hanselmann | _AssertDrainFile(master, fail=True)
|
1218 | 2df92990 | Michael Hanselmann | _AssertDrainFile(failovermaster, fail=True)
|
1219 | ff699aa9 | Michael Hanselmann | |
1220 | ff699aa9 | Michael Hanselmann | # Back to original master node
|
1221 | ff699aa9 | Michael Hanselmann | AssertCommand(cmd, node=master) |
1222 | ff699aa9 | Michael Hanselmann | finally:
|
1223 | 565cb4bf | Michael Hanselmann | failovermaster.Release() |
1224 | ff699aa9 | Michael Hanselmann | |
1225 | 2df92990 | Michael Hanselmann | # Ensure queue is not drained
|
1226 | 2df92990 | Michael Hanselmann | for node in [master, failovermaster]: |
1227 | 2df92990 | Michael Hanselmann | _AssertDrainFile(node, fail=True)
|
1228 | ff699aa9 | Michael Hanselmann | |
1229 | ff699aa9 | Michael Hanselmann | |
1230 | cec9845c | Michael Hanselmann | def TestClusterCopyfile(): |
1231 | cec9845c | Michael Hanselmann | """gnt-cluster copyfile"""
|
1232 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
1233 | cec9845c | Michael Hanselmann | |
1234 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
1235 | 830da270 | Michael Hanselmann | |
1236 | cec9845c | Michael Hanselmann | # Create temporary file
|
1237 | cec9845c | Michael Hanselmann | f = tempfile.NamedTemporaryFile() |
1238 | 830da270 | Michael Hanselmann | f.write(uniqueid) |
1239 | cec9845c | Michael Hanselmann | f.flush() |
1240 | cec9845c | Michael Hanselmann | f.seek(0)
|
1241 | cec9845c | Michael Hanselmann | |
1242 | cec9845c | Michael Hanselmann | # Upload file to master node
|
1243 | aecba21e | Michael Hanselmann | testname = qa_utils.UploadFile(master.primary, f.name) |
1244 | cec9845c | Michael Hanselmann | try:
|
1245 | cec9845c | Michael Hanselmann | # Copy file to all nodes
|
1246 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "copyfile", testname]) |
1247 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(testname, uniqueid) |
1248 | cec9845c | Michael Hanselmann | finally:
|
1249 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(testname) |
1250 | 830da270 | Michael Hanselmann | |
1251 | 830da270 | Michael Hanselmann | |
1252 | 830da270 | Michael Hanselmann | def TestClusterCommand(): |
1253 | 830da270 | Michael Hanselmann | """gnt-cluster command"""
|
1254 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
1255 | 24818e8f | Michael Hanselmann | rfile = "/tmp/gnt%s" % utils.NewUUID()
|
1256 | d0c8c01d | Iustin Pop | rcmd = utils.ShellQuoteArgs(["echo", "-n", uniqueid]) |
1257 | d0c8c01d | Iustin Pop | cmd = utils.ShellQuoteArgs(["gnt-cluster", "command", |
1258 | 830da270 | Michael Hanselmann | "%s >%s" % (rcmd, rfile)])
|
1259 | 830da270 | Michael Hanselmann | |
1260 | 830da270 | Michael Hanselmann | try:
|
1261 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
1262 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(rfile, uniqueid) |
1263 | 830da270 | Michael Hanselmann | finally:
|
1264 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(rfile) |
1265 | cec9845c | Michael Hanselmann | |
1266 | cec9845c | Michael Hanselmann | |
1267 | cec9845c | Michael Hanselmann | def TestClusterDestroy(): |
1268 | cec9845c | Michael Hanselmann | """gnt-cluster destroy"""
|
1269 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "destroy", "--yes-do-it"]) |
1270 | 65a884ef | Iustin Pop | |
1271 | 65a884ef | Iustin Pop | |
1272 | 65a884ef | Iustin Pop | def TestClusterRepairDiskSizes(): |
1273 | 65a884ef | Iustin Pop | """gnt-cluster repair-disk-sizes"""
|
1274 | 65a884ef | Iustin Pop | AssertCommand(["gnt-cluster", "repair-disk-sizes"]) |
1275 | 50ef6a41 | Bernardo Dal Seno | |
1276 | 50ef6a41 | Bernardo Dal Seno | |
1277 | 50ef6a41 | Bernardo Dal Seno | def TestSetExclStorCluster(newvalue): |
1278 | 50ef6a41 | Bernardo Dal Seno | """Set the exclusive_storage node parameter at the cluster level.
|
1279 | 50ef6a41 | Bernardo Dal Seno |
|
1280 | 50ef6a41 | Bernardo Dal Seno | @type newvalue: bool
|
1281 | 50ef6a41 | Bernardo Dal Seno | @param newvalue: New value of exclusive_storage
|
1282 | 50ef6a41 | Bernardo Dal Seno | @rtype: bool
|
1283 | 50ef6a41 | Bernardo Dal Seno | @return: The old value of exclusive_storage
|
1284 | 50ef6a41 | Bernardo Dal Seno |
|
1285 | 50ef6a41 | Bernardo Dal Seno | """
|
1286 | 0e79564a | Bernardo Dal Seno | es_path = ["Default node parameters", "exclusive_storage"] |
1287 | 0e79564a | Bernardo Dal Seno | oldvalue = _GetClusterField(es_path) |
1288 | 50ef6a41 | Bernardo Dal Seno | AssertCommand(["gnt-cluster", "modify", "--node-parameters", |
1289 | 50ef6a41 | Bernardo Dal Seno | "exclusive_storage=%s" % newvalue])
|
1290 | 0e79564a | Bernardo Dal Seno | effvalue = _GetClusterField(es_path) |
1291 | 50ef6a41 | Bernardo Dal Seno | if effvalue != newvalue:
|
1292 | 50ef6a41 | Bernardo Dal Seno | raise qa_error.Error("exclusive_storage has the wrong value: %s instead" |
1293 | 50ef6a41 | Bernardo Dal Seno | " of %s" % (effvalue, newvalue))
|
1294 | 6a0f22e1 | Bernardo Dal Seno | qa_config.SetExclusiveStorage(newvalue) |
1295 | 50ef6a41 | Bernardo Dal Seno | return oldvalue
|
1296 | e8b919a1 | Bernardo Dal Seno | |
1297 | e8b919a1 | Bernardo Dal Seno | |
1298 | 21e2734f | Bernardo Dal Seno | def TestExclStorSharedPv(node): |
1299 | 21e2734f | Bernardo Dal Seno | """cluster-verify reports LVs that share the same PV with exclusive_storage.
|
1300 | 21e2734f | Bernardo Dal Seno |
|
1301 | 21e2734f | Bernardo Dal Seno | """
|
1302 | 21e2734f | Bernardo Dal Seno | vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
|
1303 | 21e2734f | Bernardo Dal Seno | lvname1 = _QA_LV_PREFIX + "vol1"
|
1304 | 21e2734f | Bernardo Dal Seno | lvname2 = _QA_LV_PREFIX + "vol2"
|
1305 | aecba21e | Michael Hanselmann | node_name = node.primary |
1306 | 21e2734f | Bernardo Dal Seno | AssertCommand(["lvcreate", "-L1G", "-n", lvname1, vgname], node=node_name) |
1307 | 21e2734f | Bernardo Dal Seno | AssertClusterVerify(fail=True, errors=[constants.CV_ENODEORPHANLV])
|
1308 | 21e2734f | Bernardo Dal Seno | AssertCommand(["lvcreate", "-L1G", "-n", lvname2, vgname], node=node_name) |
1309 | 21e2734f | Bernardo Dal Seno | AssertClusterVerify(fail=True, errors=[constants.CV_ENODELVM,
|
1310 | 21e2734f | Bernardo Dal Seno | constants.CV_ENODEORPHANLV]) |
1311 | 21e2734f | Bernardo Dal Seno | AssertCommand(["lvremove", "-f", "/".join([vgname, lvname1])], node=node_name) |
1312 | 21e2734f | Bernardo Dal Seno | AssertCommand(["lvremove", "-f", "/".join([vgname, lvname2])], node=node_name) |
1313 | 21e2734f | Bernardo Dal Seno | AssertClusterVerify() |