Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ deadfa13

History | View | Annotate | Download (21 kB)

1
#!/usr/bin/python -u
2
#
3

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

    
21

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

24
"""
25

    
26
# pylint: disable=C0103
27
# due to invalid name
28

    
29
import sys
30
import datetime
31
import optparse
32

    
33
import qa_cluster
34
import qa_config
35
import qa_daemon
36
import qa_env
37
import qa_error
38
import qa_group
39
import qa_instance
40
import qa_node
41
import qa_os
42
import qa_job
43
import qa_rapi
44
import qa_tags
45
import qa_utils
46

    
47
from ganeti import utils
48
from ganeti import rapi # pylint: disable=W0611
49
from ganeti import constants
50

    
51
import ganeti.rapi.client # pylint: disable=W0611
52
from ganeti.rapi.client import UsesRapiClient
53

    
54

    
55
def _FormatHeader(line, end=72):
56
  """Fill a line up to the end column.
57

58
  """
59
  line = "---- " + line + " "
60
  line += "-" * (end - len(line))
61
  line = line.rstrip()
62
  return line
63

    
64

    
65
def _DescriptionOf(fn):
66
  """Computes the description of an item.
67

68
  """
69
  if fn.__doc__:
70
    desc = fn.__doc__.splitlines()[0].strip()
71
  else:
72
    desc = "%r" % fn
73

    
74
  return desc.rstrip(".")
75

    
76

    
77
def RunTest(fn, *args, **kwargs):
78
  """Runs a test after printing a header.
79

80
  """
81

    
82
  tstart = datetime.datetime.now()
83

    
84
  desc = _DescriptionOf(fn)
85

    
86
  print
87
  print _FormatHeader("%s start %s" % (tstart, desc))
88

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

    
97

    
98
def RunTestIf(testnames, fn, *args, **kwargs):
99
  """Runs a test conditionally.
100

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

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

    
113

    
114
def RunEnvTests():
115
  """Run several environment tests.
116

117
  """
118
  RunTestIf("env", qa_env.TestSshConnection)
119
  RunTestIf("env", qa_env.TestIcmpPing)
120
  RunTestIf("env", qa_env.TestGanetiCommands)
121

    
122

    
123
def SetupCluster(rapi_user, rapi_secret):
124
  """Initializes the cluster.
125

126
  @param rapi_user: Login user for RAPI
127
  @param rapi_secret: Login secret for RAPI
128

129
  """
130
  RunTestIf("create-cluster", qa_cluster.TestClusterInit,
131
            rapi_user, rapi_secret)
132
  if not qa_config.TestEnabled("create-cluster"):
133
    # If the cluster is already in place, we assume that exclusive-storage is
134
    # already set according to the configuration
135
    qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False))
136

    
137
  # Test on empty cluster
138
  RunTestIf("node-list", qa_node.TestNodeList)
139
  RunTestIf("instance-list", qa_instance.TestInstanceList)
140
  RunTestIf("job-list", qa_job.TestJobList)
141

    
142
  RunTestIf("create-cluster", qa_node.TestNodeAddAll)
143
  if not qa_config.TestEnabled("create-cluster"):
144
    # consider the nodes are already there
145
    qa_node.MarkNodeAddedAll()
146

    
147
  RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
148

    
149
  # enable the watcher (unconditionally)
150
  RunTest(qa_daemon.TestResumeWatcher)
151

    
152
  RunTestIf("node-list", qa_node.TestNodeList)
153

    
154
  # Test listing fields
155
  RunTestIf("node-list", qa_node.TestNodeListFields)
156
  RunTestIf("instance-list", qa_instance.TestInstanceListFields)
157
  RunTestIf("job-list", qa_job.TestJobListFields)
158
  RunTestIf("instance-export", qa_instance.TestBackupListFields)
159

    
160
  RunTestIf("node-info", qa_node.TestNodeInfo)
161

    
162

    
163
def RunClusterTests():
164
  """Runs tests related to gnt-cluster.
165

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

    
194

    
195
def RunRepairDiskSizes():
196
  """Run the repair disk-sizes test.
197

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

    
201

    
202
def RunOsTests():
203
  """Runs all tests related to gnt-os.
204

205
  """
206
  if qa_config.TestEnabled("rapi"):
207
    rapi_getos = qa_rapi.GetOperatingSystems
208
  else:
209
    rapi_getos = None
210

    
211
  for fn in [
212
    qa_os.TestOsList,
213
    qa_os.TestOsDiagnose,
214
    ]:
215
    RunTestIf("os", fn)
216

    
217
  for fn in [
218
    qa_os.TestOsValid,
219
    qa_os.TestOsInvalid,
220
    qa_os.TestOsPartiallyValid,
221
    ]:
222
    RunTestIf("os", fn, rapi_getos)
223

    
224
  for fn in [
225
    qa_os.TestOsModifyValid,
226
    qa_os.TestOsModifyInvalid,
227
    qa_os.TestOsStatesNonExisting,
228
    ]:
229
    RunTestIf("os", fn)
230

    
231

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

235
  """
236
  RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
237
  RunTestIf(["instance-shutdown", "instance-console", "rapi"],
238
            qa_rapi.TestRapiStoppedInstanceConsole, instance)
239
  RunTestIf(["instance-shutdown", "instance-modify"],
240
            qa_instance.TestInstanceStoppedModify, instance)
241
  RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
242

    
243
  # Test shutdown/start via RAPI
244
  RunTestIf(["instance-shutdown", "rapi"],
245
            qa_rapi.TestRapiInstanceShutdown, instance)
246
  RunTestIf(["instance-shutdown", "rapi"],
247
            qa_rapi.TestRapiInstanceStartup, instance)
248

    
249
  RunTestIf("instance-list", qa_instance.TestInstanceList)
250

    
251
  RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
252

    
253
  RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
254
  RunTestIf(["instance-modify", "rapi"],
255
            qa_rapi.TestRapiInstanceModify, instance)
256

    
257
  RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
258
  RunTestIf(["instance-console", "rapi"],
259
            qa_rapi.TestRapiInstanceConsole, instance)
260

    
261
  DOWN_TESTS = qa_config.Either([
262
    "instance-reinstall",
263
    "instance-rename",
264
    "instance-grow-disk",
265
    ])
266

    
267
  # shutdown instance for any 'down' tests
268
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
269

    
270
  # now run the 'down' state tests
271
  RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
272
  RunTestIf(["instance-reinstall", "rapi"],
273
            qa_rapi.TestRapiInstanceReinstall, instance)
274

    
275
  if qa_config.TestEnabled("instance-rename"):
276
    tgt_instance = qa_config.AcquireInstance()
277
    try:
278
      rename_source = instance["name"]
279
      rename_target = tgt_instance["name"]
280
      # perform instance rename to the same name
281
      RunTest(qa_instance.TestInstanceRenameAndBack,
282
              rename_source, rename_source)
283
      RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
284
                rename_source, rename_source)
285
      if rename_target is not None:
286
        # perform instance rename to a different name, if we have one configured
287
        RunTest(qa_instance.TestInstanceRenameAndBack,
288
                rename_source, rename_target)
289
        RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
290
                  rename_source, rename_target)
291
    finally:
292
      qa_config.ReleaseInstance(tgt_instance)
293

    
294
  RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
295

    
296
  # and now start the instance again
297
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
298

    
299
  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
300

    
301
  RunTestIf("tags", qa_tags.TestInstanceTags, instance)
302

    
303
  RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
304

    
305
  RunTestIf("rapi", qa_rapi.TestInstance, instance)
306

    
307
  # Lists instances, too
308
  RunTestIf("node-list", qa_node.TestNodeList)
309

    
310
  # Some jobs have been run, let's test listing them
311
  RunTestIf("job-list", qa_job.TestJobList)
312

    
313

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

317
  """
318
  RunTestIf("node-volumes", qa_node.TestNodeVolumes)
319
  RunTestIf("node-storage", qa_node.TestNodeStorage)
320
  RunTestIf("node-oob", qa_node.TestOutOfBand)
321

    
322

    
323
def RunGroupListTests():
324
  """Run tests for listing node groups.
325

326
  """
327
  RunTestIf("group-list", qa_group.TestGroupList)
328
  RunTestIf("group-list", qa_group.TestGroupListFields)
329

    
330

    
331
def RunGroupRwTests():
332
  """Run tests for adding/removing/renaming groups.
333

334
  """
335
  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
336
  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
337
  RunTestIf("group-rwops", qa_group.TestGroupModify)
338
  RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups)
339
  RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
340
            qa_group.GetDefaultGroup())
341

    
342

    
343
def RunExportImportTests(instance, inodes):
344
  """Tries to export and import the instance.
345

346
  @type inodes: list of nodes
347
  @param inodes: current nodes of the instance
348

349
  """
350
  if qa_config.TestEnabled("instance-export"):
351
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)
352

    
353
    pnode = inodes[0]
354
    expnode = qa_config.AcquireNode(exclude=pnode)
355
    try:
356
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
357

    
358
      RunTest(qa_instance.TestBackupList, expnode)
359

    
360
      if qa_config.TestEnabled("instance-import"):
361
        newinst = qa_config.AcquireInstance()
362
        try:
363
          RunTest(qa_instance.TestInstanceImport, newinst, pnode,
364
                  expnode, name)
365
          # Check if starting the instance works
366
          RunTest(qa_instance.TestInstanceStartup, newinst)
367
          RunTest(qa_instance.TestInstanceRemove, newinst)
368
        finally:
369
          qa_config.ReleaseInstance(newinst)
370
    finally:
371
      qa_config.ReleaseNode(expnode)
372

    
373
  if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
374
    newinst = qa_config.AcquireInstance()
375
    try:
376
      tnode = qa_config.AcquireNode(exclude=inodes)
377
      try:
378
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
379
                inodes, tnode)
380
      finally:
381
        qa_config.ReleaseNode(tnode)
382
    finally:
383
      qa_config.ReleaseInstance(newinst)
384

    
385

    
386
def RunDaemonTests(instance):
387
  """Test the ganeti-watcher script.
388

389
  """
390
  RunTest(qa_daemon.TestPauseWatcher)
391

    
392
  RunTestIf("instance-automatic-restart",
393
            qa_daemon.TestInstanceAutomaticRestart, instance)
394
  RunTestIf("instance-consecutive-failures",
395
            qa_daemon.TestInstanceConsecutiveFailures, instance)
396

    
397
  RunTest(qa_daemon.TestResumeWatcher)
398

    
399

    
400
def RunHardwareFailureTests(instance, inodes):
401
  """Test cluster internal hardware failure recovery.
402

403
  """
404
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
405
  RunTestIf(["instance-failover", "rapi"],
406
            qa_rapi.TestRapiInstanceFailover, instance)
407

    
408
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
409
  RunTestIf(["instance-migrate", "rapi"],
410
            qa_rapi.TestRapiInstanceMigrate, instance)
411

    
412
  if qa_config.TestEnabled("instance-replace-disks"):
413
    # We just need alternative secondary nodes, hence "- 1"
414
    othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
415
    try:
416
      RunTestIf("rapi", qa_rapi.TestRapiInstanceReplaceDisks, instance)
417
      RunTest(qa_instance.TestReplaceDisks,
418
              instance, inodes, othernodes)
419
    finally:
420
      qa_config.ReleaseManyNodes(othernodes)
421
    del othernodes
422

    
423
  if qa_config.TestEnabled("instance-recreate-disks"):
424
    try:
425
      acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
426
      othernodes = acquirednodes
427
    except qa_error.OutOfNodesError:
428
      if len(inodes) > 1:
429
        # If the cluster is not big enough, let's reuse some of the nodes, but
430
        # with different roles. In this way, we can test a DRBD instance even on
431
        # a 3-node cluster.
432
        acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
433
        othernodes = acquirednodes + inodes[:-1]
434
      else:
435
        raise
436
    try:
437
      RunTest(qa_instance.TestRecreateDisks,
438
              instance, inodes, othernodes)
439
    finally:
440
      qa_config.ReleaseManyNodes(acquirednodes)
441

    
442
  if len(inodes) >= 2:
443
    RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
444
    RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
445

    
446

    
447
def RunExclusiveStorageTests():
448
  """Test exclusive storage."""
449
  if not qa_config.TestEnabled("cluster-exclusive-storage"):
450
    return
451

    
452
  node = qa_config.AcquireNode()
453
  try:
454
    old_es = qa_cluster.TestSetExclStorCluster(False)
455
    qa_cluster.TestExclStorSingleNode(node)
456

    
457
    qa_cluster.TestSetExclStorCluster(True)
458
    qa_cluster.TestExclStorSharedPv(node)
459

    
460
    if qa_config.TestEnabled("instance-add-plain-disk"):
461
      # Make sure that the cluster doesn't have any pre-existing problem
462
      qa_cluster.AssertClusterVerify()
463
      instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
464
      instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
465
      # cluster-verify checks that disks are allocated correctly
466
      qa_cluster.AssertClusterVerify()
467
      qa_instance.TestInstanceRemove(instance1)
468
      qa_instance.TestInstanceRemove(instance2)
469
    if qa_config.TestEnabled("instance-add-drbd-disk"):
470
      snode = qa_config.AcquireNode()
471
      try:
472
        qa_cluster.TestSetExclStorCluster(False)
473
        instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
474
        qa_cluster.TestSetExclStorCluster(True)
475
        exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
476
        qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
477
        qa_instance.TestInstanceRemove(instance)
478
      finally:
479
        qa_config.ReleaseNode(snode)
480
    qa_cluster.TestSetExclStorCluster(old_es)
481
  finally:
482
    qa_config.ReleaseNode(node)
483

    
484

    
485
def RunInstanceTests():
486
  """Create and exercise instances."""
487
  instance_tests = [
488
    ("instance-add-plain-disk", constants.DT_PLAIN,
489
     qa_instance.TestInstanceAddWithPlainDisk, 1),
490
    ("instance-add-drbd-disk", constants.DT_DRBD8,
491
     qa_instance.TestInstanceAddWithDrbdDisk, 2),
492
  ]
493

    
494
  for (test_name, templ, create_fun, num_nodes) in instance_tests:
495
    if (qa_config.TestEnabled(test_name) and
496
        qa_config.IsTemplateSupported(templ)):
497
      inodes = qa_config.AcquireManyNodes(num_nodes)
498
      try:
499
        instance = RunTest(create_fun, inodes)
500

    
501
        RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
502
        RunDaemonTests(instance)
503
        for node in inodes:
504
          RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
505
        if len(inodes) > 1:
506
          RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
507
                    constants.INITIAL_NODE_GROUP_NAME,
508
                    inodes[0]["primary"], inodes[1]["primary"])
509
        if qa_config.TestEnabled("instance-convert-disk"):
510
          RunTest(qa_instance.TestInstanceShutdown, instance)
511
          RunTest(qa_instance.TestInstanceConvertDiskToPlain, instance, inodes)
512
          RunTest(qa_instance.TestInstanceStartup, instance)
513
        RunCommonInstanceTests(instance)
514
        RunGroupListTests()
515
        RunExportImportTests(instance, inodes)
516
        RunHardwareFailureTests(instance, inodes)
517
        RunRepairDiskSizes()
518
        RunTest(qa_instance.TestInstanceRemove, instance)
519
        del instance
520
      finally:
521
        qa_config.ReleaseManyNodes(inodes)
522
      qa_cluster.AssertClusterVerify()
523

    
524

    
525
def RunQa():
526
  """Main QA body.
527

528
  """
529
  rapi_user = "ganeti-qa"
530
  rapi_secret = utils.GenerateSecret()
531

    
532
  RunEnvTests()
533
  SetupCluster(rapi_user, rapi_secret)
534

    
535
  # Load RAPI certificate
536
  qa_rapi.Setup(rapi_user, rapi_secret)
537

    
538
  RunClusterTests()
539
  RunOsTests()
540

    
541
  RunTestIf("tags", qa_tags.TestClusterTags)
542

    
543
  RunCommonNodeTests()
544
  RunGroupListTests()
545
  RunGroupRwTests()
546

    
547
  # The master shouldn't be readded or put offline; "delay" needs a non-master
548
  # node to test
549
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
550
  try:
551
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
552
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
553
    RunTestIf("delay", qa_cluster.TestDelay, pnode)
554
  finally:
555
    qa_config.ReleaseNode(pnode)
556

    
557
  # Make sure the cluster is clean before running instance tests
558
  qa_cluster.AssertClusterVerify()
559

    
560
  pnode = qa_config.AcquireNode()
561
  try:
562
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
563

    
564
    if qa_rapi.Enabled():
565
      RunTest(qa_rapi.TestNode, pnode)
566

    
567
      if qa_config.TestEnabled("instance-add-plain-disk"):
568
        for use_client in [True, False]:
569
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
570
                                  use_client)
571
          if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
572
            RunCommonInstanceTests(rapi_instance)
573
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
574
          del rapi_instance
575

    
576
  finally:
577
    qa_config.ReleaseNode(pnode)
578

    
579
  config_list = [
580
    ("default-instance-tests", lambda: None, lambda _: None),
581
    ("exclusive-storage-instance-tests",
582
     lambda: qa_cluster.TestSetExclStorCluster(True),
583
     qa_cluster.TestSetExclStorCluster),
584
  ]
585
  for (conf_name, setup_conf_f, restore_conf_f) in config_list:
586
    if qa_config.TestEnabled(conf_name):
587
      oldconf = setup_conf_f()
588
      RunInstanceTests()
589
      restore_conf_f(oldconf)
590

    
591
  pnode = qa_config.AcquireNode()
592
  try:
593
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
594
      for shutdown in [False, True]:
595
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
596
        expnode = qa_config.AcquireNode(exclude=pnode)
597
        try:
598
          if shutdown:
599
            # Stop instance before exporting and removing it
600
            RunTest(qa_instance.TestInstanceShutdown, instance)
601
          RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
602
          RunTest(qa_instance.TestBackupList, expnode)
603
        finally:
604
          qa_config.ReleaseNode(expnode)
605
        del expnode
606
        del instance
607
      qa_cluster.AssertClusterVerify()
608

    
609
  finally:
610
    qa_config.ReleaseNode(pnode)
611

    
612
  RunExclusiveStorageTests()
613

    
614
  # Test removing instance with offline drbd secondary
615
  if qa_config.TestEnabled("instance-remove-drbd-offline"):
616
    # Make sure the master is not put offline
617
    snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
618
    try:
619
      pnode = qa_config.AcquireNode(exclude=snode)
620
      try:
621
        instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
622
        qa_node.MakeNodeOffline(snode, "yes")
623
        try:
624
          RunTest(qa_instance.TestInstanceRemove, instance)
625
        finally:
626
          qa_node.MakeNodeOffline(snode, "no")
627
      finally:
628
        qa_config.ReleaseNode(pnode)
629
    finally:
630
      qa_config.ReleaseNode(snode)
631
    # FIXME: This test leaves a DRBD device and two LVs behind
632
    # Cluster-verify would fail
633

    
634
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
635

    
636
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
637

    
638

    
639
@UsesRapiClient
640
def main():
641
  """Main program.
642

643
  """
644
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
645
  parser.add_option("--yes-do-it", dest="yes_do_it",
646
                    action="store_true",
647
                    help="Really execute the tests")
648
  (qa_config.options, args) = parser.parse_args()
649

    
650
  if len(args) == 1:
651
    (config_file, ) = args
652
  else:
653
    parser.error("Wrong number of arguments.")
654

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

    
661
  qa_config.Load(config_file)
662

    
663
  primary = qa_config.GetMasterNode()["primary"]
664
  qa_utils.StartMultiplexer(primary)
665
  print ("SSH command for primary node: %s" %
666
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
667
  print ("SSH command for other nodes: %s" %
668
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
669
  try:
670
    RunQa()
671
  finally:
672
    qa_utils.CloseMultiplexers()
673

    
674
if __name__ == "__main__":
675
  main()