Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ e37f47d3

History | View | Annotate | Download (19.1 kB)

1 f89d59b9 Iustin Pop
#!/usr/bin/python -u
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 1e7acc3b Iustin Pop
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
5 a8083063 Iustin Pop
#
6 a8083063 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 a8083063 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 a8083063 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 a8083063 Iustin Pop
# (at your option) any later version.
10 a8083063 Iustin Pop
#
11 a8083063 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 a8083063 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 a8083063 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 a8083063 Iustin Pop
# General Public License for more details.
15 a8083063 Iustin Pop
#
16 a8083063 Iustin Pop
# You should have received a copy of the GNU General Public License
17 a8083063 Iustin Pop
# along with this program; if not, write to the Free Software
18 a8083063 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 a8083063 Iustin Pop
# 02110-1301, USA.
20 a8083063 Iustin Pop
21 a8083063 Iustin Pop
22 cec9845c Michael Hanselmann
"""Script for doing QA on Ganeti.
23 94508060 Michael Hanselmann

24 94508060 Michael Hanselmann
"""
25 a8083063 Iustin Pop
26 b459a848 Andrea Spadaccini
# pylint: disable=C0103
27 3582eef6 Iustin Pop
# due to invalid name
28 3582eef6 Iustin Pop
29 a8083063 Iustin Pop
import sys
30 c68d1f43 Michael Hanselmann
import datetime
31 c68d1f43 Michael Hanselmann
import optparse
32 a8083063 Iustin Pop
33 cec9845c Michael Hanselmann
import qa_cluster
34 cec9845c Michael Hanselmann
import qa_config
35 cec9845c Michael Hanselmann
import qa_daemon
36 cec9845c Michael Hanselmann
import qa_env
37 83180411 Bernardo Dal Seno
import qa_error
38 30131294 Adeodato Simo
import qa_group
39 cec9845c Michael Hanselmann
import qa_instance
40 cec9845c Michael Hanselmann
import qa_node
41 8947cf2b Michael Hanselmann
import qa_os
42 09470dd8 Michael Hanselmann
import qa_job
43 a47f574c Oleksiy Mishchenko
import qa_rapi
44 d74c2ca1 Michael Hanselmann
import qa_tags
45 1672a0d1 Michael Hanselmann
import qa_utils
46 a8083063 Iustin Pop
47 725ec2f1 René Nussbaumer
from ganeti import utils
48 8ad0da1e Iustin Pop
from ganeti import rapi # pylint: disable=W0611
49 f3fd2c9d Adeodato Simo
from ganeti import constants
50 2a7c3583 Michael Hanselmann
51 b459a848 Andrea Spadaccini
import ganeti.rapi.client # pylint: disable=W0611
52 fc3f75dd Iustin Pop
from ganeti.rapi.client import UsesRapiClient
53 725ec2f1 René Nussbaumer
54 a8083063 Iustin Pop
55 7d88f255 Iustin Pop
def _FormatHeader(line, end=72):
56 f89d59b9 Iustin Pop
  """Fill a line up to the end column.
57 f89d59b9 Iustin Pop

58 f89d59b9 Iustin Pop
  """
59 f89d59b9 Iustin Pop
  line = "---- " + line + " "
60 21bf2e2e Andrea Spadaccini
  line += "-" * (end - len(line))
61 f89d59b9 Iustin Pop
  line = line.rstrip()
62 f89d59b9 Iustin Pop
  return line
63 f89d59b9 Iustin Pop
64 f89d59b9 Iustin Pop
65 7d88f255 Iustin Pop
def _DescriptionOf(fn):
66 7d88f255 Iustin Pop
  """Computes the description of an item.
67 a8083063 Iustin Pop

68 a8083063 Iustin Pop
  """
69 cec9845c Michael Hanselmann
  if fn.__doc__:
70 cec9845c Michael Hanselmann
    desc = fn.__doc__.splitlines()[0].strip()
71 a8083063 Iustin Pop
  else:
72 f89d59b9 Iustin Pop
    desc = "%r" % fn
73 a8083063 Iustin Pop
74 7d88f255 Iustin Pop
  return desc.rstrip(".")
75 7d88f255 Iustin Pop
76 2932dc44 Michael Hanselmann
77 741c6d91 Michael Hanselmann
def RunTest(fn, *args, **kwargs):
78 7d88f255 Iustin Pop
  """Runs a test after printing a header.
79 7d88f255 Iustin Pop

80 7d88f255 Iustin Pop
  """
81 a8083063 Iustin Pop
82 f89d59b9 Iustin Pop
  tstart = datetime.datetime.now()
83 a8083063 Iustin Pop
84 7d88f255 Iustin Pop
  desc = _DescriptionOf(fn)
85 7d88f255 Iustin Pop
86 f89d59b9 Iustin Pop
  print
87 f89d59b9 Iustin Pop
  print _FormatHeader("%s start %s" % (tstart, desc))
88 f89d59b9 Iustin Pop
89 f89d59b9 Iustin Pop
  try:
90 741c6d91 Michael Hanselmann
    retval = fn(*args, **kwargs)
91 f89d59b9 Iustin Pop
    return retval
92 f89d59b9 Iustin Pop
  finally:
93 f89d59b9 Iustin Pop
    tstop = datetime.datetime.now()
94 f89d59b9 Iustin Pop
    tdelta = tstop - tstart
95 f89d59b9 Iustin Pop
    print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
96 a8083063 Iustin Pop
97 a8083063 Iustin Pop
98 741c6d91 Michael Hanselmann
def RunTestIf(testnames, fn, *args, **kwargs):
99 7d88f255 Iustin Pop
  """Runs a test conditionally.
100 7d88f255 Iustin Pop

101 7d88f255 Iustin Pop
  @param testnames: either a single test name in the configuration
102 7d88f255 Iustin Pop
      file, or a list of testnames (which will be AND-ed together)
103 7d88f255 Iustin Pop

104 7d88f255 Iustin Pop
  """
105 7d88f255 Iustin Pop
  if qa_config.TestEnabled(testnames):
106 741c6d91 Michael Hanselmann
    RunTest(fn, *args, **kwargs)
107 7d88f255 Iustin Pop
  else:
108 7d88f255 Iustin Pop
    tstart = datetime.datetime.now()
109 7d88f255 Iustin Pop
    desc = _DescriptionOf(fn)
110 7d88f255 Iustin Pop
    print _FormatHeader("%s skipping %s, test(s) %s disabled" %
111 7d88f255 Iustin Pop
                        (tstart, desc, testnames))
112 7d88f255 Iustin Pop
113 7d88f255 Iustin Pop
114 b1ffe1eb Michael Hanselmann
def RunEnvTests():
115 b1ffe1eb Michael Hanselmann
  """Run several environment tests.
116 a8083063 Iustin Pop

117 a8083063 Iustin Pop
  """
118 7d88f255 Iustin Pop
  RunTestIf("env", qa_env.TestSshConnection)
119 7d88f255 Iustin Pop
  RunTestIf("env", qa_env.TestIcmpPing)
120 7d88f255 Iustin Pop
  RunTestIf("env", qa_env.TestGanetiCommands)
121 a8083063 Iustin Pop
122 94508060 Michael Hanselmann
123 725ec2f1 René Nussbaumer
def SetupCluster(rapi_user, rapi_secret):
124 b1ffe1eb Michael Hanselmann
  """Initializes the cluster.
125 a8083063 Iustin Pop

126 725ec2f1 René Nussbaumer
  @param rapi_user: Login user for RAPI
127 725ec2f1 René Nussbaumer
  @param rapi_secret: Login secret for RAPI
128 725ec2f1 René Nussbaumer

129 b1ffe1eb Michael Hanselmann
  """
130 7d88f255 Iustin Pop
  RunTestIf("create-cluster", qa_cluster.TestClusterInit,
131 7d88f255 Iustin Pop
            rapi_user, rapi_secret)
132 288d6440 Michael Hanselmann
133 288d6440 Michael Hanselmann
  # Test on empty cluster
134 288d6440 Michael Hanselmann
  RunTestIf("node-list", qa_node.TestNodeList)
135 288d6440 Michael Hanselmann
  RunTestIf("instance-list", qa_instance.TestInstanceList)
136 09470dd8 Michael Hanselmann
  RunTestIf("job-list", qa_job.TestJobList)
137 288d6440 Michael Hanselmann
138 7d88f255 Iustin Pop
  RunTestIf("create-cluster", qa_node.TestNodeAddAll)
139 7d88f255 Iustin Pop
  if not qa_config.TestEnabled("create-cluster"):
140 8e671b7c Iustin Pop
    # consider the nodes are already there
141 8e671b7c Iustin Pop
    qa_node.MarkNodeAddedAll()
142 8201b996 Iustin Pop
143 7d88f255 Iustin Pop
  RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
144 cd04f8c2 Michael Hanselmann
145 8201b996 Iustin Pop
  # enable the watcher (unconditionally)
146 8201b996 Iustin Pop
  RunTest(qa_daemon.TestResumeWatcher)
147 8201b996 Iustin Pop
148 288d6440 Michael Hanselmann
  RunTestIf("node-list", qa_node.TestNodeList)
149 288d6440 Michael Hanselmann
150 2214cf14 Michael Hanselmann
  # Test listing fields
151 2214cf14 Michael Hanselmann
  RunTestIf("node-list", qa_node.TestNodeListFields)
152 2214cf14 Michael Hanselmann
  RunTestIf("instance-list", qa_instance.TestInstanceListFields)
153 09470dd8 Michael Hanselmann
  RunTestIf("job-list", qa_job.TestJobListFields)
154 0fdf247d Michael Hanselmann
  RunTestIf("instance-export", qa_instance.TestBackupListFields)
155 2214cf14 Michael Hanselmann
156 7d88f255 Iustin Pop
  RunTestIf("node-info", qa_node.TestNodeInfo)
157 b1ffe1eb Michael Hanselmann
158 b1ffe1eb Michael Hanselmann
159 b1ffe1eb Michael Hanselmann
def RunClusterTests():
160 b1ffe1eb Michael Hanselmann
  """Runs tests related to gnt-cluster.
161 180bdd1f Michael Hanselmann

162 b1ffe1eb Michael Hanselmann
  """
163 7d88f255 Iustin Pop
  for test, fn in [
164 92cb4940 Andrea Spadaccini
    ("create-cluster", qa_cluster.TestClusterInitDisk),
165 7d88f255 Iustin Pop
    ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
166 7d88f255 Iustin Pop
    ("cluster-verify", qa_cluster.TestClusterVerify),
167 7d88f255 Iustin Pop
    ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
168 9738ca94 Iustin Pop
    # TODO: add more cluster modify tests
169 1e7acc3b Iustin Pop
    ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
170 7d88f255 Iustin Pop
    ("cluster-modify", qa_cluster.TestClusterModifyBe),
171 92cb4940 Andrea Spadaccini
    ("cluster-modify", qa_cluster.TestClusterModifyDisk),
172 7d88f255 Iustin Pop
    ("cluster-rename", qa_cluster.TestClusterRename),
173 7d88f255 Iustin Pop
    ("cluster-info", qa_cluster.TestClusterVersion),
174 7d88f255 Iustin Pop
    ("cluster-info", qa_cluster.TestClusterInfo),
175 7d88f255 Iustin Pop
    ("cluster-info", qa_cluster.TestClusterGetmaster),
176 3e8b5a9c Iustin Pop
    ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
177 7d88f255 Iustin Pop
    ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
178 7d88f255 Iustin Pop
    ("cluster-command", qa_cluster.TestClusterCommand),
179 7d88f255 Iustin Pop
    ("cluster-burnin", qa_cluster.TestClusterBurnin),
180 7d88f255 Iustin Pop
    ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
181 ff699aa9 Michael Hanselmann
    ("cluster-master-failover",
182 ff699aa9 Michael Hanselmann
     qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
183 69df9d2b Iustin Pop
    ("cluster-oob", qa_cluster.TestClusterOob),
184 7d88f255 Iustin Pop
    ("rapi", qa_rapi.TestVersion),
185 7d88f255 Iustin Pop
    ("rapi", qa_rapi.TestEmptyCluster),
186 4fab7cab Michael Hanselmann
    ("rapi", qa_rapi.TestRapiQuery),
187 7d88f255 Iustin Pop
    ]:
188 7d88f255 Iustin Pop
    RunTestIf(test, fn)
189 8947cf2b Michael Hanselmann
190 6d4a1656 Michael Hanselmann
191 65a884ef Iustin Pop
def RunRepairDiskSizes():
192 65a884ef Iustin Pop
  """Run the repair disk-sizes test.
193 65a884ef Iustin Pop

194 65a884ef Iustin Pop
  """
195 65a884ef Iustin Pop
  RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)
196 65a884ef Iustin Pop
197 65a884ef Iustin Pop
198 b1ffe1eb Michael Hanselmann
def RunOsTests():
199 b1ffe1eb Michael Hanselmann
  """Runs all tests related to gnt-os.
200 5d640672 Michael Hanselmann

201 b1ffe1eb Michael Hanselmann
  """
202 2932dc44 Michael Hanselmann
  if qa_config.TestEnabled("rapi"):
203 2932dc44 Michael Hanselmann
    rapi_getos = qa_rapi.GetOperatingSystems
204 2932dc44 Michael Hanselmann
  else:
205 2932dc44 Michael Hanselmann
    rapi_getos = None
206 2932dc44 Michael Hanselmann
207 7d88f255 Iustin Pop
  for fn in [
208 7d88f255 Iustin Pop
    qa_os.TestOsList,
209 7d88f255 Iustin Pop
    qa_os.TestOsDiagnose,
210 2932dc44 Michael Hanselmann
    ]:
211 2932dc44 Michael Hanselmann
    RunTestIf("os", fn)
212 2932dc44 Michael Hanselmann
213 2932dc44 Michael Hanselmann
  for fn in [
214 7d88f255 Iustin Pop
    qa_os.TestOsValid,
215 7d88f255 Iustin Pop
    qa_os.TestOsInvalid,
216 7d88f255 Iustin Pop
    qa_os.TestOsPartiallyValid,
217 2932dc44 Michael Hanselmann
    ]:
218 2932dc44 Michael Hanselmann
    RunTestIf("os", fn, rapi_getos)
219 2932dc44 Michael Hanselmann
220 2932dc44 Michael Hanselmann
  for fn in [
221 7d88f255 Iustin Pop
    qa_os.TestOsModifyValid,
222 7d88f255 Iustin Pop
    qa_os.TestOsModifyInvalid,
223 074e139f Michael Hanselmann
    qa_os.TestOsStatesNonExisting,
224 7d88f255 Iustin Pop
    ]:
225 7d88f255 Iustin Pop
    RunTestIf("os", fn)
226 b1ffe1eb Michael Hanselmann
227 b1ffe1eb Michael Hanselmann
228 b1ffe1eb Michael Hanselmann
def RunCommonInstanceTests(instance):
229 b1ffe1eb Michael Hanselmann
  """Runs a few tests that are common to all disk types.
230 b1ffe1eb Michael Hanselmann

231 b1ffe1eb Michael Hanselmann
  """
232 7d88f255 Iustin Pop
  RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
233 b82d4c5e Michael Hanselmann
  RunTestIf(["instance-shutdown", "instance-console", "rapi"],
234 b82d4c5e Michael Hanselmann
            qa_rapi.TestRapiStoppedInstanceConsole, instance)
235 3016bc1f Michael Hanselmann
  RunTestIf(["instance-shutdown", "instance-modify"],
236 3016bc1f Michael Hanselmann
            qa_instance.TestInstanceStoppedModify, instance)
237 7d88f255 Iustin Pop
  RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
238 a8083063 Iustin Pop
239 a7418448 Michael Hanselmann
  # Test shutdown/start via RAPI
240 a7418448 Michael Hanselmann
  RunTestIf(["instance-shutdown", "rapi"],
241 a7418448 Michael Hanselmann
            qa_rapi.TestRapiInstanceShutdown, instance)
242 a7418448 Michael Hanselmann
  RunTestIf(["instance-shutdown", "rapi"],
243 a7418448 Michael Hanselmann
            qa_rapi.TestRapiInstanceStartup, instance)
244 a7418448 Michael Hanselmann
245 7d88f255 Iustin Pop
  RunTestIf("instance-list", qa_instance.TestInstanceList)
246 283f9d4c Michael Hanselmann
247 7d88f255 Iustin Pop
  RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
248 e9e35aaa Michael Hanselmann
249 7d88f255 Iustin Pop
  RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
250 7d88f255 Iustin Pop
  RunTestIf(["instance-modify", "rapi"],
251 7d88f255 Iustin Pop
            qa_rapi.TestRapiInstanceModify, instance)
252 c0f74c55 Iustin Pop
253 7d88f255 Iustin Pop
  RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
254 b82d4c5e Michael Hanselmann
  RunTestIf(["instance-console", "rapi"],
255 b82d4c5e Michael Hanselmann
            qa_rapi.TestRapiInstanceConsole, instance)
256 4379b1fa Michael Hanselmann
257 1be35bef Michael Hanselmann
  DOWN_TESTS = qa_config.Either([
258 1be35bef Michael Hanselmann
    "instance-reinstall",
259 1be35bef Michael Hanselmann
    "instance-rename",
260 1be35bef Michael Hanselmann
    "instance-grow-disk",
261 1be35bef Michael Hanselmann
    ])
262 1be35bef Michael Hanselmann
263 4c1a464b Iustin Pop
  # shutdown instance for any 'down' tests
264 4c1a464b Iustin Pop
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
265 4c1a464b Iustin Pop
266 4c1a464b Iustin Pop
  # now run the 'down' state tests
267 7d88f255 Iustin Pop
  RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
268 0220d2cf Guido Trotter
  RunTestIf(["instance-reinstall", "rapi"],
269 0220d2cf Guido Trotter
            qa_rapi.TestRapiInstanceReinstall, instance)
270 8a4e8898 Michael Hanselmann
271 d0c8c01d Iustin Pop
  if qa_config.TestEnabled("instance-rename"):
272 e5c2accd Guido Trotter
    rename_source = instance["name"]
273 7fb50870 Michael Hanselmann
    rename_target = qa_config.get("rename", None)
274 46747143 Guido Trotter
    # perform instance rename to the same name
275 4c1a464b Iustin Pop
    RunTest(qa_instance.TestInstanceRenameAndBack,
276 4c1a464b Iustin Pop
            rename_source, rename_source)
277 4c1a464b Iustin Pop
    RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
278 930e77d1 Michael Hanselmann
              rename_source, rename_source)
279 46747143 Guido Trotter
    if rename_target is not None:
280 46747143 Guido Trotter
      # perform instance rename to a different name, if we have one configured
281 4c1a464b Iustin Pop
      RunTest(qa_instance.TestInstanceRenameAndBack,
282 4c1a464b Iustin Pop
              rename_source, rename_target)
283 4c1a464b Iustin Pop
      RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
284 930e77d1 Michael Hanselmann
                rename_source, rename_target)
285 4c1a464b Iustin Pop
286 26a5056d Iustin Pop
  RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
287 26a5056d Iustin Pop
288 4c1a464b Iustin Pop
  # and now start the instance again
289 4c1a464b Iustin Pop
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
290 4c1a464b Iustin Pop
291 4c1a464b Iustin Pop
  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
292 18337ca9 Iustin Pop
293 7d88f255 Iustin Pop
  RunTestIf("tags", qa_tags.TestInstanceTags, instance)
294 d74c2ca1 Michael Hanselmann
295 1ef6e776 Michael Hanselmann
  RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
296 d74c2ca1 Michael Hanselmann
297 7d88f255 Iustin Pop
  RunTestIf("rapi", qa_rapi.TestInstance, instance)
298 729c4377 Iustin Pop
299 288d6440 Michael Hanselmann
  # Lists instances, too
300 288d6440 Michael Hanselmann
  RunTestIf("node-list", qa_node.TestNodeList)
301 288d6440 Michael Hanselmann
302 09470dd8 Michael Hanselmann
  # Some jobs have been run, let's test listing them
303 09470dd8 Michael Hanselmann
  RunTestIf("job-list", qa_job.TestJobList)
304 09470dd8 Michael Hanselmann
305 729c4377 Iustin Pop
306 729c4377 Iustin Pop
def RunCommonNodeTests():
307 729c4377 Iustin Pop
  """Run a few common node tests.
308 729c4377 Iustin Pop

309 729c4377 Iustin Pop
  """
310 7d88f255 Iustin Pop
  RunTestIf("node-volumes", qa_node.TestNodeVolumes)
311 7d88f255 Iustin Pop
  RunTestIf("node-storage", qa_node.TestNodeStorage)
312 a1de4b18 René Nussbaumer
  RunTestIf("node-oob", qa_node.TestOutOfBand)
313 8e1db003 Michael Hanselmann
314 8d8d650c Michael Hanselmann
315 30131294 Adeodato Simo
def RunGroupListTests():
316 30131294 Adeodato Simo
  """Run tests for listing node groups.
317 30131294 Adeodato Simo

318 30131294 Adeodato Simo
  """
319 7ab8b7d7 Adeodato Simo
  RunTestIf("group-list", qa_group.TestGroupList)
320 7ab8b7d7 Adeodato Simo
  RunTestIf("group-list", qa_group.TestGroupListFields)
321 30131294 Adeodato Simo
322 30131294 Adeodato Simo
323 66787da5 Adeodato Simo
def RunGroupRwTests():
324 66787da5 Adeodato Simo
  """Run tests for adding/removing/renaming groups.
325 66787da5 Adeodato Simo

326 66787da5 Adeodato Simo
  """
327 66787da5 Adeodato Simo
  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
328 4b10fb65 Adeodato Simo
  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
329 4b10fb65 Adeodato Simo
  RunTestIf("group-rwops", qa_group.TestGroupModify)
330 b9e478fe Michael Hanselmann
  RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups)
331 fe508a9d Michael Hanselmann
  RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
332 fe508a9d Michael Hanselmann
            qa_group.GetDefaultGroup())
333 4b10fb65 Adeodato Simo
334 66787da5 Adeodato Simo
335 638a7266 Iustin Pop
def RunExportImportTests(instance, pnode, snode):
336 b1ffe1eb Michael Hanselmann
  """Tries to export and import the instance.
337 a8083063 Iustin Pop

338 638a7266 Iustin Pop
  @param pnode: current primary node of the instance
339 638a7266 Iustin Pop
  @param snode: current secondary node of the instance, if any,
340 638a7266 Iustin Pop
      otherwise None
341 638a7266 Iustin Pop

342 b1ffe1eb Michael Hanselmann
  """
343 d0c8c01d Iustin Pop
  if qa_config.TestEnabled("instance-export"):
344 bc696589 Michael Hanselmann
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)
345 bc696589 Michael Hanselmann
346 b1ffe1eb Michael Hanselmann
    expnode = qa_config.AcquireNode(exclude=pnode)
347 b1ffe1eb Michael Hanselmann
    try:
348 b1ffe1eb Michael Hanselmann
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
349 b1ffe1eb Michael Hanselmann
350 b1ffe1eb Michael Hanselmann
      RunTest(qa_instance.TestBackupList, expnode)
351 b1ffe1eb Michael Hanselmann
352 d0c8c01d Iustin Pop
      if qa_config.TestEnabled("instance-import"):
353 b1ffe1eb Michael Hanselmann
        newinst = qa_config.AcquireInstance()
354 5d640672 Michael Hanselmann
        try:
355 5fa0375e Michael Hanselmann
          RunTest(qa_instance.TestInstanceImport, newinst, pnode,
356 b1ffe1eb Michael Hanselmann
                  expnode, name)
357 51131cad Michael Hanselmann
          # Check if starting the instance works
358 51131cad Michael Hanselmann
          RunTest(qa_instance.TestInstanceStartup, newinst)
359 b1ffe1eb Michael Hanselmann
          RunTest(qa_instance.TestInstanceRemove, newinst)
360 5d640672 Michael Hanselmann
        finally:
361 b1ffe1eb Michael Hanselmann
          qa_config.ReleaseInstance(newinst)
362 b1ffe1eb Michael Hanselmann
    finally:
363 b1ffe1eb Michael Hanselmann
      qa_config.ReleaseNode(expnode)
364 5d640672 Michael Hanselmann
365 7d88f255 Iustin Pop
  if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
366 5d831182 Michael Hanselmann
    newinst = qa_config.AcquireInstance()
367 5d831182 Michael Hanselmann
    try:
368 638a7266 Iustin Pop
      if snode is None:
369 638a7266 Iustin Pop
        excl = [pnode]
370 638a7266 Iustin Pop
      else:
371 638a7266 Iustin Pop
        excl = [pnode, snode]
372 638a7266 Iustin Pop
      tnode = qa_config.AcquireNode(exclude=excl)
373 5d831182 Michael Hanselmann
      try:
374 5d831182 Michael Hanselmann
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
375 638a7266 Iustin Pop
                pnode, snode, tnode)
376 5d831182 Michael Hanselmann
      finally:
377 638a7266 Iustin Pop
        qa_config.ReleaseNode(tnode)
378 5d831182 Michael Hanselmann
    finally:
379 5d831182 Michael Hanselmann
      qa_config.ReleaseInstance(newinst)
380 5d831182 Michael Hanselmann
381 283f9d4c Michael Hanselmann
382 b998270c Iustin Pop
def RunDaemonTests(instance):
383 b1ffe1eb Michael Hanselmann
  """Test the ganeti-watcher script.
384 9df6d173 Michael Hanselmann

385 b1ffe1eb Michael Hanselmann
  """
386 8201b996 Iustin Pop
  RunTest(qa_daemon.TestPauseWatcher)
387 e9e35aaa Michael Hanselmann
388 7d88f255 Iustin Pop
  RunTestIf("instance-automatic-restart",
389 b998270c Iustin Pop
            qa_daemon.TestInstanceAutomaticRestart, instance)
390 7d88f255 Iustin Pop
  RunTestIf("instance-consecutive-failures",
391 b998270c Iustin Pop
            qa_daemon.TestInstanceConsecutiveFailures, instance)
392 e9e35aaa Michael Hanselmann
393 8201b996 Iustin Pop
  RunTest(qa_daemon.TestResumeWatcher)
394 8201b996 Iustin Pop
395 9df6d173 Michael Hanselmann
396 83180411 Bernardo Dal Seno
def RunSingleHomedHardwareFailureTests(instance, pnode):
397 83180411 Bernardo Dal Seno
  """Test hardware failure recovery for single-homed instances.
398 83180411 Bernardo Dal Seno

399 83180411 Bernardo Dal Seno
  """
400 83180411 Bernardo Dal Seno
  if qa_config.TestEnabled("instance-recreate-disks"):
401 83180411 Bernardo Dal Seno
    othernode = qa_config.AcquireNode(exclude=[pnode])
402 83180411 Bernardo Dal Seno
    try:
403 83180411 Bernardo Dal Seno
      RunTest(qa_instance.TestRecreateDisks,
404 83180411 Bernardo Dal Seno
              instance, pnode, None, [othernode])
405 83180411 Bernardo Dal Seno
    finally:
406 83180411 Bernardo Dal Seno
      qa_config.ReleaseNode(othernode)
407 83180411 Bernardo Dal Seno
408 83180411 Bernardo Dal Seno
409 b1ffe1eb Michael Hanselmann
def RunHardwareFailureTests(instance, pnode, snode):
410 b1ffe1eb Michael Hanselmann
  """Test cluster internal hardware failure recovery.
411 a8083063 Iustin Pop

412 b1ffe1eb Michael Hanselmann
  """
413 7d88f255 Iustin Pop
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
414 c0a146a1 Michael Hanselmann
  RunTestIf(["instance-failover", "rapi"],
415 c0a146a1 Michael Hanselmann
            qa_rapi.TestRapiInstanceFailover, instance)
416 b1ffe1eb Michael Hanselmann
417 7d88f255 Iustin Pop
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
418 7d88f255 Iustin Pop
  RunTestIf(["instance-migrate", "rapi"],
419 7d88f255 Iustin Pop
            qa_rapi.TestRapiInstanceMigrate, instance)
420 938bde86 Michael Hanselmann
421 d0c8c01d Iustin Pop
  if qa_config.TestEnabled("instance-replace-disks"):
422 76f59a32 Michael Hanselmann
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
423 7910e7a5 Michael Hanselmann
    try:
424 539d65ba Michael Hanselmann
      RunTestIf("rapi", qa_rapi.TestRapiInstanceReplaceDisks, instance)
425 7910e7a5 Michael Hanselmann
      RunTest(qa_instance.TestReplaceDisks,
426 7910e7a5 Michael Hanselmann
              instance, pnode, snode, othernode)
427 7910e7a5 Michael Hanselmann
    finally:
428 7910e7a5 Michael Hanselmann
      qa_config.ReleaseNode(othernode)
429 7910e7a5 Michael Hanselmann
430 83180411 Bernardo Dal Seno
  if qa_config.TestEnabled("instance-recreate-disks"):
431 83180411 Bernardo Dal Seno
    othernode1 = qa_config.AcquireNode(exclude=[pnode, snode])
432 83180411 Bernardo Dal Seno
    try:
433 83180411 Bernardo Dal Seno
      othernode2 = qa_config.AcquireNode(exclude=[pnode, snode, othernode1])
434 83180411 Bernardo Dal Seno
    except qa_error.OutOfNodesError:
435 83180411 Bernardo Dal Seno
      # Let's reuse one of the nodes if the cluster is not big enough
436 83180411 Bernardo Dal Seno
      othernode2 = pnode
437 83180411 Bernardo Dal Seno
    try:
438 83180411 Bernardo Dal Seno
      RunTest(qa_instance.TestRecreateDisks,
439 83180411 Bernardo Dal Seno
              instance, pnode, snode, [othernode1, othernode2])
440 83180411 Bernardo Dal Seno
    finally:
441 83180411 Bernardo Dal Seno
      qa_config.ReleaseNode(othernode1)
442 83180411 Bernardo Dal Seno
      if othernode2 != pnode:
443 83180411 Bernardo Dal Seno
        qa_config.ReleaseNode(othernode2)
444 83180411 Bernardo Dal Seno
445 7d88f255 Iustin Pop
  RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, pnode, snode)
446 b1ffe1eb Michael Hanselmann
447 7d88f255 Iustin Pop
  RunTestIf("node-failover", qa_node.TestNodeFailover, pnode, snode)
448 b1ffe1eb Michael Hanselmann
449 7d88f255 Iustin Pop
  RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
450 b1ffe1eb Michael Hanselmann
            instance, pnode, snode)
451 7d88f255 Iustin Pop
  RunTestIf("instance-disk-failure",
452 7d88f255 Iustin Pop
            qa_instance.TestInstanceSecondaryDiskFailure, instance,
453 7d88f255 Iustin Pop
            pnode, snode)
454 b1ffe1eb Michael Hanselmann
455 b1ffe1eb Michael Hanselmann
456 f7e6f3c8 Iustin Pop
def RunQa():
457 f7e6f3c8 Iustin Pop
  """Main QA body.
458 b1ffe1eb Michael Hanselmann

459 b1ffe1eb Michael Hanselmann
  """
460 725ec2f1 René Nussbaumer
  rapi_user = "ganeti-qa"
461 725ec2f1 René Nussbaumer
  rapi_secret = utils.GenerateSecret()
462 725ec2f1 René Nussbaumer
463 b1ffe1eb Michael Hanselmann
  RunEnvTests()
464 725ec2f1 René Nussbaumer
  SetupCluster(rapi_user, rapi_secret)
465 2771835c Michael Hanselmann
466 2771835c Michael Hanselmann
  # Load RAPI certificate
467 76917d97 Iustin Pop
  qa_rapi.Setup(rapi_user, rapi_secret)
468 2771835c Michael Hanselmann
469 b1ffe1eb Michael Hanselmann
  RunClusterTests()
470 b1ffe1eb Michael Hanselmann
  RunOsTests()
471 4b62db14 Michael Hanselmann
472 7d88f255 Iustin Pop
  RunTestIf("tags", qa_tags.TestClusterTags)
473 d74c2ca1 Michael Hanselmann
474 729c4377 Iustin Pop
  RunCommonNodeTests()
475 30131294 Adeodato Simo
  RunGroupListTests()
476 66787da5 Adeodato Simo
  RunGroupRwTests()
477 729c4377 Iustin Pop
478 6f058bf2 Bernardo Dal Seno
  # The master shouldn't be readded or put offline; "delay" needs a non-master
479 6f058bf2 Bernardo Dal Seno
  # node to test
480 d0cb68cb Michael Hanselmann
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
481 d0cb68cb Michael Hanselmann
  try:
482 7d88f255 Iustin Pop
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
483 7d88f255 Iustin Pop
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
484 5a85b99e Michael Hanselmann
    RunTestIf("delay", qa_cluster.TestDelay, pnode)
485 d0cb68cb Michael Hanselmann
  finally:
486 d0cb68cb Michael Hanselmann
    qa_config.ReleaseNode(pnode)
487 102b115b Michael Hanselmann
488 b1ffe1eb Michael Hanselmann
  pnode = qa_config.AcquireNode()
489 b1ffe1eb Michael Hanselmann
  try:
490 7d88f255 Iustin Pop
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
491 d74c2ca1 Michael Hanselmann
492 a47f574c Oleksiy Mishchenko
    if qa_rapi.Enabled():
493 a47f574c Oleksiy Mishchenko
      RunTest(qa_rapi.TestNode, pnode)
494 a47f574c Oleksiy Mishchenko
495 8cb70e56 Michael Hanselmann
      if qa_config.TestEnabled("instance-add-plain-disk"):
496 924e95f9 Michael Hanselmann
        for use_client in [True, False]:
497 924e95f9 Michael Hanselmann
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
498 924e95f9 Michael Hanselmann
                                  use_client)
499 b498540e Iustin Pop
          if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
500 b498540e Iustin Pop
            RunCommonInstanceTests(rapi_instance)
501 924e95f9 Michael Hanselmann
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
502 924e95f9 Michael Hanselmann
          del rapi_instance
503 8cb70e56 Michael Hanselmann
504 65a884ef Iustin Pop
    if qa_config.TestEnabled("instance-add-plain-disk"):
505 b1ffe1eb Michael Hanselmann
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
506 b1ffe1eb Michael Hanselmann
      RunCommonInstanceTests(instance)
507 30131294 Adeodato Simo
      RunGroupListTests()
508 24fed61e René Nussbaumer
      RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
509 638a7266 Iustin Pop
      RunExportImportTests(instance, pnode, None)
510 b998270c Iustin Pop
      RunDaemonTests(instance)
511 65a884ef Iustin Pop
      RunRepairDiskSizes()
512 83180411 Bernardo Dal Seno
      RunSingleHomedHardwareFailureTests(instance, pnode)
513 b1ffe1eb Michael Hanselmann
      RunTest(qa_instance.TestInstanceRemove, instance)
514 b1ffe1eb Michael Hanselmann
      del instance
515 9df6d173 Michael Hanselmann
516 7d7609a3 Michael Hanselmann
    multinode_tests = [
517 d0c8c01d Iustin Pop
      ("instance-add-drbd-disk",
518 7d7609a3 Michael Hanselmann
       qa_instance.TestInstanceAddWithDrbdDisk),
519 7d7609a3 Michael Hanselmann
    ]
520 7d7609a3 Michael Hanselmann
521 7d7609a3 Michael Hanselmann
    for name, func in multinode_tests:
522 7d7609a3 Michael Hanselmann
      if qa_config.TestEnabled(name):
523 7d7609a3 Michael Hanselmann
        snode = qa_config.AcquireNode(exclude=pnode)
524 7d7609a3 Michael Hanselmann
        try:
525 7d7609a3 Michael Hanselmann
          instance = RunTest(func, pnode, snode)
526 286b7335 Iustin Pop
          RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, pnode)
527 286b7335 Iustin Pop
          RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, snode)
528 7d7609a3 Michael Hanselmann
          RunCommonInstanceTests(instance)
529 30131294 Adeodato Simo
          RunGroupListTests()
530 479197d5 Bernardo Dal Seno
          RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
531 479197d5 Bernardo Dal Seno
                    constants.INITIAL_NODE_GROUP_NAME,
532 479197d5 Bernardo Dal Seno
                    pnode["primary"], snode["primary"])
533 d0c8c01d Iustin Pop
          if qa_config.TestEnabled("instance-convert-disk"):
534 f9f0ce7f Guido Trotter
            RunTest(qa_instance.TestInstanceShutdown, instance)
535 7f69aabb Iustin Pop
            RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
536 f9f0ce7f Guido Trotter
            RunTest(qa_instance.TestInstanceStartup, instance)
537 638a7266 Iustin Pop
          RunExportImportTests(instance, pnode, snode)
538 7d7609a3 Michael Hanselmann
          RunHardwareFailureTests(instance, pnode, snode)
539 65a884ef Iustin Pop
          RunRepairDiskSizes()
540 7d7609a3 Michael Hanselmann
          RunTest(qa_instance.TestInstanceRemove, instance)
541 7d7609a3 Michael Hanselmann
          del instance
542 7d7609a3 Michael Hanselmann
        finally:
543 7d7609a3 Michael Hanselmann
          qa_config.ReleaseNode(snode)
544 a8083063 Iustin Pop
545 6f058bf2 Bernardo Dal Seno
  finally:
546 6f058bf2 Bernardo Dal Seno
    qa_config.ReleaseNode(pnode)
547 6f058bf2 Bernardo Dal Seno
548 6f058bf2 Bernardo Dal Seno
  # Test removing instance with offline drbd secondary
549 6f058bf2 Bernardo Dal Seno
  if qa_config.TestEnabled("instance-remove-drbd-offline"):
550 6f058bf2 Bernardo Dal Seno
    # Make sure the master is not put offline
551 6f058bf2 Bernardo Dal Seno
    snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
552 6f058bf2 Bernardo Dal Seno
    try:
553 6f058bf2 Bernardo Dal Seno
      pnode = qa_config.AcquireNode(exclude=snode)
554 c7e54e1d Agata Murawska
      try:
555 6f058bf2 Bernardo Dal Seno
        instance = qa_instance.TestInstanceAddWithDrbdDisk(pnode, snode)
556 c7e54e1d Agata Murawska
        qa_node.MakeNodeOffline(snode, "yes")
557 6f058bf2 Bernardo Dal Seno
        try:
558 6f058bf2 Bernardo Dal Seno
          RunTest(qa_instance.TestInstanceRemove, instance)
559 6f058bf2 Bernardo Dal Seno
        finally:
560 6f058bf2 Bernardo Dal Seno
          qa_node.MakeNodeOffline(snode, "no")
561 c7e54e1d Agata Murawska
      finally:
562 6f058bf2 Bernardo Dal Seno
        qa_config.ReleaseNode(pnode)
563 6f058bf2 Bernardo Dal Seno
    finally:
564 6f058bf2 Bernardo Dal Seno
      qa_config.ReleaseNode(snode)
565 c7e54e1d Agata Murawska
566 6f058bf2 Bernardo Dal Seno
  pnode = qa_config.AcquireNode()
567 6f058bf2 Bernardo Dal Seno
  try:
568 7d88f255 Iustin Pop
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
569 3b01286e Michael Hanselmann
      for shutdown in [False, True]:
570 3b01286e Michael Hanselmann
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
571 3b01286e Michael Hanselmann
        expnode = qa_config.AcquireNode(exclude=pnode)
572 3b01286e Michael Hanselmann
        try:
573 3b01286e Michael Hanselmann
          if shutdown:
574 3b01286e Michael Hanselmann
            # Stop instance before exporting and removing it
575 3b01286e Michael Hanselmann
            RunTest(qa_instance.TestInstanceShutdown, instance)
576 3b01286e Michael Hanselmann
          RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
577 3b01286e Michael Hanselmann
          RunTest(qa_instance.TestBackupList, expnode)
578 3b01286e Michael Hanselmann
        finally:
579 3b01286e Michael Hanselmann
          qa_config.ReleaseNode(expnode)
580 3b01286e Michael Hanselmann
        del expnode
581 3b01286e Michael Hanselmann
        del instance
582 8d8d650c Michael Hanselmann
583 a8083063 Iustin Pop
  finally:
584 b1ffe1eb Michael Hanselmann
    qa_config.ReleaseNode(pnode)
585 a8083063 Iustin Pop
586 7d88f255 Iustin Pop
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
587 a8083063 Iustin Pop
588 7d88f255 Iustin Pop
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
589 a8083063 Iustin Pop
590 cec9845c Michael Hanselmann
591 fc3f75dd Iustin Pop
@UsesRapiClient
592 f7e6f3c8 Iustin Pop
def main():
593 f7e6f3c8 Iustin Pop
  """Main program.
594 f7e6f3c8 Iustin Pop

595 f7e6f3c8 Iustin Pop
  """
596 f7e6f3c8 Iustin Pop
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
597 d0c8c01d Iustin Pop
  parser.add_option("--yes-do-it", dest="yes_do_it",
598 5ae4945a Iustin Pop
                    action="store_true",
599 5ae4945a Iustin Pop
                    help="Really execute the tests")
600 f7e6f3c8 Iustin Pop
  (qa_config.options, args) = parser.parse_args()
601 f7e6f3c8 Iustin Pop
602 f7e6f3c8 Iustin Pop
  if len(args) == 1:
603 f7e6f3c8 Iustin Pop
    (config_file, ) = args
604 f7e6f3c8 Iustin Pop
  else:
605 f7e6f3c8 Iustin Pop
    parser.error("Wrong number of arguments.")
606 f7e6f3c8 Iustin Pop
607 f7e6f3c8 Iustin Pop
  if not qa_config.options.yes_do_it:
608 f7e6f3c8 Iustin Pop
    print ("Executing this script irreversibly destroys any Ganeti\n"
609 f7e6f3c8 Iustin Pop
           "configuration on all nodes involved. If you really want\n"
610 f7e6f3c8 Iustin Pop
           "to start testing, supply the --yes-do-it option.")
611 f7e6f3c8 Iustin Pop
    sys.exit(1)
612 f7e6f3c8 Iustin Pop
613 f7e6f3c8 Iustin Pop
  qa_config.Load(config_file)
614 f7e6f3c8 Iustin Pop
615 710bc88c Iustin Pop
  primary = qa_config.GetMasterNode()["primary"]
616 710bc88c Iustin Pop
  qa_utils.StartMultiplexer(primary)
617 710bc88c Iustin Pop
  print ("SSH command for primary node: %s" %
618 710bc88c Iustin Pop
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
619 710bc88c Iustin Pop
  print ("SSH command for other nodes: %s" %
620 710bc88c Iustin Pop
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
621 f7e6f3c8 Iustin Pop
  try:
622 f7e6f3c8 Iustin Pop
    RunQa()
623 f7e6f3c8 Iustin Pop
  finally:
624 f7e6f3c8 Iustin Pop
    qa_utils.CloseMultiplexers()
625 f7e6f3c8 Iustin Pop
626 d0c8c01d Iustin Pop
if __name__ == "__main__":
627 cec9845c Michael Hanselmann
  main()