ganeti-qa.py 16.7 KB
Newer Older
Iustin Pop's avatar
Iustin Pop committed
1
#!/usr/bin/python -u
Iustin Pop's avatar
Iustin Pop committed
2
3
#

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


22
"""Script for doing QA on Ganeti.
23
24

"""
Iustin Pop's avatar
Iustin Pop committed
25

26
# pylint: disable=C0103
Iustin Pop's avatar
Iustin Pop committed
27
28
# due to invalid name

Iustin Pop's avatar
Iustin Pop committed
29
import sys
30
31
import datetime
import optparse
Iustin Pop's avatar
Iustin Pop committed
32

33
34
35
36
import qa_cluster
import qa_config
import qa_daemon
import qa_env
37
import qa_group
38
39
import qa_instance
import qa_node
40
import qa_os
41
import qa_job
Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
42
import qa_rapi
Michael Hanselmann's avatar
Michael Hanselmann committed
43
import qa_tags
44
import qa_utils
Iustin Pop's avatar
Iustin Pop committed
45

46
from ganeti import utils
47
from ganeti import rapi
48
from ganeti import constants
49

50
import ganeti.rapi.client # pylint: disable=W0611
51

Iustin Pop's avatar
Iustin Pop committed
52

Iustin Pop's avatar
Iustin Pop committed
53
def _FormatHeader(line, end=72):
Iustin Pop's avatar
Iustin Pop committed
54
55
56
57
  """Fill a line up to the end column.

  """
  line = "---- " + line + " "
Andrea Spadaccini's avatar
Andrea Spadaccini committed
58
  line += "-" * (end - len(line))
Iustin Pop's avatar
Iustin Pop committed
59
60
61
62
  line = line.rstrip()
  return line


Iustin Pop's avatar
Iustin Pop committed
63
64
def _DescriptionOf(fn):
  """Computes the description of an item.
Iustin Pop's avatar
Iustin Pop committed
65
66

  """
67
68
  if fn.__doc__:
    desc = fn.__doc__.splitlines()[0].strip()
Iustin Pop's avatar
Iustin Pop committed
69
  else:
Iustin Pop's avatar
Iustin Pop committed
70
    desc = "%r" % fn
Iustin Pop's avatar
Iustin Pop committed
71

Iustin Pop's avatar
Iustin Pop committed
72
73
  return desc.rstrip(".")

74

75
def RunTest(fn, *args, **kwargs):
Iustin Pop's avatar
Iustin Pop committed
76
77
78
  """Runs a test after printing a header.

  """
Iustin Pop's avatar
Iustin Pop committed
79

Iustin Pop's avatar
Iustin Pop committed
80
  tstart = datetime.datetime.now()
Iustin Pop's avatar
Iustin Pop committed
81

Iustin Pop's avatar
Iustin Pop committed
82
83
  desc = _DescriptionOf(fn)

Iustin Pop's avatar
Iustin Pop committed
84
85
86
87
  print
  print _FormatHeader("%s start %s" % (tstart, desc))

  try:
88
    retval = fn(*args, **kwargs)
Iustin Pop's avatar
Iustin Pop committed
89
90
91
92
93
    return retval
  finally:
    tstop = datetime.datetime.now()
    tdelta = tstop - tstart
    print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
Iustin Pop's avatar
Iustin Pop committed
94
95


96
def RunTestIf(testnames, fn, *args, **kwargs):
Iustin Pop's avatar
Iustin Pop committed
97
98
99
100
101
102
103
  """Runs a test conditionally.

  @param testnames: either a single test name in the configuration
      file, or a list of testnames (which will be AND-ed together)

  """
  if qa_config.TestEnabled(testnames):
104
    RunTest(fn, *args, **kwargs)
Iustin Pop's avatar
Iustin Pop committed
105
106
107
108
109
110
111
  else:
    tstart = datetime.datetime.now()
    desc = _DescriptionOf(fn)
    print _FormatHeader("%s skipping %s, test(s) %s disabled" %
                        (tstart, desc, testnames))


Michael Hanselmann's avatar
Michael Hanselmann committed
112
113
def RunEnvTests():
  """Run several environment tests.
Iustin Pop's avatar
Iustin Pop committed
114
115

  """
Iustin Pop's avatar
Iustin Pop committed
116
117
118
  RunTestIf("env", qa_env.TestSshConnection)
  RunTestIf("env", qa_env.TestIcmpPing)
  RunTestIf("env", qa_env.TestGanetiCommands)
Iustin Pop's avatar
Iustin Pop committed
119

120

121
def SetupCluster(rapi_user, rapi_secret):
Michael Hanselmann's avatar
Michael Hanselmann committed
122
  """Initializes the cluster.
Iustin Pop's avatar
Iustin Pop committed
123

124
125
126
  @param rapi_user: Login user for RAPI
  @param rapi_secret: Login secret for RAPI

Michael Hanselmann's avatar
Michael Hanselmann committed
127
  """
Iustin Pop's avatar
Iustin Pop committed
128
129
  RunTestIf("create-cluster", qa_cluster.TestClusterInit,
            rapi_user, rapi_secret)
130
131
132
133

  # Test on empty cluster
  RunTestIf("node-list", qa_node.TestNodeList)
  RunTestIf("instance-list", qa_instance.TestInstanceList)
134
  RunTestIf("job-list", qa_job.TestJobList)
135

Iustin Pop's avatar
Iustin Pop committed
136
137
  RunTestIf("create-cluster", qa_node.TestNodeAddAll)
  if not qa_config.TestEnabled("create-cluster"):
138
139
    # consider the nodes are already there
    qa_node.MarkNodeAddedAll()
140

Iustin Pop's avatar
Iustin Pop committed
141
  RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
142

143
144
145
  # enable the watcher (unconditionally)
  RunTest(qa_daemon.TestResumeWatcher)

146
147
  RunTestIf("node-list", qa_node.TestNodeList)

148
149
150
  # Test listing fields
  RunTestIf("node-list", qa_node.TestNodeListFields)
  RunTestIf("instance-list", qa_instance.TestInstanceListFields)
151
  RunTestIf("job-list", qa_job.TestJobListFields)
152
  RunTestIf("instance-export", qa_instance.TestBackupListFields)
153

Iustin Pop's avatar
Iustin Pop committed
154
  RunTestIf("node-info", qa_node.TestNodeInfo)
Michael Hanselmann's avatar
Michael Hanselmann committed
155
156
157
158


def RunClusterTests():
  """Runs tests related to gnt-cluster.
159

Michael Hanselmann's avatar
Michael Hanselmann committed
160
  """
Iustin Pop's avatar
Iustin Pop committed
161
  for test, fn in [
162
    ("create-cluster", qa_cluster.TestClusterInitDisk),
Iustin Pop's avatar
Iustin Pop committed
163
164
165
    ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
    ("cluster-verify", qa_cluster.TestClusterVerify),
    ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
166
    # TODO: add more cluster modify tests
167
    ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
Iustin Pop's avatar
Iustin Pop committed
168
    ("cluster-modify", qa_cluster.TestClusterModifyBe),
169
    ("cluster-modify", qa_cluster.TestClusterModifyDisk),
Iustin Pop's avatar
Iustin Pop committed
170
171
172
173
    ("cluster-rename", qa_cluster.TestClusterRename),
    ("cluster-info", qa_cluster.TestClusterVersion),
    ("cluster-info", qa_cluster.TestClusterInfo),
    ("cluster-info", qa_cluster.TestClusterGetmaster),
Iustin Pop's avatar
Iustin Pop committed
174
    ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
Iustin Pop's avatar
Iustin Pop committed
175
176
177
178
    ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
    ("cluster-command", qa_cluster.TestClusterCommand),
    ("cluster-burnin", qa_cluster.TestClusterBurnin),
    ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
179
180
    ("cluster-master-failover",
     qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
Iustin Pop's avatar
Iustin Pop committed
181
    ("cluster-oob", qa_cluster.TestClusterOob),
Iustin Pop's avatar
Iustin Pop committed
182
183
    ("rapi", qa_rapi.TestVersion),
    ("rapi", qa_rapi.TestEmptyCluster),
184
    ("rapi", qa_rapi.TestRapiQuery),
Iustin Pop's avatar
Iustin Pop committed
185
186
    ]:
    RunTestIf(test, fn)
187

188

189
190
191
192
193
194
195
def RunRepairDiskSizes():
  """Run the repair disk-sizes test.

  """
  RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)


Michael Hanselmann's avatar
Michael Hanselmann committed
196
197
def RunOsTests():
  """Runs all tests related to gnt-os.
Michael Hanselmann's avatar
Michael Hanselmann committed
198

Michael Hanselmann's avatar
Michael Hanselmann committed
199
  """
200
201
202
203
204
  if qa_config.TestEnabled("rapi"):
    rapi_getos = qa_rapi.GetOperatingSystems
  else:
    rapi_getos = None

Iustin Pop's avatar
Iustin Pop committed
205
206
207
  for fn in [
    qa_os.TestOsList,
    qa_os.TestOsDiagnose,
208
209
210
211
    ]:
    RunTestIf("os", fn)

  for fn in [
Iustin Pop's avatar
Iustin Pop committed
212
213
214
    qa_os.TestOsValid,
    qa_os.TestOsInvalid,
    qa_os.TestOsPartiallyValid,
215
216
217
218
    ]:
    RunTestIf("os", fn, rapi_getos)

  for fn in [
Iustin Pop's avatar
Iustin Pop committed
219
220
    qa_os.TestOsModifyValid,
    qa_os.TestOsModifyInvalid,
221
    qa_os.TestOsStatesNonExisting,
Iustin Pop's avatar
Iustin Pop committed
222
223
    ]:
    RunTestIf("os", fn)
Michael Hanselmann's avatar
Michael Hanselmann committed
224
225
226
227
228
229


def RunCommonInstanceTests(instance):
  """Runs a few tests that are common to all disk types.

  """
Iustin Pop's avatar
Iustin Pop committed
230
  RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
231
232
  RunTestIf(["instance-shutdown", "instance-console", "rapi"],
            qa_rapi.TestRapiStoppedInstanceConsole, instance)
233
234
  RunTestIf(["instance-shutdown", "instance-modify"],
            qa_instance.TestInstanceStoppedModify, instance)
Iustin Pop's avatar
Iustin Pop committed
235
  RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
Iustin Pop's avatar
Iustin Pop committed
236

237
238
239
240
241
242
  # Test shutdown/start via RAPI
  RunTestIf(["instance-shutdown", "rapi"],
            qa_rapi.TestRapiInstanceShutdown, instance)
  RunTestIf(["instance-shutdown", "rapi"],
            qa_rapi.TestRapiInstanceStartup, instance)

Iustin Pop's avatar
Iustin Pop committed
243
  RunTestIf("instance-list", qa_instance.TestInstanceList)
Michael Hanselmann's avatar
Michael Hanselmann committed
244

Iustin Pop's avatar
Iustin Pop committed
245
  RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
246

Iustin Pop's avatar
Iustin Pop committed
247
248
249
  RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
  RunTestIf(["instance-modify", "rapi"],
            qa_rapi.TestRapiInstanceModify, instance)
250

Iustin Pop's avatar
Iustin Pop committed
251
  RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
252
253
  RunTestIf(["instance-console", "rapi"],
            qa_rapi.TestRapiInstanceConsole, instance)
254

255
256
257
258
259
260
  DOWN_TESTS = qa_config.Either([
    "instance-reinstall",
    "instance-rename",
    "instance-grow-disk",
    ])

Iustin Pop's avatar
Iustin Pop committed
261
262
263
264
  # shutdown instance for any 'down' tests
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)

  # now run the 'down' state tests
Iustin Pop's avatar
Iustin Pop committed
265
  RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
266
267
  RunTestIf(["instance-reinstall", "rapi"],
            qa_rapi.TestRapiInstanceReinstall, instance)
268

Iustin Pop's avatar
Iustin Pop committed
269
  if qa_config.TestEnabled("instance-rename"):
270
    rename_source = instance["name"]
271
    rename_target = qa_config.get("rename", None)
272
    # perform instance rename to the same name
Iustin Pop's avatar
Iustin Pop committed
273
274
275
    RunTest(qa_instance.TestInstanceRenameAndBack,
            rename_source, rename_source)
    RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
276
              rename_source, rename_source)
277
278
    if rename_target is not None:
      # perform instance rename to a different name, if we have one configured
Iustin Pop's avatar
Iustin Pop committed
279
280
281
      RunTest(qa_instance.TestInstanceRenameAndBack,
              rename_source, rename_target)
      RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
282
                rename_source, rename_target)
Iustin Pop's avatar
Iustin Pop committed
283

Iustin Pop's avatar
Iustin Pop committed
284
285
  RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)

Iustin Pop's avatar
Iustin Pop committed
286
287
288
289
  # and now start the instance again
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)

  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
290

Iustin Pop's avatar
Iustin Pop committed
291
  RunTestIf("tags", qa_tags.TestInstanceTags, instance)
Michael Hanselmann's avatar
Michael Hanselmann committed
292

Michael Hanselmann's avatar
Michael Hanselmann committed
293
  RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
Michael Hanselmann's avatar
Michael Hanselmann committed
294

Iustin Pop's avatar
Iustin Pop committed
295
  RunTestIf("rapi", qa_rapi.TestInstance, instance)
296

297
298
299
  # Lists instances, too
  RunTestIf("node-list", qa_node.TestNodeList)

300
301
302
  # Some jobs have been run, let's test listing them
  RunTestIf("job-list", qa_job.TestJobList)

303
304
305
306
307

def RunCommonNodeTests():
  """Run a few common node tests.

  """
Iustin Pop's avatar
Iustin Pop committed
308
309
  RunTestIf("node-volumes", qa_node.TestNodeVolumes)
  RunTestIf("node-storage", qa_node.TestNodeStorage)
310
  RunTestIf("node-oob", qa_node.TestOutOfBand)
311

312

313
314
315
316
def RunGroupListTests():
  """Run tests for listing node groups.

  """
317
318
  RunTestIf("group-list", qa_group.TestGroupList)
  RunTestIf("group-list", qa_group.TestGroupListFields)
319
320


321
322
323
324
325
def RunGroupRwTests():
  """Run tests for adding/removing/renaming groups.

  """
  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
326
327
  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
  RunTestIf("group-rwops", qa_group.TestGroupModify)
328
  RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups)
329
330
  RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
            qa_group.GetDefaultGroup())
331

332

333
def RunExportImportTests(instance, pnode, snode):
Michael Hanselmann's avatar
Michael Hanselmann committed
334
  """Tries to export and import the instance.
Iustin Pop's avatar
Iustin Pop committed
335

336
337
338
339
  @param pnode: current primary node of the instance
  @param snode: current secondary node of the instance, if any,
      otherwise None

Michael Hanselmann's avatar
Michael Hanselmann committed
340
  """
Iustin Pop's avatar
Iustin Pop committed
341
  if qa_config.TestEnabled("instance-export"):
342
343
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)

Michael Hanselmann's avatar
Michael Hanselmann committed
344
345
346
347
348
349
    expnode = qa_config.AcquireNode(exclude=pnode)
    try:
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)

      RunTest(qa_instance.TestBackupList, expnode)

Iustin Pop's avatar
Iustin Pop committed
350
      if qa_config.TestEnabled("instance-import"):
Michael Hanselmann's avatar
Michael Hanselmann committed
351
        newinst = qa_config.AcquireInstance()
Michael Hanselmann's avatar
Michael Hanselmann committed
352
        try:
353
          RunTest(qa_instance.TestInstanceImport, newinst, pnode,
Michael Hanselmann's avatar
Michael Hanselmann committed
354
                  expnode, name)
355
356
          # Check if starting the instance works
          RunTest(qa_instance.TestInstanceStartup, newinst)
Michael Hanselmann's avatar
Michael Hanselmann committed
357
          RunTest(qa_instance.TestInstanceRemove, newinst)
Michael Hanselmann's avatar
Michael Hanselmann committed
358
        finally:
Michael Hanselmann's avatar
Michael Hanselmann committed
359
360
361
          qa_config.ReleaseInstance(newinst)
    finally:
      qa_config.ReleaseNode(expnode)
Michael Hanselmann's avatar
Michael Hanselmann committed
362

Iustin Pop's avatar
Iustin Pop committed
363
  if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
364
365
    newinst = qa_config.AcquireInstance()
    try:
366
367
368
369
370
      if snode is None:
        excl = [pnode]
      else:
        excl = [pnode, snode]
      tnode = qa_config.AcquireNode(exclude=excl)
371
372
      try:
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
373
                pnode, snode, tnode)
374
      finally:
375
        qa_config.ReleaseNode(tnode)
376
377
378
    finally:
      qa_config.ReleaseInstance(newinst)

Michael Hanselmann's avatar
Michael Hanselmann committed
379

380
def RunDaemonTests(instance):
Michael Hanselmann's avatar
Michael Hanselmann committed
381
  """Test the ganeti-watcher script.
382

Michael Hanselmann's avatar
Michael Hanselmann committed
383
  """
384
  RunTest(qa_daemon.TestPauseWatcher)
385

Iustin Pop's avatar
Iustin Pop committed
386
  RunTestIf("instance-automatic-restart",
387
            qa_daemon.TestInstanceAutomaticRestart, instance)
Iustin Pop's avatar
Iustin Pop committed
388
  RunTestIf("instance-consecutive-failures",
389
            qa_daemon.TestInstanceConsecutiveFailures, instance)
390

391
392
  RunTest(qa_daemon.TestResumeWatcher)

393

Michael Hanselmann's avatar
Michael Hanselmann committed
394
395
def RunHardwareFailureTests(instance, pnode, snode):
  """Test cluster internal hardware failure recovery.
Iustin Pop's avatar
Iustin Pop committed
396

Michael Hanselmann's avatar
Michael Hanselmann committed
397
  """
Iustin Pop's avatar
Iustin Pop committed
398
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
399
400
  RunTestIf(["instance-failover", "rapi"],
            qa_rapi.TestRapiInstanceFailover, instance)
Michael Hanselmann's avatar
Michael Hanselmann committed
401

Iustin Pop's avatar
Iustin Pop committed
402
403
404
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
  RunTestIf(["instance-migrate", "rapi"],
            qa_rapi.TestRapiInstanceMigrate, instance)
405

Iustin Pop's avatar
Iustin Pop committed
406
  if qa_config.TestEnabled("instance-replace-disks"):
407
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
408
    try:
409
      RunTestIf("rapi", qa_rapi.TestRapiInstanceReplaceDisks, instance)
410
411
412
413
414
      RunTest(qa_instance.TestReplaceDisks,
              instance, pnode, snode, othernode)
    finally:
      qa_config.ReleaseNode(othernode)

Iustin Pop's avatar
Iustin Pop committed
415
  RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, pnode, snode)
Michael Hanselmann's avatar
Michael Hanselmann committed
416

Iustin Pop's avatar
Iustin Pop committed
417
  RunTestIf("node-failover", qa_node.TestNodeFailover, pnode, snode)
Michael Hanselmann's avatar
Michael Hanselmann committed
418

Iustin Pop's avatar
Iustin Pop committed
419
  RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
Michael Hanselmann's avatar
Michael Hanselmann committed
420
            instance, pnode, snode)
Iustin Pop's avatar
Iustin Pop committed
421
422
423
  RunTestIf("instance-disk-failure",
            qa_instance.TestInstanceSecondaryDiskFailure, instance,
            pnode, snode)
Michael Hanselmann's avatar
Michael Hanselmann committed
424
425


426
427
def RunQa():
  """Main QA body.
Michael Hanselmann's avatar
Michael Hanselmann committed
428
429

  """
430
431
432
  rapi_user = "ganeti-qa"
  rapi_secret = utils.GenerateSecret()

Michael Hanselmann's avatar
Michael Hanselmann committed
433
  RunEnvTests()
434
  SetupCluster(rapi_user, rapi_secret)
Michael Hanselmann's avatar
Michael Hanselmann committed
435
436

  # Load RAPI certificate
437
  qa_rapi.Setup(rapi_user, rapi_secret)
Michael Hanselmann's avatar
Michael Hanselmann committed
438

Michael Hanselmann's avatar
Michael Hanselmann committed
439
440
  RunClusterTests()
  RunOsTests()
441

Iustin Pop's avatar
Iustin Pop committed
442
  RunTestIf("tags", qa_tags.TestClusterTags)
Michael Hanselmann's avatar
Michael Hanselmann committed
443

444
  RunCommonNodeTests()
445
  RunGroupListTests()
446
  RunGroupRwTests()
447

448
449
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
  try:
Iustin Pop's avatar
Iustin Pop committed
450
451
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
452
    RunTestIf("delay", qa_cluster.TestDelay, pnode)
453
454
  finally:
    qa_config.ReleaseNode(pnode)
455

Michael Hanselmann's avatar
Michael Hanselmann committed
456
457
  pnode = qa_config.AcquireNode()
  try:
Iustin Pop's avatar
Iustin Pop committed
458
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
Michael Hanselmann's avatar
Michael Hanselmann committed
459

Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
460
461
462
    if qa_rapi.Enabled():
      RunTest(qa_rapi.TestNode, pnode)

463
      if qa_config.TestEnabled("instance-add-plain-disk"):
464
465
466
467
468
469
        for use_client in [True, False]:
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
                                  use_client)
          RunCommonInstanceTests(rapi_instance)
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
          del rapi_instance
470

471
    if qa_config.TestEnabled("instance-add-plain-disk"):
Michael Hanselmann's avatar
Michael Hanselmann committed
472
473
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
      RunCommonInstanceTests(instance)
474
      RunGroupListTests()
475
      RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
476
      RunExportImportTests(instance, pnode, None)
477
      RunDaemonTests(instance)
478
      RunRepairDiskSizes()
Michael Hanselmann's avatar
Michael Hanselmann committed
479
480
      RunTest(qa_instance.TestInstanceRemove, instance)
      del instance
481

482
    multinode_tests = [
Iustin Pop's avatar
Iustin Pop committed
483
      ("instance-add-drbd-disk",
484
485
486
487
488
489
490
491
492
       qa_instance.TestInstanceAddWithDrbdDisk),
    ]

    for name, func in multinode_tests:
      if qa_config.TestEnabled(name):
        snode = qa_config.AcquireNode(exclude=pnode)
        try:
          instance = RunTest(func, pnode, snode)
          RunCommonInstanceTests(instance)
493
          RunGroupListTests()
494
495
496
          RunTest(qa_group.TestAssignNodesIncludingSplit,
                  constants.INITIAL_NODE_GROUP_NAME,
                  pnode["primary"], snode["primary"])
Iustin Pop's avatar
Iustin Pop committed
497
          if qa_config.TestEnabled("instance-convert-disk"):
498
            RunTest(qa_instance.TestInstanceShutdown, instance)
499
            RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
500
            RunTest(qa_instance.TestInstanceStartup, instance)
501
          RunExportImportTests(instance, pnode, snode)
502
          RunHardwareFailureTests(instance, pnode, snode)
503
          RunRepairDiskSizes()
504
505
506
507
          RunTest(qa_instance.TestInstanceRemove, instance)
          del instance
        finally:
          qa_config.ReleaseNode(snode)
Iustin Pop's avatar
Iustin Pop committed
508

Iustin Pop's avatar
Iustin Pop committed
509
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
510
511
512
513
514
515
516
517
518
519
520
521
522
      for shutdown in [False, True]:
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
        expnode = qa_config.AcquireNode(exclude=pnode)
        try:
          if shutdown:
            # Stop instance before exporting and removing it
            RunTest(qa_instance.TestInstanceShutdown, instance)
          RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
          RunTest(qa_instance.TestBackupList, expnode)
        finally:
          qa_config.ReleaseNode(expnode)
        del expnode
        del instance
523

Iustin Pop's avatar
Iustin Pop committed
524
  finally:
Michael Hanselmann's avatar
Michael Hanselmann committed
525
    qa_config.ReleaseNode(pnode)
Iustin Pop's avatar
Iustin Pop committed
526

Iustin Pop's avatar
Iustin Pop committed
527
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
Iustin Pop's avatar
Iustin Pop committed
528

Iustin Pop's avatar
Iustin Pop committed
529
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
Iustin Pop's avatar
Iustin Pop committed
530

531

532
533
534
535
536
537
@rapi.client.UsesRapiClient
def main():
  """Main program.

  """
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
Iustin Pop's avatar
Iustin Pop committed
538
  parser.add_option("--yes-do-it", dest="yes_do_it",
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
      action="store_true",
      help="Really execute the tests")
  (qa_config.options, args) = parser.parse_args()

  if len(args) == 1:
    (config_file, ) = args
  else:
    parser.error("Wrong number of arguments.")

  if not qa_config.options.yes_do_it:
    print ("Executing this script irreversibly destroys any Ganeti\n"
           "configuration on all nodes involved. If you really want\n"
           "to start testing, supply the --yes-do-it option.")
    sys.exit(1)

  qa_config.Load(config_file)

  qa_utils.StartMultiplexer(qa_config.GetMasterNode()["primary"])
  try:
    RunQa()
  finally:
    qa_utils.CloseMultiplexers()

Iustin Pop's avatar
Iustin Pop committed
562
if __name__ == "__main__":
563
  main()