Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 301adaae

History | View | Annotate | Download (21.9 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_network
41
import qa_node
42
import qa_os
43
import qa_job
44
import qa_rapi
45
import qa_tags
46
import qa_utils
47

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

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

    
55

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

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

    
65

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

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

    
75
  return desc.rstrip(".")
76

    
77

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

81
  """
82

    
83
  tstart = datetime.datetime.now()
84

    
85
  desc = _DescriptionOf(fn)
86

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

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

    
98

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

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

105
  """
106
  if qa_config.TestEnabled(testnames):
107
    RunTest(fn, *args, **kwargs)
108
  else:
109
    tstart = datetime.datetime.now()
110
    desc = _DescriptionOf(fn)
111
    # TODO: Formatting test names when non-string names are involved
112
    print _FormatHeader("%s skipping %s, test(s) %s disabled" %
113
                        (tstart, desc, testnames))
114

    
115

    
116
def RunEnvTests():
117
  """Run several environment tests.
118

119
  """
120
  RunTestIf("env", qa_env.TestSshConnection)
121
  RunTestIf("env", qa_env.TestIcmpPing)
122
  RunTestIf("env", qa_env.TestGanetiCommands)
123

    
124

    
125
def SetupCluster(rapi_user, rapi_secret):
126
  """Initializes the cluster.
127

128
  @param rapi_user: Login user for RAPI
129
  @param rapi_secret: Login secret for RAPI
130

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

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

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

    
149
  RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
150

    
151
  # enable the watcher (unconditionally)
152
  RunTest(qa_daemon.TestResumeWatcher)
153

    
154
  RunTestIf("node-list", qa_node.TestNodeList)
155

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

    
162
  RunTestIf("node-info", qa_node.TestNodeInfo)
163

    
164

    
165
def RunClusterTests():
166
  """Runs tests related to gnt-cluster.
167

168
  """
169
  for test, fn in [
170
    ("create-cluster", qa_cluster.TestClusterInitDisk),
171
    ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
172
    ("cluster-verify", qa_cluster.TestClusterVerify),
173
    ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
174
    # TODO: add more cluster modify tests
175
    ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
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_config.NoVirtualCluster],
184
     qa_cluster.TestClusterCopyfile),
185
    ("cluster-command", qa_cluster.TestClusterCommand),
186
    ("cluster-burnin", qa_cluster.TestClusterBurnin),
187
    ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
188
    ("cluster-master-failover",
189
     qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
190
    (["cluster-oob", qa_config.NoVirtualCluster],
191
     qa_cluster.TestClusterOob),
192
    (qa_rapi.Enabled, qa_rapi.TestVersion),
193
    (qa_rapi.Enabled, qa_rapi.TestEmptyCluster),
194
    (qa_rapi.Enabled, qa_rapi.TestRapiQuery),
195
    ]:
196
    RunTestIf(test, fn)
197

    
198

    
199
def RunRepairDiskSizes():
200
  """Run the repair disk-sizes test.
201

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

    
205

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

209
  """
210
  os_enabled = ["os", qa_config.NoVirtualCluster]
211

    
212
  if qa_config.TestEnabled(qa_rapi.Enabled):
213
    rapi_getos = qa_rapi.GetOperatingSystems
214
  else:
215
    rapi_getos = None
216

    
217
  for fn in [
218
    qa_os.TestOsList,
219
    qa_os.TestOsDiagnose,
220
    ]:
221
    RunTestIf(os_enabled, fn)
222

    
223
  for fn in [
224
    qa_os.TestOsValid,
225
    qa_os.TestOsInvalid,
226
    qa_os.TestOsPartiallyValid,
227
    ]:
228
    RunTestIf(os_enabled, fn, rapi_getos)
229

    
230
  for fn in [
231
    qa_os.TestOsModifyValid,
232
    qa_os.TestOsModifyInvalid,
233
    qa_os.TestOsStatesNonExisting,
234
    ]:
235
    RunTestIf(os_enabled, fn)
236

    
237

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

241
  """
242
  RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
243
  RunTestIf(["instance-shutdown", "instance-console", qa_rapi.Enabled],
244
            qa_rapi.TestRapiStoppedInstanceConsole, instance)
245
  RunTestIf(["instance-shutdown", "instance-modify"],
246
            qa_instance.TestInstanceStoppedModify, instance)
247
  RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
248

    
249
  # Test shutdown/start via RAPI
250
  RunTestIf(["instance-shutdown", qa_rapi.Enabled],
251
            qa_rapi.TestRapiInstanceShutdown, instance)
252
  RunTestIf(["instance-shutdown", qa_rapi.Enabled],
253
            qa_rapi.TestRapiInstanceStartup, instance)
254

    
255
  RunTestIf("instance-list", qa_instance.TestInstanceList)
256

    
257
  RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
258

    
259
  RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
260
  RunTestIf(["instance-modify", qa_rapi.Enabled],
261
            qa_rapi.TestRapiInstanceModify, instance)
262

    
263
  RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
264
  RunTestIf(["instance-console", qa_rapi.Enabled],
265
            qa_rapi.TestRapiInstanceConsole, instance)
266

    
267
  DOWN_TESTS = qa_config.Either([
268
    "instance-reinstall",
269
    "instance-rename",
270
    "instance-grow-disk",
271
    ])
272

    
273
  # shutdown instance for any 'down' tests
274
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
275

    
276
  # now run the 'down' state tests
277
  RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
278
  RunTestIf(["instance-reinstall", qa_rapi.Enabled],
279
            qa_rapi.TestRapiInstanceReinstall, instance)
280

    
281
  if qa_config.TestEnabled("instance-rename"):
282
    tgt_instance = qa_config.AcquireInstance()
283
    try:
284
      rename_source = instance.name
285
      rename_target = tgt_instance.name
286
      # perform instance rename to the same name
287
      RunTest(qa_instance.TestInstanceRenameAndBack,
288
              rename_source, rename_source)
289
      RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
290
                rename_source, rename_source)
291
      if rename_target is not None:
292
        # perform instance rename to a different name, if we have one configured
293
        RunTest(qa_instance.TestInstanceRenameAndBack,
294
                rename_source, rename_target)
295
        RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
296
                  rename_source, rename_target)
297
    finally:
298
      tgt_instance.Release()
299

    
300
  RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
301

    
302
  # and now start the instance again
303
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
304

    
305
  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
306

    
307
  RunTestIf("tags", qa_tags.TestInstanceTags, instance)
308

    
309
  RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
310

    
311
  RunTestIf(qa_rapi.Enabled, qa_rapi.TestInstance, instance)
312

    
313
  # Lists instances, too
314
  RunTestIf("node-list", qa_node.TestNodeList)
315

    
316
  # Some jobs have been run, let's test listing them
317
  RunTestIf("job-list", qa_job.TestJobList)
318

    
319

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

323
  """
324
  RunTestIf("node-volumes", qa_node.TestNodeVolumes)
325
  RunTestIf("node-storage", qa_node.TestNodeStorage)
326
  RunTestIf(["node-oob", qa_config.NoVirtualCluster], qa_node.TestOutOfBand)
327

    
328

    
329
def RunGroupListTests():
330
  """Run tests for listing node groups.
331

332
  """
333
  RunTestIf("group-list", qa_group.TestGroupList)
334
  RunTestIf("group-list", qa_group.TestGroupListFields)
335

    
336

    
337
def RunNetworkTests():
338
  """Run tests for network management.
339

340
  """
341
  RunTestIf("network", qa_network.TestNetworkAddRemove)
342
  RunTestIf("network", qa_network.TestNetworkConnect)
343

    
344

    
345
def RunGroupRwTests():
346
  """Run tests for adding/removing/renaming groups.
347

348
  """
349
  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
350
  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
351
  RunTestIf("group-rwops", qa_group.TestGroupModify)
352
  RunTestIf(["group-rwops", qa_rapi.Enabled], qa_rapi.TestRapiNodeGroups)
353
  RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
354
            qa_group.GetDefaultGroup())
355

    
356

    
357
def RunExportImportTests(instance, inodes):
358
  """Tries to export and import the instance.
359

360
  @type inodes: list of nodes
361
  @param inodes: current nodes of the instance
362

363
  """
364
  if qa_config.TestEnabled("instance-export"):
365
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)
366

    
367
    pnode = inodes[0]
368
    expnode = qa_config.AcquireNode(exclude=pnode)
369
    try:
370
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
371

    
372
      RunTest(qa_instance.TestBackupList, expnode)
373

    
374
      if qa_config.TestEnabled("instance-import"):
375
        newinst = qa_config.AcquireInstance()
376
        try:
377
          RunTest(qa_instance.TestInstanceImport, newinst, pnode,
378
                  expnode, name)
379
          # Check if starting the instance works
380
          RunTest(qa_instance.TestInstanceStartup, newinst)
381
          RunTest(qa_instance.TestInstanceRemove, newinst)
382
        finally:
383
          newinst.Release()
384
    finally:
385
      expnode.Release()
386

    
387
  if qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"]):
388
    newinst = qa_config.AcquireInstance()
389
    try:
390
      tnode = qa_config.AcquireNode(exclude=inodes)
391
      try:
392
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
393
                inodes, tnode)
394
      finally:
395
        tnode.Release()
396
    finally:
397
      newinst.Release()
398

    
399

    
400
def RunDaemonTests(instance):
401
  """Test the ganeti-watcher script.
402

403
  """
404
  RunTest(qa_daemon.TestPauseWatcher)
405

    
406
  RunTestIf("instance-automatic-restart",
407
            qa_daemon.TestInstanceAutomaticRestart, instance)
408
  RunTestIf("instance-consecutive-failures",
409
            qa_daemon.TestInstanceConsecutiveFailures, instance)
410

    
411
  RunTest(qa_daemon.TestResumeWatcher)
412

    
413

    
414
def RunHardwareFailureTests(instance, inodes):
415
  """Test cluster internal hardware failure recovery.
416

417
  """
418
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
419
  RunTestIf(["instance-failover", qa_rapi.Enabled],
420
            qa_rapi.TestRapiInstanceFailover, instance)
421

    
422
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
423
  RunTestIf(["instance-migrate", qa_rapi.Enabled],
424
            qa_rapi.TestRapiInstanceMigrate, instance)
425

    
426
  if qa_config.TestEnabled("instance-replace-disks"):
427
    # We just need alternative secondary nodes, hence "- 1"
428
    othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
429
    try:
430
      RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceReplaceDisks, instance)
431
      RunTest(qa_instance.TestReplaceDisks,
432
              instance, inodes, othernodes)
433
    finally:
434
      qa_config.ReleaseManyNodes(othernodes)
435
    del othernodes
436

    
437
  if qa_config.TestEnabled("instance-recreate-disks"):
438
    try:
439
      acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
440
      othernodes = acquirednodes
441
    except qa_error.OutOfNodesError:
442
      if len(inodes) > 1:
443
        # If the cluster is not big enough, let's reuse some of the nodes, but
444
        # with different roles. In this way, we can test a DRBD instance even on
445
        # a 3-node cluster.
446
        acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
447
        othernodes = acquirednodes + inodes[:-1]
448
      else:
449
        raise
450
    try:
451
      RunTest(qa_instance.TestRecreateDisks,
452
              instance, inodes, othernodes)
453
    finally:
454
      qa_config.ReleaseManyNodes(acquirednodes)
455

    
456
  if len(inodes) >= 2:
457
    RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
458
    RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
459

    
460

    
461
def RunExclusiveStorageTests():
462
  """Test exclusive storage."""
463
  if not qa_config.TestEnabled("cluster-exclusive-storage"):
464
    return
465

    
466
  node = qa_config.AcquireNode()
467
  try:
468
    old_es = qa_cluster.TestSetExclStorCluster(False)
469
    qa_node.TestExclStorSingleNode(node)
470

    
471
    qa_cluster.TestSetExclStorCluster(True)
472
    qa_cluster.TestExclStorSharedPv(node)
473

    
474
    if qa_config.TestEnabled("instance-add-plain-disk"):
475
      # Make sure that the cluster doesn't have any pre-existing problem
476
      qa_cluster.AssertClusterVerify()
477

    
478
      # Create and allocate instances
479
      instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
480
      try:
481
        instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
482
        try:
483
          # cluster-verify checks that disks are allocated correctly
484
          qa_cluster.AssertClusterVerify()
485

    
486
          # Remove instances
487
          qa_instance.TestInstanceRemove(instance2)
488
          qa_instance.TestInstanceRemove(instance1)
489
        finally:
490
          instance2.Release()
491
      finally:
492
        instance1.Release()
493

    
494
    if qa_config.TestEnabled("instance-add-drbd-disk"):
495
      snode = qa_config.AcquireNode()
496
      try:
497
        qa_cluster.TestSetExclStorCluster(False)
498
        instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
499
        try:
500
          qa_cluster.TestSetExclStorCluster(True)
501
          exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
502
          qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
503
          qa_instance.TestInstanceRemove(instance)
504
        finally:
505
          instance.Release()
506
      finally:
507
        snode.Release()
508
    qa_cluster.TestSetExclStorCluster(old_es)
509
  finally:
510
    node.Release()
511

    
512

    
513
def RunInstanceTests():
514
  """Create and exercise instances."""
515
  instance_tests = [
516
    ("instance-add-plain-disk", constants.DT_PLAIN,
517
     qa_instance.TestInstanceAddWithPlainDisk, 1),
518
    ("instance-add-drbd-disk", constants.DT_DRBD8,
519
     qa_instance.TestInstanceAddWithDrbdDisk, 2),
520
  ]
521

    
522
  for (test_name, templ, create_fun, num_nodes) in instance_tests:
523
    if (qa_config.TestEnabled(test_name) and
524
        qa_config.IsTemplateSupported(templ)):
525
      inodes = qa_config.AcquireManyNodes(num_nodes)
526
      try:
527
        instance = RunTest(create_fun, inodes)
528
        try:
529
          RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
530
          RunDaemonTests(instance)
531
          for node in inodes:
532
            RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
533
          if len(inodes) > 1:
534
            RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
535
                      constants.INITIAL_NODE_GROUP_NAME,
536
                      inodes[0].primary, inodes[1].primary)
537
          if qa_config.TestEnabled("instance-convert-disk"):
538
            RunTest(qa_instance.TestInstanceShutdown, instance)
539
            RunTest(qa_instance.TestInstanceConvertDiskToPlain,
540
                    instance, inodes)
541
            RunTest(qa_instance.TestInstanceStartup, instance)
542
          RunCommonInstanceTests(instance)
543
          RunGroupListTests()
544
          RunExportImportTests(instance, inodes)
545
          RunHardwareFailureTests(instance, inodes)
546
          RunRepairDiskSizes()
547
          RunTest(qa_instance.TestInstanceRemove, instance)
548
        finally:
549
          instance.Release()
550
        del instance
551
      finally:
552
        qa_config.ReleaseManyNodes(inodes)
553
      qa_cluster.AssertClusterVerify()
554

    
555

    
556
def RunQa():
557
  """Main QA body.
558

559
  """
560
  rapi_user = "ganeti-qa"
561
  rapi_secret = utils.GenerateSecret()
562

    
563
  RunEnvTests()
564
  SetupCluster(rapi_user, rapi_secret)
565

    
566
  # Load RAPI certificate
567
  qa_rapi.Setup(rapi_user, rapi_secret)
568

    
569
  RunClusterTests()
570
  RunOsTests()
571

    
572
  RunTestIf("tags", qa_tags.TestClusterTags)
573

    
574
  RunCommonNodeTests()
575
  RunGroupListTests()
576
  RunGroupRwTests()
577
  RunNetworkTests()
578

    
579
  # The master shouldn't be readded or put offline; "delay" needs a non-master
580
  # node to test
581
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
582
  try:
583
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
584
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
585
    RunTestIf("delay", qa_cluster.TestDelay, pnode)
586
  finally:
587
    pnode.Release()
588

    
589
  # Make sure the cluster is clean before running instance tests
590
  qa_cluster.AssertClusterVerify()
591

    
592
  pnode = qa_config.AcquireNode()
593
  try:
594
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
595

    
596
    if qa_rapi.Enabled():
597
      RunTest(qa_rapi.TestNode, pnode)
598

    
599
      if qa_config.TestEnabled("instance-add-plain-disk"):
600
        for use_client in [True, False]:
601
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
602
                                  use_client)
603
          try:
604
            if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
605
              RunCommonInstanceTests(rapi_instance)
606
            RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
607
          finally:
608
            rapi_instance.Release()
609
          del rapi_instance
610

    
611
  finally:
612
    pnode.Release()
613

    
614
  config_list = [
615
    ("default-instance-tests", lambda: None, lambda _: None),
616
    ("exclusive-storage-instance-tests",
617
     lambda: qa_cluster.TestSetExclStorCluster(True),
618
     qa_cluster.TestSetExclStorCluster),
619
  ]
620
  for (conf_name, setup_conf_f, restore_conf_f) in config_list:
621
    if qa_config.TestEnabled(conf_name):
622
      oldconf = setup_conf_f()
623
      RunInstanceTests()
624
      restore_conf_f(oldconf)
625

    
626
  pnode = qa_config.AcquireNode()
627
  try:
628
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
629
      for shutdown in [False, True]:
630
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
631
        try:
632
          expnode = qa_config.AcquireNode(exclude=pnode)
633
          try:
634
            if shutdown:
635
              # Stop instance before exporting and removing it
636
              RunTest(qa_instance.TestInstanceShutdown, instance)
637
            RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
638
            RunTest(qa_instance.TestBackupList, expnode)
639
          finally:
640
            expnode.Release()
641
        finally:
642
          instance.Release()
643
        del expnode
644
        del instance
645
      qa_cluster.AssertClusterVerify()
646

    
647
  finally:
648
    pnode.Release()
649

    
650
  RunExclusiveStorageTests()
651

    
652
  # Test removing instance with offline drbd secondary
653
  if qa_config.TestEnabled("instance-remove-drbd-offline"):
654
    # Make sure the master is not put offline
655
    snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
656
    try:
657
      pnode = qa_config.AcquireNode(exclude=snode)
658
      try:
659
        instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
660
        set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
661
        set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
662
        RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
663
                set_offline, set_online)
664
      finally:
665
        pnode.Release()
666
    finally:
667
      snode.Release()
668
    qa_cluster.AssertClusterVerify()
669

    
670
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
671

    
672
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
673

    
674

    
675
@UsesRapiClient
676
def main():
677
  """Main program.
678

679
  """
680
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
681
  parser.add_option("--yes-do-it", dest="yes_do_it",
682
                    action="store_true",
683
                    help="Really execute the tests")
684
  (opts, args) = parser.parse_args()
685

    
686
  if len(args) == 1:
687
    (config_file, ) = args
688
  else:
689
    parser.error("Wrong number of arguments.")
690

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

    
697
  qa_config.Load(config_file)
698

    
699
  primary = qa_config.GetMasterNode().primary
700
  qa_utils.StartMultiplexer(primary)
701
  print ("SSH command for primary node: %s" %
702
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
703
  print ("SSH command for other nodes: %s" %
704
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
705
  try:
706
    RunQa()
707
  finally:
708
    qa_utils.CloseMultiplexers()
709

    
710
if __name__ == "__main__":
711
  main()