Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ b3f3aa3d

History | View | Annotate | Download (21.1 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.TestClusterModifyIPolicy),
175
    ("cluster-modify", qa_cluster.TestClusterModifyISpecs),
176
    ("cluster-modify", qa_cluster.TestClusterModifyBe),
177
    ("cluster-modify", qa_cluster.TestClusterModifyDisk),
178
    ("cluster-rename", qa_cluster.TestClusterRename),
179
    ("cluster-info", qa_cluster.TestClusterVersion),
180
    ("cluster-info", qa_cluster.TestClusterInfo),
181
    ("cluster-info", qa_cluster.TestClusterGetmaster),
182
    ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
183
    ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
184
    ("cluster-command", qa_cluster.TestClusterCommand),
185
    ("cluster-burnin", qa_cluster.TestClusterBurnin),
186
    ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
187
    ("cluster-master-failover",
188
     qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
189
    ("cluster-oob", qa_cluster.TestClusterOob),
190
    ("rapi", qa_rapi.TestVersion),
191
    ("rapi", qa_rapi.TestEmptyCluster),
192
    ("rapi", qa_rapi.TestRapiQuery),
193
    ]:
194
    RunTestIf(test, fn)
195

    
196

    
197
def RunRepairDiskSizes():
198
  """Run the repair disk-sizes test.
199

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

    
203

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

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

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

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

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

    
233

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

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

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

    
251
  RunTestIf("instance-list", qa_instance.TestInstanceList)
252

    
253
  RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
254

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

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

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

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

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

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

    
296
  RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
297

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

    
301
  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
302

    
303
  RunTestIf("tags", qa_tags.TestInstanceTags, instance)
304

    
305
  RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
306

    
307
  RunTestIf("rapi", qa_rapi.TestInstance, instance)
308

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

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

    
315

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

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

    
324

    
325
def RunGroupListTests():
326
  """Run tests for listing node groups.
327

328
  """
329
  RunTestIf("group-list", qa_group.TestGroupList)
330
  RunTestIf("group-list", qa_group.TestGroupListFields)
331

    
332

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

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

    
344

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

348
  @type inodes: list of nodes
349
  @param inodes: current nodes of the instance
350

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

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

    
360
      RunTest(qa_instance.TestBackupList, expnode)
361

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

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

    
387

    
388
def RunDaemonTests(instance):
389
  """Test the ganeti-watcher script.
390

391
  """
392
  RunTest(qa_daemon.TestPauseWatcher)
393

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

    
399
  RunTest(qa_daemon.TestResumeWatcher)
400

    
401

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

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

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

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

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

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

    
448

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

    
454
  node = qa_config.AcquireNode()
455
  try:
456
    old_es = qa_cluster.TestSetExclStorCluster(False)
457
    qa_node.TestExclStorSingleNode(node)
458

    
459
    qa_cluster.TestSetExclStorCluster(True)
460
    qa_cluster.TestExclStorSharedPv(node)
461

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

    
486

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

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

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

    
526

    
527
def RunQa():
528
  """Main QA body.
529

530
  """
531
  rapi_user = "ganeti-qa"
532
  rapi_secret = utils.GenerateSecret()
533

    
534
  RunEnvTests()
535
  SetupCluster(rapi_user, rapi_secret)
536

    
537
  # Load RAPI certificate
538
  qa_rapi.Setup(rapi_user, rapi_secret)
539

    
540
  RunClusterTests()
541
  RunOsTests()
542

    
543
  RunTestIf("tags", qa_tags.TestClusterTags)
544

    
545
  RunCommonNodeTests()
546
  RunGroupListTests()
547
  RunGroupRwTests()
548

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

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

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

    
566
    if qa_rapi.Enabled():
567
      RunTest(qa_rapi.TestNode, pnode)
568

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

    
578
  finally:
579
    qa_config.ReleaseNode(pnode)
580

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

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

    
611
  finally:
612
    qa_config.ReleaseNode(pnode)
613

    
614
  RunExclusiveStorageTests()
615

    
616
  # Test removing instance with offline drbd secondary
617
  if qa_config.TestEnabled("instance-remove-drbd-offline"):
618
    # Make sure the master is not put offline
619
    snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
620
    try:
621
      pnode = qa_config.AcquireNode(exclude=snode)
622
      try:
623
        instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
624
        set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
625
        set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
626
        RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
627
                set_offline, set_online)
628
      finally:
629
        qa_config.ReleaseNode(pnode)
630
    finally:
631
      qa_config.ReleaseNode(snode)
632
    qa_cluster.AssertClusterVerify()
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()