Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 5fa0375e

History | View | Annotate | Download (16.8 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 30131294 Adeodato Simo
import qa_group
38 cec9845c Michael Hanselmann
import qa_instance
39 cec9845c Michael Hanselmann
import qa_node
40 8947cf2b Michael Hanselmann
import qa_os
41 09470dd8 Michael Hanselmann
import qa_job
42 a47f574c Oleksiy Mishchenko
import qa_rapi
43 d74c2ca1 Michael Hanselmann
import qa_tags
44 1672a0d1 Michael Hanselmann
import qa_utils
45 a8083063 Iustin Pop
46 725ec2f1 René Nussbaumer
from ganeti import utils
47 2a7c3583 Michael Hanselmann
from ganeti import rapi
48 f3fd2c9d Adeodato Simo
from ganeti import constants
49 2a7c3583 Michael Hanselmann
50 b459a848 Andrea Spadaccini
import ganeti.rapi.client # pylint: disable=W0611
51 725ec2f1 René Nussbaumer
52 a8083063 Iustin Pop
53 7d88f255 Iustin Pop
def _FormatHeader(line, end=72):
54 f89d59b9 Iustin Pop
  """Fill a line up to the end column.
55 f89d59b9 Iustin Pop

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

344 b1ffe1eb Michael Hanselmann
  """
345 d0c8c01d Iustin Pop
  if qa_config.TestEnabled("instance-export"):
346 bc696589 Michael Hanselmann
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)
347 bc696589 Michael Hanselmann
348 b1ffe1eb Michael Hanselmann
    expnode = qa_config.AcquireNode(exclude=pnode)
349 b1ffe1eb Michael Hanselmann
    try:
350 b1ffe1eb Michael Hanselmann
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
351 b1ffe1eb Michael Hanselmann
352 b1ffe1eb Michael Hanselmann
      RunTest(qa_instance.TestBackupList, expnode)
353 b1ffe1eb Michael Hanselmann
354 d0c8c01d Iustin Pop
      if qa_config.TestEnabled("instance-import"):
355 b1ffe1eb Michael Hanselmann
        newinst = qa_config.AcquireInstance()
356 5d640672 Michael Hanselmann
        try:
357 5fa0375e Michael Hanselmann
          RunTest(qa_instance.TestInstanceImport, newinst, pnode,
358 b1ffe1eb Michael Hanselmann
                  expnode, name)
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 b1ffe1eb Michael Hanselmann
def RunHardwareFailureTests(instance, pnode, snode):
397 b1ffe1eb Michael Hanselmann
  """Test cluster internal hardware failure recovery.
398 a8083063 Iustin Pop

399 b1ffe1eb Michael Hanselmann
  """
400 7d88f255 Iustin Pop
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
401 c0a146a1 Michael Hanselmann
  RunTestIf(["instance-failover", "rapi"],
402 c0a146a1 Michael Hanselmann
            qa_rapi.TestRapiInstanceFailover, instance)
403 b1ffe1eb Michael Hanselmann
404 7d88f255 Iustin Pop
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
405 7d88f255 Iustin Pop
  RunTestIf(["instance-migrate", "rapi"],
406 7d88f255 Iustin Pop
            qa_rapi.TestRapiInstanceMigrate, instance)
407 938bde86 Michael Hanselmann
408 d0c8c01d Iustin Pop
  if qa_config.TestEnabled("instance-replace-disks"):
409 76f59a32 Michael Hanselmann
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
410 7910e7a5 Michael Hanselmann
    try:
411 539d65ba Michael Hanselmann
      RunTestIf("rapi", qa_rapi.TestRapiInstanceReplaceDisks, instance)
412 7910e7a5 Michael Hanselmann
      RunTest(qa_instance.TestReplaceDisks,
413 7910e7a5 Michael Hanselmann
              instance, pnode, snode, othernode)
414 7910e7a5 Michael Hanselmann
    finally:
415 7910e7a5 Michael Hanselmann
      qa_config.ReleaseNode(othernode)
416 7910e7a5 Michael Hanselmann
417 7d88f255 Iustin Pop
  RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, pnode, snode)
418 b1ffe1eb Michael Hanselmann
419 7d88f255 Iustin Pop
  RunTestIf("node-failover", qa_node.TestNodeFailover, pnode, snode)
420 b1ffe1eb Michael Hanselmann
421 7d88f255 Iustin Pop
  RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
422 b1ffe1eb Michael Hanselmann
            instance, pnode, snode)
423 7d88f255 Iustin Pop
  RunTestIf("instance-disk-failure",
424 7d88f255 Iustin Pop
            qa_instance.TestInstanceSecondaryDiskFailure, instance,
425 7d88f255 Iustin Pop
            pnode, snode)
426 b1ffe1eb Michael Hanselmann
427 b1ffe1eb Michael Hanselmann
428 f7e6f3c8 Iustin Pop
def RunQa():
429 f7e6f3c8 Iustin Pop
  """Main QA body.
430 b1ffe1eb Michael Hanselmann

431 b1ffe1eb Michael Hanselmann
  """
432 725ec2f1 René Nussbaumer
  rapi_user = "ganeti-qa"
433 725ec2f1 René Nussbaumer
  rapi_secret = utils.GenerateSecret()
434 725ec2f1 René Nussbaumer
435 b1ffe1eb Michael Hanselmann
  RunEnvTests()
436 725ec2f1 René Nussbaumer
  SetupCluster(rapi_user, rapi_secret)
437 2771835c Michael Hanselmann
438 2771835c Michael Hanselmann
  # Load RAPI certificate
439 76917d97 Iustin Pop
  qa_rapi.Setup(rapi_user, rapi_secret)
440 2771835c Michael Hanselmann
441 b1ffe1eb Michael Hanselmann
  RunClusterTests()
442 b1ffe1eb Michael Hanselmann
  RunOsTests()
443 4b62db14 Michael Hanselmann
444 7d88f255 Iustin Pop
  RunTestIf("tags", qa_tags.TestClusterTags)
445 d74c2ca1 Michael Hanselmann
446 729c4377 Iustin Pop
  RunCommonNodeTests()
447 30131294 Adeodato Simo
  RunGroupListTests()
448 66787da5 Adeodato Simo
  RunGroupRwTests()
449 729c4377 Iustin Pop
450 d0cb68cb Michael Hanselmann
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
451 d0cb68cb Michael Hanselmann
  try:
452 7d88f255 Iustin Pop
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
453 7d88f255 Iustin Pop
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
454 5a85b99e Michael Hanselmann
    RunTestIf("delay", qa_cluster.TestDelay, pnode)
455 d0cb68cb Michael Hanselmann
  finally:
456 d0cb68cb Michael Hanselmann
    qa_config.ReleaseNode(pnode)
457 102b115b Michael Hanselmann
458 b1ffe1eb Michael Hanselmann
  pnode = qa_config.AcquireNode()
459 b1ffe1eb Michael Hanselmann
  try:
460 7d88f255 Iustin Pop
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
461 d74c2ca1 Michael Hanselmann
462 a47f574c Oleksiy Mishchenko
    if qa_rapi.Enabled():
463 a47f574c Oleksiy Mishchenko
      RunTest(qa_rapi.TestNode, pnode)
464 a47f574c Oleksiy Mishchenko
465 8cb70e56 Michael Hanselmann
      if qa_config.TestEnabled("instance-add-plain-disk"):
466 924e95f9 Michael Hanselmann
        for use_client in [True, False]:
467 924e95f9 Michael Hanselmann
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
468 924e95f9 Michael Hanselmann
                                  use_client)
469 924e95f9 Michael Hanselmann
          RunCommonInstanceTests(rapi_instance)
470 924e95f9 Michael Hanselmann
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
471 924e95f9 Michael Hanselmann
          del rapi_instance
472 8cb70e56 Michael Hanselmann
473 65a884ef Iustin Pop
    if qa_config.TestEnabled("instance-add-plain-disk"):
474 b1ffe1eb Michael Hanselmann
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
475 b1ffe1eb Michael Hanselmann
      RunCommonInstanceTests(instance)
476 30131294 Adeodato Simo
      RunGroupListTests()
477 24fed61e René Nussbaumer
      RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
478 638a7266 Iustin Pop
      RunExportImportTests(instance, pnode, None)
479 b998270c Iustin Pop
      RunDaemonTests(instance)
480 65a884ef Iustin Pop
      RunRepairDiskSizes()
481 b1ffe1eb Michael Hanselmann
      RunTest(qa_instance.TestInstanceRemove, instance)
482 b1ffe1eb Michael Hanselmann
      del instance
483 9df6d173 Michael Hanselmann
484 7d7609a3 Michael Hanselmann
    multinode_tests = [
485 d0c8c01d Iustin Pop
      ("instance-add-drbd-disk",
486 7d7609a3 Michael Hanselmann
       qa_instance.TestInstanceAddWithDrbdDisk),
487 7d7609a3 Michael Hanselmann
    ]
488 7d7609a3 Michael Hanselmann
489 7d7609a3 Michael Hanselmann
    for name, func in multinode_tests:
490 7d7609a3 Michael Hanselmann
      if qa_config.TestEnabled(name):
491 7d7609a3 Michael Hanselmann
        snode = qa_config.AcquireNode(exclude=pnode)
492 7d7609a3 Michael Hanselmann
        try:
493 7d7609a3 Michael Hanselmann
          instance = RunTest(func, pnode, snode)
494 7d7609a3 Michael Hanselmann
          RunCommonInstanceTests(instance)
495 30131294 Adeodato Simo
          RunGroupListTests()
496 f3fd2c9d Adeodato Simo
          RunTest(qa_group.TestAssignNodesIncludingSplit,
497 f3fd2c9d Adeodato Simo
                  constants.INITIAL_NODE_GROUP_NAME,
498 f3fd2c9d Adeodato Simo
                  pnode["primary"], snode["primary"])
499 d0c8c01d Iustin Pop
          if qa_config.TestEnabled("instance-convert-disk"):
500 f9f0ce7f Guido Trotter
            RunTest(qa_instance.TestInstanceShutdown, instance)
501 7f69aabb Iustin Pop
            RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
502 f9f0ce7f Guido Trotter
            RunTest(qa_instance.TestInstanceStartup, instance)
503 638a7266 Iustin Pop
          RunExportImportTests(instance, pnode, snode)
504 7d7609a3 Michael Hanselmann
          RunHardwareFailureTests(instance, pnode, snode)
505 65a884ef Iustin Pop
          RunRepairDiskSizes()
506 7d7609a3 Michael Hanselmann
          RunTest(qa_instance.TestInstanceRemove, instance)
507 7d7609a3 Michael Hanselmann
          del instance
508 7d7609a3 Michael Hanselmann
        finally:
509 7d7609a3 Michael Hanselmann
          qa_config.ReleaseNode(snode)
510 a8083063 Iustin Pop
511 7d88f255 Iustin Pop
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
512 3b01286e Michael Hanselmann
      for shutdown in [False, True]:
513 3b01286e Michael Hanselmann
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
514 3b01286e Michael Hanselmann
        expnode = qa_config.AcquireNode(exclude=pnode)
515 3b01286e Michael Hanselmann
        try:
516 3b01286e Michael Hanselmann
          if shutdown:
517 3b01286e Michael Hanselmann
            # Stop instance before exporting and removing it
518 3b01286e Michael Hanselmann
            RunTest(qa_instance.TestInstanceShutdown, instance)
519 3b01286e Michael Hanselmann
          RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
520 3b01286e Michael Hanselmann
          RunTest(qa_instance.TestBackupList, expnode)
521 3b01286e Michael Hanselmann
        finally:
522 3b01286e Michael Hanselmann
          qa_config.ReleaseNode(expnode)
523 3b01286e Michael Hanselmann
        del expnode
524 3b01286e Michael Hanselmann
        del instance
525 8d8d650c Michael Hanselmann
526 a8083063 Iustin Pop
  finally:
527 b1ffe1eb Michael Hanselmann
    qa_config.ReleaseNode(pnode)
528 a8083063 Iustin Pop
529 7d88f255 Iustin Pop
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
530 a8083063 Iustin Pop
531 7d88f255 Iustin Pop
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
532 a8083063 Iustin Pop
533 cec9845c Michael Hanselmann
534 f7e6f3c8 Iustin Pop
@rapi.client.UsesRapiClient
535 f7e6f3c8 Iustin Pop
def main():
536 f7e6f3c8 Iustin Pop
  """Main program.
537 f7e6f3c8 Iustin Pop

538 f7e6f3c8 Iustin Pop
  """
539 f7e6f3c8 Iustin Pop
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
540 d0c8c01d Iustin Pop
  parser.add_option("--yes-do-it", dest="yes_do_it",
541 f7e6f3c8 Iustin Pop
      action="store_true",
542 f7e6f3c8 Iustin Pop
      help="Really execute the tests")
543 f7e6f3c8 Iustin Pop
  (qa_config.options, args) = parser.parse_args()
544 f7e6f3c8 Iustin Pop
545 f7e6f3c8 Iustin Pop
  if len(args) == 1:
546 f7e6f3c8 Iustin Pop
    (config_file, ) = args
547 f7e6f3c8 Iustin Pop
  else:
548 f7e6f3c8 Iustin Pop
    parser.error("Wrong number of arguments.")
549 f7e6f3c8 Iustin Pop
550 f7e6f3c8 Iustin Pop
  if not qa_config.options.yes_do_it:
551 f7e6f3c8 Iustin Pop
    print ("Executing this script irreversibly destroys any Ganeti\n"
552 f7e6f3c8 Iustin Pop
           "configuration on all nodes involved. If you really want\n"
553 f7e6f3c8 Iustin Pop
           "to start testing, supply the --yes-do-it option.")
554 f7e6f3c8 Iustin Pop
    sys.exit(1)
555 f7e6f3c8 Iustin Pop
556 f7e6f3c8 Iustin Pop
  qa_config.Load(config_file)
557 f7e6f3c8 Iustin Pop
558 f7e6f3c8 Iustin Pop
  qa_utils.StartMultiplexer(qa_config.GetMasterNode()["primary"])
559 f7e6f3c8 Iustin Pop
  try:
560 f7e6f3c8 Iustin Pop
    RunQa()
561 f7e6f3c8 Iustin Pop
  finally:
562 f7e6f3c8 Iustin Pop
    qa_utils.CloseMultiplexers()
563 f7e6f3c8 Iustin Pop
564 d0c8c01d Iustin Pop
if __name__ == "__main__":
565 cec9845c Michael Hanselmann
  main()