root / qa / qa_instance.py @ dbdb0594
History | View | Annotate | Download (24.5 kB)
1 | c68d1f43 | Michael Hanselmann | #
|
---|---|---|---|
2 | c68d1f43 | Michael Hanselmann | #
|
3 | c68d1f43 | Michael Hanselmann | |
4 | deaa347b | Bernardo Dal Seno | # Copyright (C) 2007, 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 | """Instance related QA tests.
|
23 | cec9845c | Michael Hanselmann |
|
24 | cec9845c | Michael Hanselmann | """
|
25 | cec9845c | Michael Hanselmann | |
26 | c99200a3 | Bernardo Dal Seno | import operator |
27 | e8ae0c20 | Michael Hanselmann | import re |
28 | e8ae0c20 | Michael Hanselmann | |
29 | cec9845c | Michael Hanselmann | from ganeti import utils |
30 | 5d640672 | Michael Hanselmann | from ganeti import constants |
31 | 288d6440 | Michael Hanselmann | from ganeti import query |
32 | 304d9f02 | Michael Hanselmann | from ganeti import pathutils |
33 | cec9845c | Michael Hanselmann | |
34 | cec9845c | Michael Hanselmann | import qa_config |
35 | 5d640672 | Michael Hanselmann | import qa_utils |
36 | e8ae0c20 | Michael Hanselmann | import qa_error |
37 | e8ae0c20 | Michael Hanselmann | |
38 | cc27265e | René Nussbaumer | from qa_utils import AssertIn, AssertCommand, AssertEqual |
39 | 5fa0375e | Michael Hanselmann | from qa_utils import InstanceCheck, INST_DOWN, INST_UP, FIRST_ARG, RETURN_VALUE |
40 | cec9845c | Michael Hanselmann | |
41 | e8ae0c20 | Michael Hanselmann | |
42 | e8ae0c20 | Michael Hanselmann | def _GetDiskStatePath(disk): |
43 | e8ae0c20 | Michael Hanselmann | return "/sys/block/%s/device/state" % disk |
44 | cec9845c | Michael Hanselmann | |
45 | cec9845c | Michael Hanselmann | |
46 | 1c573fb4 | Iustin Pop | def _GetGenericAddParameters(inst, force_mac=None): |
47 | 8ccbbe4b | Guido Trotter | params = ["-B"]
|
48 | 8ccbbe4b | Guido Trotter | params.append("%s=%s,%s=%s" % (constants.BE_MINMEM,
|
49 | 8ccbbe4b | Guido Trotter | qa_config.get(constants.BE_MINMEM), |
50 | 8ccbbe4b | Guido Trotter | constants.BE_MAXMEM, |
51 | 8ccbbe4b | Guido Trotter | qa_config.get(constants.BE_MAXMEM))) |
52 | d0c8c01d | Iustin Pop | for idx, size in enumerate(qa_config.get("disk")): |
53 | 1d693311 | Michael Hanselmann | params.extend(["--disk", "%s:size=%s" % (idx, size)]) |
54 | f346a7d9 | Michael Hanselmann | |
55 | f346a7d9 | Michael Hanselmann | # Set static MAC address if configured
|
56 | 1c573fb4 | Iustin Pop | if force_mac:
|
57 | 1c573fb4 | Iustin Pop | nic0_mac = force_mac |
58 | 1c573fb4 | Iustin Pop | else:
|
59 | 1c573fb4 | Iustin Pop | nic0_mac = qa_config.GetInstanceNicMac(inst) |
60 | f346a7d9 | Michael Hanselmann | if nic0_mac:
|
61 | f346a7d9 | Michael Hanselmann | params.extend(["--net", "0:mac=%s" % nic0_mac]) |
62 | f346a7d9 | Michael Hanselmann | |
63 | 1d693311 | Michael Hanselmann | return params
|
64 | 5d640672 | Michael Hanselmann | |
65 | 5d640672 | Michael Hanselmann | |
66 | 113b8d89 | Michael Hanselmann | def _DiskTest(node, disk_template): |
67 | cec9845c | Michael Hanselmann | instance = qa_config.AcquireInstance() |
68 | cec9845c | Michael Hanselmann | try:
|
69 | d0c8c01d | Iustin Pop | cmd = (["gnt-instance", "add", |
70 | d0c8c01d | Iustin Pop | "--os-type=%s" % qa_config.get("os"), |
71 | d0c8c01d | Iustin Pop | "--disk-template=%s" % disk_template,
|
72 | d0c8c01d | Iustin Pop | "--node=%s" % node] +
|
73 | f346a7d9 | Michael Hanselmann | _GetGenericAddParameters(instance)) |
74 | d0c8c01d | Iustin Pop | cmd.append(instance["name"])
|
75 | cec9845c | Michael Hanselmann | |
76 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
77 | 6a343475 | Michael Hanselmann | |
78 | 6a343475 | Michael Hanselmann | _CheckSsconfInstanceList(instance["name"])
|
79 | 906a0346 | Bernardo Dal Seno | qa_config.SetInstanceTemplate(instance, disk_template) |
80 | 6a343475 | Michael Hanselmann | |
81 | cec9845c | Michael Hanselmann | return instance
|
82 | cec9845c | Michael Hanselmann | except:
|
83 | 6f88e076 | Michael Hanselmann | instance.Release() |
84 | cec9845c | Michael Hanselmann | raise
|
85 | cec9845c | Michael Hanselmann | |
86 | cec9845c | Michael Hanselmann | |
87 | cc4b14f0 | Bernardo Dal Seno | def _GetInstanceInfo(instance): |
88 | cc4b14f0 | Bernardo Dal Seno | """Return information about the actual state of an instance.
|
89 | 82d2f3df | Bernardo Dal Seno |
|
90 | b07afbb3 | Iustin Pop | @type instance: string
|
91 | b07afbb3 | Iustin Pop | @param instance: the instance name
|
92 | f006f110 | Bernardo Dal Seno | @return: a dictionary with the following keys:
|
93 | b07afbb3 | Iustin Pop | - "nodes": instance nodes, a list of strings
|
94 | b07afbb3 | Iustin Pop | - "volumes": instance volume IDs, a list of strings
|
95 | f006f110 | Bernardo Dal Seno | - "drbd-minors": DRBD minors used by the instance, a dictionary where
|
96 | f006f110 | Bernardo Dal Seno | keys are nodes, and values are lists of integers (or an empty
|
97 | f006f110 | Bernardo Dal Seno | dictionary for non-DRBD instances)
|
98 | 82d2f3df | Bernardo Dal Seno |
|
99 | 82d2f3df | Bernardo Dal Seno | """
|
100 | 82d2f3df | Bernardo Dal Seno | master = qa_config.GetMasterNode() |
101 | b07afbb3 | Iustin Pop | infocmd = utils.ShellQuoteArgs(["gnt-instance", "info", instance]) |
102 | 82d2f3df | Bernardo Dal Seno | info_out = qa_utils.GetCommandOutput(master["primary"], infocmd)
|
103 | 82d2f3df | Bernardo Dal Seno | re_node = re.compile(r"^\s+-\s+(?:primary|secondaries):\s+(\S.+)$")
|
104 | 82d2f3df | Bernardo Dal Seno | node_elem = r"([^,()]+)(?:\s+\([^)]+\))?"
|
105 | 82d2f3df | Bernardo Dal Seno | # re_nodelist matches a list of nodes returned by gnt-instance info, e.g.:
|
106 | 82d2f3df | Bernardo Dal Seno | # node1.fqdn
|
107 | 82d2f3df | Bernardo Dal Seno | # node2.fqdn,node3.fqdn
|
108 | 82d2f3df | Bernardo Dal Seno | # node4.fqdn (group mygroup, group UUID 01234567-abcd-0123-4567-0123456789ab)
|
109 | 82d2f3df | Bernardo Dal Seno | # FIXME This works with no more than 2 secondaries
|
110 | 82d2f3df | Bernardo Dal Seno | re_nodelist = re.compile(node_elem + "(?:," + node_elem + ")?$") |
111 | 82d2f3df | Bernardo Dal Seno | re_vol = re.compile(r"^\s+logical_id:\s+(\S+)$")
|
112 | f006f110 | Bernardo Dal Seno | re_drbdnode = re.compile(r"^\s+node[AB]:\s+([^\s,]+),\s+minor=([0-9]+)$")
|
113 | 82d2f3df | Bernardo Dal Seno | nodes = [] |
114 | 82d2f3df | Bernardo Dal Seno | vols = [] |
115 | f006f110 | Bernardo Dal Seno | drbd_min = {} |
116 | 82d2f3df | Bernardo Dal Seno | for line in info_out.splitlines(): |
117 | 82d2f3df | Bernardo Dal Seno | m = re_node.match(line) |
118 | 82d2f3df | Bernardo Dal Seno | if m:
|
119 | 82d2f3df | Bernardo Dal Seno | nodestr = m.group(1)
|
120 | 82d2f3df | Bernardo Dal Seno | m2 = re_nodelist.match(nodestr) |
121 | 82d2f3df | Bernardo Dal Seno | if m2:
|
122 | 82d2f3df | Bernardo Dal Seno | nodes.extend(filter(None, m2.groups())) |
123 | 82d2f3df | Bernardo Dal Seno | else:
|
124 | 82d2f3df | Bernardo Dal Seno | nodes.append(nodestr) |
125 | 82d2f3df | Bernardo Dal Seno | m = re_vol.match(line) |
126 | 82d2f3df | Bernardo Dal Seno | if m:
|
127 | 82d2f3df | Bernardo Dal Seno | vols.append(m.group(1))
|
128 | f006f110 | Bernardo Dal Seno | m = re_drbdnode.match(line) |
129 | f006f110 | Bernardo Dal Seno | if m:
|
130 | f006f110 | Bernardo Dal Seno | node = m.group(1)
|
131 | f006f110 | Bernardo Dal Seno | minor = int(m.group(2)) |
132 | f006f110 | Bernardo Dal Seno | if drbd_min.get(node) is not None: |
133 | f006f110 | Bernardo Dal Seno | drbd_min[node].append(minor) |
134 | f006f110 | Bernardo Dal Seno | else:
|
135 | f006f110 | Bernardo Dal Seno | drbd_min[node] = [minor] |
136 | 82d2f3df | Bernardo Dal Seno | assert vols
|
137 | 82d2f3df | Bernardo Dal Seno | assert nodes
|
138 | f006f110 | Bernardo Dal Seno | return {"nodes": nodes, "volumes": vols, "drbd-minors": drbd_min} |
139 | cc4b14f0 | Bernardo Dal Seno | |
140 | cc4b14f0 | Bernardo Dal Seno | |
141 | cc4b14f0 | Bernardo Dal Seno | def _DestroyInstanceVolumes(instance): |
142 | cc4b14f0 | Bernardo Dal Seno | """Remove all the LVM volumes of an instance.
|
143 | cc4b14f0 | Bernardo Dal Seno |
|
144 | cc4b14f0 | Bernardo Dal Seno | This is used to simulate HW errors (dead nodes, broken disks...); the
|
145 | cc4b14f0 | Bernardo Dal Seno | configuration of the instance is not affected.
|
146 | cc4b14f0 | Bernardo Dal Seno | @type instance: dictionary
|
147 | cc4b14f0 | Bernardo Dal Seno | @param instance: the instance
|
148 | cc4b14f0 | Bernardo Dal Seno |
|
149 | cc4b14f0 | Bernardo Dal Seno | """
|
150 | b07afbb3 | Iustin Pop | info = _GetInstanceInfo(instance["name"])
|
151 | cc4b14f0 | Bernardo Dal Seno | vols = info["volumes"]
|
152 | cc4b14f0 | Bernardo Dal Seno | for node in info["nodes"]: |
153 | 82d2f3df | Bernardo Dal Seno | AssertCommand(["lvremove", "-f"] + vols, node=node) |
154 | 82d2f3df | Bernardo Dal Seno | |
155 | 82d2f3df | Bernardo Dal Seno | |
156 | d55408b0 | Bernardo Dal Seno | def _GetBoolInstanceField(instance, field): |
157 | d55408b0 | Bernardo Dal Seno | """Get the Boolean value of a field of an instance.
|
158 | d55408b0 | Bernardo Dal Seno |
|
159 | d55408b0 | Bernardo Dal Seno | @type instance: string
|
160 | d55408b0 | Bernardo Dal Seno | @param instance: Instance name
|
161 | d55408b0 | Bernardo Dal Seno | @type field: string
|
162 | d55408b0 | Bernardo Dal Seno | @param field: Name of the field
|
163 | d55408b0 | Bernardo Dal Seno |
|
164 | d55408b0 | Bernardo Dal Seno | """
|
165 | d55408b0 | Bernardo Dal Seno | master = qa_config.GetMasterNode() |
166 | d55408b0 | Bernardo Dal Seno | infocmd = utils.ShellQuoteArgs(["gnt-instance", "list", "--no-headers", |
167 | d55408b0 | Bernardo Dal Seno | "-o", field, instance])
|
168 | d55408b0 | Bernardo Dal Seno | info_out = qa_utils.GetCommandOutput(master["primary"], infocmd).strip()
|
169 | d55408b0 | Bernardo Dal Seno | if info_out == "Y": |
170 | d55408b0 | Bernardo Dal Seno | return True |
171 | d55408b0 | Bernardo Dal Seno | elif info_out == "N": |
172 | d55408b0 | Bernardo Dal Seno | return False |
173 | d55408b0 | Bernardo Dal Seno | else:
|
174 | d55408b0 | Bernardo Dal Seno | raise qa_error.Error("Field %s of instance %s has a non-Boolean value:" |
175 | d55408b0 | Bernardo Dal Seno | " %s" % (field, instance, info_out))
|
176 | d55408b0 | Bernardo Dal Seno | |
177 | d55408b0 | Bernardo Dal Seno | |
178 | 5de31440 | Bernardo Dal Seno | def IsFailoverSupported(instance): |
179 | 5de31440 | Bernardo Dal Seno | templ = qa_config.GetInstanceTemplate(instance) |
180 | 5de31440 | Bernardo Dal Seno | return templ in constants.DTS_MIRRORED |
181 | 5de31440 | Bernardo Dal Seno | |
182 | 5de31440 | Bernardo Dal Seno | |
183 | 5de31440 | Bernardo Dal Seno | def IsMigrationSupported(instance): |
184 | 5de31440 | Bernardo Dal Seno | templ = qa_config.GetInstanceTemplate(instance) |
185 | 5de31440 | Bernardo Dal Seno | return templ in constants.DTS_MIRRORED |
186 | 5de31440 | Bernardo Dal Seno | |
187 | 5de31440 | Bernardo Dal Seno | |
188 | 5de31440 | Bernardo Dal Seno | def IsDiskReplacingSupported(instance): |
189 | 5de31440 | Bernardo Dal Seno | templ = qa_config.GetInstanceTemplate(instance) |
190 | 5de31440 | Bernardo Dal Seno | return templ == constants.DT_DRBD8
|
191 | 5de31440 | Bernardo Dal Seno | |
192 | 5de31440 | Bernardo Dal Seno | |
193 | 5fa0375e | Michael Hanselmann | @InstanceCheck(None, INST_UP, RETURN_VALUE) |
194 | c99200a3 | Bernardo Dal Seno | def TestInstanceAddWithPlainDisk(nodes): |
195 | cec9845c | Michael Hanselmann | """gnt-instance add -t plain"""
|
196 | c99200a3 | Bernardo Dal Seno | assert len(nodes) == 1 |
197 | c99200a3 | Bernardo Dal Seno | return _DiskTest(nodes[0]["primary"], "plain") |
198 | cec9845c | Michael Hanselmann | |
199 | cec9845c | Michael Hanselmann | |
200 | 5fa0375e | Michael Hanselmann | @InstanceCheck(None, INST_UP, RETURN_VALUE) |
201 | c99200a3 | Bernardo Dal Seno | def TestInstanceAddWithDrbdDisk(nodes): |
202 | 7d7609a3 | Michael Hanselmann | """gnt-instance add -t drbd"""
|
203 | c99200a3 | Bernardo Dal Seno | assert len(nodes) == 2 |
204 | c99200a3 | Bernardo Dal Seno | return _DiskTest(":".join(map(operator.itemgetter("primary"), nodes)), |
205 | d0c8c01d | Iustin Pop | "drbd")
|
206 | 7d7609a3 | Michael Hanselmann | |
207 | 7d7609a3 | Michael Hanselmann | |
208 | 5fa0375e | Michael Hanselmann | @InstanceCheck(None, INST_DOWN, FIRST_ARG) |
209 | cec9845c | Michael Hanselmann | def TestInstanceRemove(instance): |
210 | cec9845c | Michael Hanselmann | """gnt-instance remove"""
|
211 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "remove", "-f", instance["name"]]) |
212 | cec9845c | Michael Hanselmann | |
213 | cec9845c | Michael Hanselmann | |
214 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_UP, FIRST_ARG)
|
215 | cec9845c | Michael Hanselmann | def TestInstanceStartup(instance): |
216 | cec9845c | Michael Hanselmann | """gnt-instance startup"""
|
217 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "startup", instance["name"]]) |
218 | cec9845c | Michael Hanselmann | |
219 | cec9845c | Michael Hanselmann | |
220 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_DOWN, FIRST_ARG)
|
221 | cec9845c | Michael Hanselmann | def TestInstanceShutdown(instance): |
222 | cec9845c | Michael Hanselmann | """gnt-instance shutdown"""
|
223 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "shutdown", instance["name"]]) |
224 | cec9845c | Michael Hanselmann | |
225 | cec9845c | Michael Hanselmann | |
226 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
227 | 8a4e8898 | Michael Hanselmann | def TestInstanceReboot(instance): |
228 | 8a4e8898 | Michael Hanselmann | """gnt-instance reboot"""
|
229 | d0c8c01d | Iustin Pop | options = qa_config.get("options", {})
|
230 | 1d103c02 | Iustin Pop | reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
|
231 | 2f4b4f78 | Iustin Pop | name = instance["name"]
|
232 | 1d103c02 | Iustin Pop | for rtype in reboot_types: |
233 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "reboot", "--type=%s" % rtype, name]) |
234 | 8a4e8898 | Michael Hanselmann | |
235 | cc27265e | René Nussbaumer | AssertCommand(["gnt-instance", "shutdown", name]) |
236 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, False)
|
237 | cc27265e | René Nussbaumer | AssertCommand(["gnt-instance", "reboot", name]) |
238 | cc27265e | René Nussbaumer | |
239 | cc27265e | René Nussbaumer | master = qa_config.GetMasterNode() |
240 | 58ea8d17 | Michael Hanselmann | cmd = ["gnt-instance", "list", "--no-headers", "-o", "status", name] |
241 | cc27265e | René Nussbaumer | result_output = qa_utils.GetCommandOutput(master["primary"],
|
242 | cc27265e | René Nussbaumer | utils.ShellQuoteArgs(cmd)) |
243 | cc27265e | René Nussbaumer | AssertEqual(result_output.strip(), constants.INSTST_RUNNING) |
244 | cc27265e | René Nussbaumer | |
245 | 8a4e8898 | Michael Hanselmann | |
246 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
|
247 | 283f9d4c | Michael Hanselmann | def TestInstanceReinstall(instance): |
248 | 283f9d4c | Michael Hanselmann | """gnt-instance reinstall"""
|
249 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "reinstall", "-f", instance["name"]]) |
250 | 283f9d4c | Michael Hanselmann | |
251 | 64be07b1 | Michael Hanselmann | # Test with non-existant OS definition
|
252 | 64be07b1 | Michael Hanselmann | AssertCommand(["gnt-instance", "reinstall", "-f", |
253 | 64be07b1 | Michael Hanselmann | "--os-type=NonExistantOsForQa",
|
254 | 64be07b1 | Michael Hanselmann | instance["name"]],
|
255 | 64be07b1 | Michael Hanselmann | fail=True)
|
256 | 64be07b1 | Michael Hanselmann | |
257 | 283f9d4c | Michael Hanselmann | |
258 | 6a343475 | Michael Hanselmann | def _ReadSsconfInstanceList(): |
259 | 6a343475 | Michael Hanselmann | """Reads ssconf_instance_list from the master node.
|
260 | 6a343475 | Michael Hanselmann |
|
261 | 6a343475 | Michael Hanselmann | """
|
262 | 6a343475 | Michael Hanselmann | master = qa_config.GetMasterNode() |
263 | 6a343475 | Michael Hanselmann | |
264 | 304d9f02 | Michael Hanselmann | cmd = ["cat", utils.PathJoin(pathutils.DATA_DIR,
|
265 | 6a343475 | Michael Hanselmann | "ssconf_%s" % constants.SS_INSTANCE_LIST)]
|
266 | 6a343475 | Michael Hanselmann | |
267 | 6a343475 | Michael Hanselmann | return qa_utils.GetCommandOutput(master["primary"], |
268 | 6a343475 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).splitlines() |
269 | 6a343475 | Michael Hanselmann | |
270 | 6a343475 | Michael Hanselmann | |
271 | 6a343475 | Michael Hanselmann | def _CheckSsconfInstanceList(instance): |
272 | 6a343475 | Michael Hanselmann | """Checks if a certain instance is in the ssconf instance list.
|
273 | 6a343475 | Michael Hanselmann |
|
274 | 6a343475 | Michael Hanselmann | @type instance: string
|
275 | 6a343475 | Michael Hanselmann | @param instance: Instance name
|
276 | 6a343475 | Michael Hanselmann |
|
277 | 6a343475 | Michael Hanselmann | """
|
278 | 6a343475 | Michael Hanselmann | AssertIn(qa_utils.ResolveInstanceName(instance), |
279 | 6a343475 | Michael Hanselmann | _ReadSsconfInstanceList()) |
280 | 6a343475 | Michael Hanselmann | |
281 | 6a343475 | Michael Hanselmann | |
282 | 51131cad | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
|
283 | 4c1a464b | Iustin Pop | def TestInstanceRenameAndBack(rename_source, rename_target): |
284 | 4c1a464b | Iustin Pop | """gnt-instance rename
|
285 | 4c1a464b | Iustin Pop |
|
286 | 4c1a464b | Iustin Pop | This must leave the instance with the original name, not the target
|
287 | 4c1a464b | Iustin Pop | name.
|
288 | 4c1a464b | Iustin Pop |
|
289 | 4c1a464b | Iustin Pop | """
|
290 | 31fe5102 | René Nussbaumer | _CheckSsconfInstanceList(rename_source) |
291 | 5fa0375e | Michael Hanselmann | |
292 | 4c1a464b | Iustin Pop | # first do a rename to a different actual name, expecting it to fail
|
293 | 31fe5102 | René Nussbaumer | qa_utils.AddToEtcHosts(["meeeeh-not-exists", rename_target])
|
294 | 31fe5102 | René Nussbaumer | try:
|
295 | 31fe5102 | René Nussbaumer | AssertCommand(["gnt-instance", "rename", rename_source, rename_target], |
296 | 31fe5102 | René Nussbaumer | fail=True)
|
297 | 31fe5102 | René Nussbaumer | _CheckSsconfInstanceList(rename_source) |
298 | 31fe5102 | René Nussbaumer | finally:
|
299 | 31fe5102 | René Nussbaumer | qa_utils.RemoveFromEtcHosts(["meeeeh-not-exists", rename_target])
|
300 | 5fa0375e | Michael Hanselmann | |
301 | b07afbb3 | Iustin Pop | # Check instance volume tags correctly updated
|
302 | b07afbb3 | Iustin Pop | # FIXME: this is LVM specific!
|
303 | b07afbb3 | Iustin Pop | info = _GetInstanceInfo(rename_source) |
304 | b07afbb3 | Iustin Pop | tags_cmd = ("lvs -o tags --noheadings %s | grep " %
|
305 | b07afbb3 | Iustin Pop | (" ".join(info["volumes"]), )) |
306 | b07afbb3 | Iustin Pop | |
307 | 4c1a464b | Iustin Pop | # and now rename instance to rename_target...
|
308 | 31fe5102 | René Nussbaumer | AssertCommand(["gnt-instance", "rename", rename_source, rename_target]) |
309 | 31fe5102 | René Nussbaumer | _CheckSsconfInstanceList(rename_target) |
310 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(rename_source, False)
|
311 | 51131cad | Michael Hanselmann | qa_utils.RunInstanceCheck(rename_target, False)
|
312 | 5fa0375e | Michael Hanselmann | |
313 | b07afbb3 | Iustin Pop | # NOTE: tags might not be the exactly as the instance name, due to
|
314 | b07afbb3 | Iustin Pop | # charset restrictions; hence the test might be flaky
|
315 | b07afbb3 | Iustin Pop | if rename_source != rename_target:
|
316 | b07afbb3 | Iustin Pop | for node in info["nodes"]: |
317 | b07afbb3 | Iustin Pop | AssertCommand(tags_cmd + rename_source, node=node, fail=True)
|
318 | b07afbb3 | Iustin Pop | AssertCommand(tags_cmd + rename_target, node=node, fail=False)
|
319 | b07afbb3 | Iustin Pop | |
320 | 4c1a464b | Iustin Pop | # and back
|
321 | 4c1a464b | Iustin Pop | AssertCommand(["gnt-instance", "rename", rename_target, rename_source]) |
322 | 4c1a464b | Iustin Pop | _CheckSsconfInstanceList(rename_source) |
323 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(rename_target, False)
|
324 | 18337ca9 | Iustin Pop | |
325 | b07afbb3 | Iustin Pop | if rename_source != rename_target:
|
326 | b07afbb3 | Iustin Pop | for node in info["nodes"]: |
327 | b07afbb3 | Iustin Pop | AssertCommand(tags_cmd + rename_source, node=node, fail=False)
|
328 | b07afbb3 | Iustin Pop | AssertCommand(tags_cmd + rename_target, node=node, fail=True)
|
329 | b07afbb3 | Iustin Pop | |
330 | 18337ca9 | Iustin Pop | |
331 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
332 | cec9845c | Michael Hanselmann | def TestInstanceFailover(instance): |
333 | cec9845c | Michael Hanselmann | """gnt-instance failover"""
|
334 | 5de31440 | Bernardo Dal Seno | if not IsFailoverSupported(instance): |
335 | 5de31440 | Bernardo Dal Seno | print qa_utils.FormatInfo("Instance doesn't support failover, skipping" |
336 | 5de31440 | Bernardo Dal Seno | " test")
|
337 | 5de31440 | Bernardo Dal Seno | return
|
338 | 5de31440 | Bernardo Dal Seno | |
339 | d0c8c01d | Iustin Pop | cmd = ["gnt-instance", "failover", "--force", instance["name"]] |
340 | 5fa0375e | Michael Hanselmann | |
341 | 2f4b4f78 | Iustin Pop | # failover ...
|
342 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
343 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, True)
|
344 | 5fa0375e | Michael Hanselmann | |
345 | 76f59a32 | Michael Hanselmann | # ... and back
|
346 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
347 | 76f59a32 | Michael Hanselmann | |
348 | cec9845c | Michael Hanselmann | |
349 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
350 | d55408b0 | Bernardo Dal Seno | def TestInstanceMigrate(instance, toggle_always_failover=True): |
351 | 938bde86 | Michael Hanselmann | """gnt-instance migrate"""
|
352 | 5de31440 | Bernardo Dal Seno | if not IsMigrationSupported(instance): |
353 | 5de31440 | Bernardo Dal Seno | print qa_utils.FormatInfo("Instance doesn't support migration, skipping" |
354 | 5de31440 | Bernardo Dal Seno | " test")
|
355 | 5de31440 | Bernardo Dal Seno | return
|
356 | 5de31440 | Bernardo Dal Seno | |
357 | 938bde86 | Michael Hanselmann | cmd = ["gnt-instance", "migrate", "--force", instance["name"]] |
358 | d55408b0 | Bernardo Dal Seno | af_par = constants.BE_ALWAYS_FAILOVER |
359 | d55408b0 | Bernardo Dal Seno | af_field = "be/" + constants.BE_ALWAYS_FAILOVER
|
360 | d55408b0 | Bernardo Dal Seno | af_init_val = _GetBoolInstanceField(instance["name"], af_field)
|
361 | 5fa0375e | Michael Hanselmann | |
362 | 2f4b4f78 | Iustin Pop | # migrate ...
|
363 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
364 | d55408b0 | Bernardo Dal Seno | # TODO: Verify the choice between failover and migration
|
365 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, True)
|
366 | 5fa0375e | Michael Hanselmann | |
367 | d55408b0 | Bernardo Dal Seno | # ... and back (possibly with always_failover toggled)
|
368 | d55408b0 | Bernardo Dal Seno | if toggle_always_failover:
|
369 | d55408b0 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "modify", "-B", |
370 | d55408b0 | Bernardo Dal Seno | ("%s=%s" % (af_par, not af_init_val)), |
371 | d55408b0 | Bernardo Dal Seno | instance["name"]])
|
372 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
373 | d55408b0 | Bernardo Dal Seno | # TODO: Verify the choice between failover and migration
|
374 | d55408b0 | Bernardo Dal Seno | qa_utils.RunInstanceCheck(instance, True)
|
375 | d55408b0 | Bernardo Dal Seno | if toggle_always_failover:
|
376 | d55408b0 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "modify", "-B", |
377 | d55408b0 | Bernardo Dal Seno | ("%s=%s" % (af_par, af_init_val)), instance["name"]]) |
378 | 5fa0375e | Michael Hanselmann | |
379 | 5fa0375e | Michael Hanselmann | # TODO: Split into multiple tests
|
380 | e9c487be | René Nussbaumer | AssertCommand(["gnt-instance", "shutdown", instance["name"]]) |
381 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, False)
|
382 | e9c487be | René Nussbaumer | AssertCommand(cmd, fail=True)
|
383 | e9c487be | René Nussbaumer | AssertCommand(["gnt-instance", "migrate", "--force", "--allow-failover", |
384 | e9c487be | René Nussbaumer | instance["name"]])
|
385 | e9c487be | René Nussbaumer | AssertCommand(["gnt-instance", "start", instance["name"]]) |
386 | e9c487be | René Nussbaumer | AssertCommand(cmd) |
387 | d55408b0 | Bernardo Dal Seno | # @InstanceCheck enforces the check that the instance is running
|
388 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, True)
|
389 | 5fa0375e | Michael Hanselmann | |
390 | 42a769f9 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "modify", "-B", |
391 | 42a769f9 | Bernardo Dal Seno | ("%s=%s" %
|
392 | 42a769f9 | Bernardo Dal Seno | (constants.BE_ALWAYS_FAILOVER, constants.VALUE_TRUE)), |
393 | 42a769f9 | Bernardo Dal Seno | instance["name"]])
|
394 | 5fa0375e | Michael Hanselmann | |
395 | 320a5dae | Bernardo Dal Seno | AssertCommand(cmd) |
396 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, True)
|
397 | 320a5dae | Bernardo Dal Seno | # TODO: Verify that a failover has been done instead of a migration
|
398 | 5fa0375e | Michael Hanselmann | |
399 | 5fa0375e | Michael Hanselmann | # TODO: Verify whether the default value is restored here (not hardcoded)
|
400 | 42a769f9 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "modify", "-B", |
401 | 42a769f9 | Bernardo Dal Seno | ("%s=%s" %
|
402 | 42a769f9 | Bernardo Dal Seno | (constants.BE_ALWAYS_FAILOVER, constants.VALUE_FALSE)), |
403 | 42a769f9 | Bernardo Dal Seno | instance["name"]])
|
404 | 5fa0375e | Michael Hanselmann | |
405 | 42a769f9 | Bernardo Dal Seno | AssertCommand(cmd) |
406 | 5fa0375e | Michael Hanselmann | qa_utils.RunInstanceCheck(instance, True)
|
407 | 938bde86 | Michael Hanselmann | |
408 | 938bde86 | Michael Hanselmann | |
409 | cec9845c | Michael Hanselmann | def TestInstanceInfo(instance): |
410 | cec9845c | Michael Hanselmann | """gnt-instance info"""
|
411 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "info", instance["name"]]) |
412 | 5d640672 | Michael Hanselmann | |
413 | 5d640672 | Michael Hanselmann | |
414 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
415 | c0f74c55 | Iustin Pop | def TestInstanceModify(instance): |
416 | c0f74c55 | Iustin Pop | """gnt-instance modify"""
|
417 | d488adb6 | Michael Hanselmann | default_hv = qa_config.GetDefaultHypervisor() |
418 | d488adb6 | Michael Hanselmann | |
419 | 1d693311 | Michael Hanselmann | # Assume /sbin/init exists on all systems
|
420 | 1d693311 | Michael Hanselmann | test_kernel = "/sbin/init"
|
421 | 1d693311 | Michael Hanselmann | test_initrd = test_kernel |
422 | 1d693311 | Michael Hanselmann | |
423 | 8ccbbe4b | Guido Trotter | orig_maxmem = qa_config.get(constants.BE_MAXMEM) |
424 | 8ccbbe4b | Guido Trotter | orig_minmem = qa_config.get(constants.BE_MINMEM) |
425 | 2f4b4f78 | Iustin Pop | #orig_bridge = qa_config.get("bridge", "xen-br0")
|
426 | d488adb6 | Michael Hanselmann | |
427 | c0f74c55 | Iustin Pop | args = [ |
428 | 8ccbbe4b | Guido Trotter | ["-B", "%s=128" % constants.BE_MINMEM], |
429 | 8ccbbe4b | Guido Trotter | ["-B", "%s=128" % constants.BE_MAXMEM], |
430 | 8ccbbe4b | Guido Trotter | ["-B", "%s=%s,%s=%s" % (constants.BE_MINMEM, orig_minmem, |
431 | 8ccbbe4b | Guido Trotter | constants.BE_MAXMEM, orig_maxmem)], |
432 | 1d693311 | Michael Hanselmann | ["-B", "%s=2" % constants.BE_VCPUS], |
433 | 1d693311 | Michael Hanselmann | ["-B", "%s=1" % constants.BE_VCPUS], |
434 | 1d693311 | Michael Hanselmann | ["-B", "%s=%s" % (constants.BE_VCPUS, constants.VALUE_DEFAULT)], |
435 | 42a769f9 | Bernardo Dal Seno | ["-B", "%s=%s" % (constants.BE_ALWAYS_FAILOVER, constants.VALUE_TRUE)], |
436 | 42a769f9 | Bernardo Dal Seno | ["-B", "%s=%s" % (constants.BE_ALWAYS_FAILOVER, constants.VALUE_DEFAULT)], |
437 | 1d693311 | Michael Hanselmann | |
438 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_KERNEL_PATH, test_kernel)], |
439 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_KERNEL_PATH, constants.VALUE_DEFAULT)], |
440 | 1d693311 | Michael Hanselmann | |
441 | 1d693311 | Michael Hanselmann | # TODO: bridge tests
|
442 | 1d693311 | Michael Hanselmann | #["--bridge", "xen-br1"],
|
443 | 1d693311 | Michael Hanselmann | #["--bridge", orig_bridge],
|
444 | c0f74c55 | Iustin Pop | ] |
445 | d488adb6 | Michael Hanselmann | |
446 | d488adb6 | Michael Hanselmann | if default_hv == constants.HT_XEN_PVM:
|
447 | d488adb6 | Michael Hanselmann | args.extend([ |
448 | d488adb6 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_INITRD_PATH, test_initrd)], |
449 | d488adb6 | Michael Hanselmann | ["-H", "no_%s" % (constants.HV_INITRD_PATH, )], |
450 | d488adb6 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_INITRD_PATH, constants.VALUE_DEFAULT)], |
451 | d488adb6 | Michael Hanselmann | ]) |
452 | d488adb6 | Michael Hanselmann | elif default_hv == constants.HT_XEN_HVM:
|
453 | d488adb6 | Michael Hanselmann | args.extend([ |
454 | d488adb6 | Michael Hanselmann | ["-H", "%s=acn" % constants.HV_BOOT_ORDER], |
455 | d488adb6 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_BOOT_ORDER, constants.VALUE_DEFAULT)], |
456 | d488adb6 | Michael Hanselmann | ]) |
457 | d488adb6 | Michael Hanselmann | |
458 | c0f74c55 | Iustin Pop | for alist in args: |
459 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "modify"] + alist + [instance["name"]]) |
460 | c0f74c55 | Iustin Pop | |
461 | c0f74c55 | Iustin Pop | # check no-modify
|
462 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "modify", instance["name"]], fail=True) |
463 | c0f74c55 | Iustin Pop | |
464 | 1ba25bad | Guido Trotter | # Marking offline while instance is running must fail...
|
465 | 1ba25bad | Guido Trotter | AssertCommand(["gnt-instance", "modify", "--offline", instance["name"]], |
466 | 1ba25bad | Guido Trotter | fail=True)
|
467 | 1ba25bad | Guido Trotter | |
468 | 1ba25bad | Guido Trotter | # ...while making it online is ok, and should work
|
469 | 1ba25bad | Guido Trotter | AssertCommand(["gnt-instance", "modify", "--online", instance["name"]]) |
470 | 3016bc1f | Michael Hanselmann | |
471 | 3016bc1f | Michael Hanselmann | |
472 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
|
473 | 3016bc1f | Michael Hanselmann | def TestInstanceStoppedModify(instance): |
474 | 3016bc1f | Michael Hanselmann | """gnt-instance modify (stopped instance)"""
|
475 | 3016bc1f | Michael Hanselmann | name = instance["name"]
|
476 | 3016bc1f | Michael Hanselmann | |
477 | 58f0ce16 | Michael Hanselmann | # Instance was not marked offline; try marking it online once more
|
478 | 58f0ce16 | Michael Hanselmann | AssertCommand(["gnt-instance", "modify", "--online", name]) |
479 | 3016bc1f | Michael Hanselmann | |
480 | 3016bc1f | Michael Hanselmann | # Mark instance as offline
|
481 | 3016bc1f | Michael Hanselmann | AssertCommand(["gnt-instance", "modify", "--offline", name]) |
482 | 3016bc1f | Michael Hanselmann | |
483 | 1ba25bad | Guido Trotter | # When the instance is offline shutdown should only work with --force,
|
484 | 1ba25bad | Guido Trotter | # while start should never work
|
485 | 1ba25bad | Guido Trotter | AssertCommand(["gnt-instance", "shutdown", name], fail=True) |
486 | 1ba25bad | Guido Trotter | AssertCommand(["gnt-instance", "shutdown", "--force", name]) |
487 | 1ba25bad | Guido Trotter | AssertCommand(["gnt-instance", "start", name], fail=True) |
488 | 1ba25bad | Guido Trotter | AssertCommand(["gnt-instance", "start", "--force", name], fail=True) |
489 | 1ba25bad | Guido Trotter | |
490 | 1ba25bad | Guido Trotter | # Also do offline to offline
|
491 | 1ba25bad | Guido Trotter | AssertCommand(["gnt-instance", "modify", "--offline", name]) |
492 | 1ba25bad | Guido Trotter | |
493 | 3016bc1f | Michael Hanselmann | # And online again
|
494 | 3016bc1f | Michael Hanselmann | AssertCommand(["gnt-instance", "modify", "--online", name]) |
495 | 3016bc1f | Michael Hanselmann | |
496 | c0f74c55 | Iustin Pop | |
497 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
|
498 | c99200a3 | Bernardo Dal Seno | def TestInstanceConvertDiskToPlain(instance, inodes): |
499 | 7f69aabb | Iustin Pop | """gnt-instance modify -t"""
|
500 | 2f4b4f78 | Iustin Pop | name = instance["name"]
|
501 | 5de31440 | Bernardo Dal Seno | template = qa_config.GetInstanceTemplate(instance) |
502 | 5de31440 | Bernardo Dal Seno | if template != "drbd": |
503 | 5de31440 | Bernardo Dal Seno | print qa_utils.FormatInfo("Unsupported template %s, skipping conversion" |
504 | 5de31440 | Bernardo Dal Seno | " test" % template)
|
505 | 5de31440 | Bernardo Dal Seno | return
|
506 | c99200a3 | Bernardo Dal Seno | assert len(inodes) == 2 |
507 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "modify", "-t", "plain", name]) |
508 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "modify", "-t", "drbd", |
509 | c99200a3 | Bernardo Dal Seno | "-n", inodes[1]["primary"], name]) |
510 | 7f69aabb | Iustin Pop | |
511 | 7f69aabb | Iustin Pop | |
512 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
|
513 | 26a5056d | Iustin Pop | def TestInstanceGrowDisk(instance): |
514 | 26a5056d | Iustin Pop | """gnt-instance grow-disk"""
|
515 | 5de31440 | Bernardo Dal Seno | if qa_config.GetExclusiveStorage():
|
516 | 5de31440 | Bernardo Dal Seno | print qa_utils.FormatInfo("Test not supported with exclusive_storage") |
517 | 5de31440 | Bernardo Dal Seno | return
|
518 | 26a5056d | Iustin Pop | name = instance["name"]
|
519 | 26a5056d | Iustin Pop | all_size = qa_config.get("disk")
|
520 | 26a5056d | Iustin Pop | all_grow = qa_config.get("disk-growth")
|
521 | 26a5056d | Iustin Pop | if not all_grow: |
522 | 26a5056d | Iustin Pop | # missing disk sizes but instance grow disk has been enabled,
|
523 | 26a5056d | Iustin Pop | # let's set fixed/nomimal growth
|
524 | 26a5056d | Iustin Pop | all_grow = ["128M" for _ in all_size] |
525 | 26a5056d | Iustin Pop | for idx, (size, grow) in enumerate(zip(all_size, all_grow)): |
526 | 26a5056d | Iustin Pop | # succeed in grow by amount
|
527 | 26a5056d | Iustin Pop | AssertCommand(["gnt-instance", "grow-disk", name, str(idx), grow]) |
528 | 26a5056d | Iustin Pop | # fail in grow to the old size
|
529 | 26a5056d | Iustin Pop | AssertCommand(["gnt-instance", "grow-disk", "--absolute", name, str(idx), |
530 | 26a5056d | Iustin Pop | size], fail=True)
|
531 | 26a5056d | Iustin Pop | # succeed to grow to old size + 2 * growth
|
532 | 26a5056d | Iustin Pop | int_size = utils.ParseUnit(size) |
533 | 26a5056d | Iustin Pop | int_grow = utils.ParseUnit(grow) |
534 | 26a5056d | Iustin Pop | AssertCommand(["gnt-instance", "grow-disk", "--absolute", name, str(idx), |
535 | 26a5056d | Iustin Pop | str(int_size + 2 * int_grow)]) |
536 | 26a5056d | Iustin Pop | |
537 | 26a5056d | Iustin Pop | |
538 | 283f9d4c | Michael Hanselmann | def TestInstanceList(): |
539 | 283f9d4c | Michael Hanselmann | """gnt-instance list"""
|
540 | 288d6440 | Michael Hanselmann | qa_utils.GenericQueryTest("gnt-instance", query.INSTANCE_FIELDS.keys())
|
541 | 283f9d4c | Michael Hanselmann | |
542 | 283f9d4c | Michael Hanselmann | |
543 | 2214cf14 | Michael Hanselmann | def TestInstanceListFields(): |
544 | 2214cf14 | Michael Hanselmann | """gnt-instance list-fields"""
|
545 | 2214cf14 | Michael Hanselmann | qa_utils.GenericQueryFieldsTest("gnt-instance", query.INSTANCE_FIELDS.keys())
|
546 | 2214cf14 | Michael Hanselmann | |
547 | 2214cf14 | Michael Hanselmann | |
548 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
549 | 4379b1fa | Michael Hanselmann | def TestInstanceConsole(instance): |
550 | 4379b1fa | Michael Hanselmann | """gnt-instance console"""
|
551 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "console", "--show-cmd", instance["name"]]) |
552 | 4379b1fa | Michael Hanselmann | |
553 | 4379b1fa | Michael Hanselmann | |
554 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
555 | c99200a3 | Bernardo Dal Seno | def TestReplaceDisks(instance, curr_nodes, other_nodes): |
556 | 7910e7a5 | Michael Hanselmann | """gnt-instance replace-disks"""
|
557 | 7910e7a5 | Michael Hanselmann | def buildcmd(args): |
558 | d0c8c01d | Iustin Pop | cmd = ["gnt-instance", "replace-disks"] |
559 | 7910e7a5 | Michael Hanselmann | cmd.extend(args) |
560 | 7910e7a5 | Michael Hanselmann | cmd.append(instance["name"])
|
561 | 7910e7a5 | Michael Hanselmann | return cmd
|
562 | 7910e7a5 | Michael Hanselmann | |
563 | 5de31440 | Bernardo Dal Seno | if not IsDiskReplacingSupported(instance): |
564 | 5de31440 | Bernardo Dal Seno | print qa_utils.FormatInfo("Instance doesn't support disk replacing," |
565 | 5de31440 | Bernardo Dal Seno | " skipping test")
|
566 | 5de31440 | Bernardo Dal Seno | return
|
567 | 5de31440 | Bernardo Dal Seno | |
568 | c99200a3 | Bernardo Dal Seno | # Currently all supported templates have one primary and one secondary node
|
569 | c99200a3 | Bernardo Dal Seno | assert len(curr_nodes) == 2 |
570 | c99200a3 | Bernardo Dal Seno | snode = curr_nodes[1]
|
571 | c99200a3 | Bernardo Dal Seno | assert len(other_nodes) == 1 |
572 | c99200a3 | Bernardo Dal Seno | othernode = other_nodes[0]
|
573 | c99200a3 | Bernardo Dal Seno | |
574 | e85be22a | Bernardo Dal Seno | options = qa_config.get("options", {})
|
575 | e85be22a | Bernardo Dal Seno | use_ialloc = options.get("use-iallocators", True) |
576 | 2f4b4f78 | Iustin Pop | for data in [ |
577 | 2f4b4f78 | Iustin Pop | ["-p"],
|
578 | 2f4b4f78 | Iustin Pop | ["-s"],
|
579 | e85be22a | Bernardo Dal Seno | # A placeholder; the actual command choice depends on use_ialloc
|
580 | e85be22a | Bernardo Dal Seno | None,
|
581 | e85be22a | Bernardo Dal Seno | # Restore the original secondary
|
582 | e85be22a | Bernardo Dal Seno | ["--new-secondary=%s" % snode["primary"]], |
583 | 2f4b4f78 | Iustin Pop | ]: |
584 | e85be22a | Bernardo Dal Seno | if data is None: |
585 | e85be22a | Bernardo Dal Seno | if use_ialloc:
|
586 | e85be22a | Bernardo Dal Seno | data = ["-I", constants.DEFAULT_IALLOCATOR_SHORTCUT]
|
587 | e85be22a | Bernardo Dal Seno | else:
|
588 | e85be22a | Bernardo Dal Seno | data = ["--new-secondary=%s" % othernode["primary"]] |
589 | 2f4b4f78 | Iustin Pop | AssertCommand(buildcmd(data)) |
590 | 7910e7a5 | Michael Hanselmann | |
591 | 9026e935 | René Nussbaumer | AssertCommand(buildcmd(["-a"]))
|
592 | 9026e935 | René Nussbaumer | AssertCommand(["gnt-instance", "stop", instance["name"]]) |
593 | 9026e935 | René Nussbaumer | AssertCommand(buildcmd(["-a"]), fail=True) |
594 | 9026e935 | René Nussbaumer | AssertCommand(["gnt-instance", "activate-disks", instance["name"]]) |
595 | 32da72f3 | Iustin Pop | AssertCommand(["gnt-instance", "activate-disks", "--wait-for-sync", |
596 | 32da72f3 | Iustin Pop | instance["name"]])
|
597 | 9026e935 | René Nussbaumer | AssertCommand(buildcmd(["-a"]))
|
598 | 9026e935 | René Nussbaumer | AssertCommand(["gnt-instance", "start", instance["name"]]) |
599 | 9026e935 | René Nussbaumer | |
600 | 7910e7a5 | Michael Hanselmann | |
601 | 83180411 | Bernardo Dal Seno | def _AssertRecreateDisks(cmdargs, instance, fail=False, check=True, |
602 | 83180411 | Bernardo Dal Seno | destroy=True):
|
603 | 83180411 | Bernardo Dal Seno | """Execute gnt-instance recreate-disks and check the result
|
604 | 83180411 | Bernardo Dal Seno |
|
605 | 83180411 | Bernardo Dal Seno | @param cmdargs: Arguments (instance name excluded)
|
606 | 83180411 | Bernardo Dal Seno | @param instance: Instance to operate on
|
607 | 83180411 | Bernardo Dal Seno | @param fail: True if the command is expected to fail
|
608 | 83180411 | Bernardo Dal Seno | @param check: If True and fail is False, check that the disks work
|
609 | 83180411 | Bernardo Dal Seno | @prama destroy: If True, destroy the old disks first
|
610 | 83180411 | Bernardo Dal Seno |
|
611 | 83180411 | Bernardo Dal Seno | """
|
612 | 83180411 | Bernardo Dal Seno | if destroy:
|
613 | 83180411 | Bernardo Dal Seno | _DestroyInstanceVolumes(instance) |
614 | 83180411 | Bernardo Dal Seno | AssertCommand((["gnt-instance", "recreate-disks"] + cmdargs + |
615 | 83180411 | Bernardo Dal Seno | [instance["name"]]), fail)
|
616 | 83180411 | Bernardo Dal Seno | if not fail and check: |
617 | 83180411 | Bernardo Dal Seno | # Quick check that the disks are there
|
618 | 83180411 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "activate-disks", instance["name"]]) |
619 | 32da72f3 | Iustin Pop | AssertCommand(["gnt-instance", "activate-disks", "--wait-for-sync", |
620 | 32da72f3 | Iustin Pop | instance["name"]])
|
621 | 83180411 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "deactivate-disks", instance["name"]]) |
622 | 83180411 | Bernardo Dal Seno | |
623 | a1cd2ecf | Bernardo Dal Seno | |
624 | 83180411 | Bernardo Dal Seno | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
625 | c99200a3 | Bernardo Dal Seno | def TestRecreateDisks(instance, inodes, othernodes): |
626 | 83180411 | Bernardo Dal Seno | """gnt-instance recreate-disks
|
627 | 83180411 | Bernardo Dal Seno |
|
628 | 83180411 | Bernardo Dal Seno | @param instance: Instance to work on
|
629 | c99200a3 | Bernardo Dal Seno | @param inodes: List of the current nodes of the instance
|
630 | 83180411 | Bernardo Dal Seno | @param othernodes: list/tuple of nodes where to temporarily recreate disks
|
631 | 83180411 | Bernardo Dal Seno |
|
632 | 83180411 | Bernardo Dal Seno | """
|
633 | e85be22a | Bernardo Dal Seno | options = qa_config.get("options", {})
|
634 | e85be22a | Bernardo Dal Seno | use_ialloc = options.get("use-iallocators", True) |
635 | 83180411 | Bernardo Dal Seno | other_seq = ":".join([n["primary"] for n in othernodes]) |
636 | c99200a3 | Bernardo Dal Seno | orig_seq = ":".join([n["primary"] for n in inodes]) |
637 | a085d96d | Bernardo Dal Seno | # These fail because the instance is running
|
638 | 83180411 | Bernardo Dal Seno | _AssertRecreateDisks(["-n", other_seq], instance, fail=True, destroy=False) |
639 | e85be22a | Bernardo Dal Seno | if use_ialloc:
|
640 | e85be22a | Bernardo Dal Seno | _AssertRecreateDisks(["-I", "hail"], instance, fail=True, destroy=False) |
641 | e85be22a | Bernardo Dal Seno | else:
|
642 | e85be22a | Bernardo Dal Seno | _AssertRecreateDisks(["-n", other_seq], instance, fail=True, destroy=False) |
643 | 83180411 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "stop", instance["name"]]) |
644 | 83180411 | Bernardo Dal Seno | # Disks exist: this should fail
|
645 | 83180411 | Bernardo Dal Seno | _AssertRecreateDisks([], instance, fail=True, destroy=False) |
646 | 83180411 | Bernardo Dal Seno | # Recreate disks in place
|
647 | 83180411 | Bernardo Dal Seno | _AssertRecreateDisks([], instance) |
648 | 83180411 | Bernardo Dal Seno | # Move disks away
|
649 | e85be22a | Bernardo Dal Seno | if use_ialloc:
|
650 | e85be22a | Bernardo Dal Seno | _AssertRecreateDisks(["-I", "hail"], instance) |
651 | e85be22a | Bernardo Dal Seno | # Move disks somewhere else
|
652 | e85be22a | Bernardo Dal Seno | _AssertRecreateDisks(["-I", constants.DEFAULT_IALLOCATOR_SHORTCUT],
|
653 | e85be22a | Bernardo Dal Seno | instance) |
654 | e85be22a | Bernardo Dal Seno | else:
|
655 | e85be22a | Bernardo Dal Seno | _AssertRecreateDisks(["-n", other_seq], instance)
|
656 | 83180411 | Bernardo Dal Seno | # Move disks back
|
657 | 83180411 | Bernardo Dal Seno | _AssertRecreateDisks(["-n", orig_seq], instance, check=False) |
658 | 83180411 | Bernardo Dal Seno | # This and InstanceCheck decoration check that the disks are working
|
659 | 83180411 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "reinstall", "-f", instance["name"]]) |
660 | 83180411 | Bernardo Dal Seno | AssertCommand(["gnt-instance", "start", instance["name"]]) |
661 | 83180411 | Bernardo Dal Seno | |
662 | 83180411 | Bernardo Dal Seno | |
663 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
664 | 5d640672 | Michael Hanselmann | def TestInstanceExport(instance, node): |
665 | bc696589 | Michael Hanselmann | """gnt-backup export -n ..."""
|
666 | 2f4b4f78 | Iustin Pop | name = instance["name"]
|
667 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-backup", "export", "-n", node["primary"], name]) |
668 | 2f4b4f78 | Iustin Pop | return qa_utils.ResolveInstanceName(name)
|
669 | 5d640672 | Michael Hanselmann | |
670 | 5d640672 | Michael Hanselmann | |
671 | 51131cad | Michael Hanselmann | @InstanceCheck(None, INST_DOWN, FIRST_ARG) |
672 | 8d8d650c | Michael Hanselmann | def TestInstanceExportWithRemove(instance, node): |
673 | 8d8d650c | Michael Hanselmann | """gnt-backup export --remove-instance"""
|
674 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-backup", "export", "-n", node["primary"], |
675 | 2f4b4f78 | Iustin Pop | "--remove-instance", instance["name"]]) |
676 | 8d8d650c | Michael Hanselmann | |
677 | 8d8d650c | Michael Hanselmann | |
678 | 5fa0375e | Michael Hanselmann | @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
|
679 | bc696589 | Michael Hanselmann | def TestInstanceExportNoTarget(instance): |
680 | bc696589 | Michael Hanselmann | """gnt-backup export (without target node, should fail)"""
|
681 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-backup", "export", instance["name"]], fail=True) |
682 | bc696589 | Michael Hanselmann | |
683 | bc696589 | Michael Hanselmann | |
684 | 51131cad | Michael Hanselmann | @InstanceCheck(None, INST_DOWN, FIRST_ARG) |
685 | 5fa0375e | Michael Hanselmann | def TestInstanceImport(newinst, node, expnode, name): |
686 | 5d640672 | Michael Hanselmann | """gnt-backup import"""
|
687 | 906a0346 | Bernardo Dal Seno | templ = constants.DT_PLAIN |
688 | d0c8c01d | Iustin Pop | cmd = (["gnt-backup", "import", |
689 | 906a0346 | Bernardo Dal Seno | "--disk-template=%s" % templ,
|
690 | d0c8c01d | Iustin Pop | "--no-ip-check",
|
691 | d0c8c01d | Iustin Pop | "--src-node=%s" % expnode["primary"], |
692 | 304d9f02 | Michael Hanselmann | "--src-dir=%s/%s" % (pathutils.EXPORT_DIR, name),
|
693 | d0c8c01d | Iustin Pop | "--node=%s" % node["primary"]] + |
694 | 1c573fb4 | Iustin Pop | _GetGenericAddParameters(newinst, force_mac=constants.VALUE_GENERATE)) |
695 | d0c8c01d | Iustin Pop | cmd.append(newinst["name"])
|
696 | 2f4b4f78 | Iustin Pop | AssertCommand(cmd) |
697 | 906a0346 | Bernardo Dal Seno | qa_config.SetInstanceTemplate(newinst, templ) |
698 | 283f9d4c | Michael Hanselmann | |
699 | 283f9d4c | Michael Hanselmann | |
700 | 283f9d4c | Michael Hanselmann | def TestBackupList(expnode): |
701 | 283f9d4c | Michael Hanselmann | """gnt-backup list"""
|
702 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-backup", "list", "--node=%s" % expnode["primary"]]) |
703 | e8ae0c20 | Michael Hanselmann | |
704 | 0fdf247d | Michael Hanselmann | qa_utils.GenericQueryTest("gnt-backup", query.EXPORT_FIELDS.keys(),
|
705 | 0fdf247d | Michael Hanselmann | namefield=None, test_unknown=False) |
706 | 0fdf247d | Michael Hanselmann | |
707 | 0fdf247d | Michael Hanselmann | |
708 | 0fdf247d | Michael Hanselmann | def TestBackupListFields(): |
709 | 0fdf247d | Michael Hanselmann | """gnt-backup list-fields"""
|
710 | 0fdf247d | Michael Hanselmann | qa_utils.GenericQueryFieldsTest("gnt-backup", query.EXPORT_FIELDS.keys())
|
711 | f006f110 | Bernardo Dal Seno | |
712 | f006f110 | Bernardo Dal Seno | |
713 | f006f110 | Bernardo Dal Seno | def TestRemoveInstanceOfflineNode(instance, snode, set_offline, set_online): |
714 | f006f110 | Bernardo Dal Seno | """gtn-instance remove with an off-line node
|
715 | f006f110 | Bernardo Dal Seno |
|
716 | f006f110 | Bernardo Dal Seno | @param instance: instance
|
717 | f006f110 | Bernardo Dal Seno | @param snode: secondary node, to be set offline
|
718 | f006f110 | Bernardo Dal Seno | @param set_offline: function to call to set the node off-line
|
719 | f006f110 | Bernardo Dal Seno | @param set_online: function to call to set the node on-line
|
720 | f006f110 | Bernardo Dal Seno |
|
721 | f006f110 | Bernardo Dal Seno | """
|
722 | f006f110 | Bernardo Dal Seno | info = _GetInstanceInfo(instance["name"])
|
723 | f006f110 | Bernardo Dal Seno | set_offline(snode) |
724 | f006f110 | Bernardo Dal Seno | try:
|
725 | f006f110 | Bernardo Dal Seno | TestInstanceRemove(instance) |
726 | f006f110 | Bernardo Dal Seno | finally:
|
727 | f006f110 | Bernardo Dal Seno | set_online(snode) |
728 | f006f110 | Bernardo Dal Seno | # Clean up the disks on the offline node
|
729 | f006f110 | Bernardo Dal Seno | for minor in info["drbd-minors"][snode["primary"]]: |
730 | f006f110 | Bernardo Dal Seno | AssertCommand(["drbdsetup", str(minor), "down"], node=snode) |
731 | f006f110 | Bernardo Dal Seno | AssertCommand(["lvremove", "-f"] + info["volumes"], node=snode) |