Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ aecba21e

History | View | Annotate | Download (21.5 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
    print _FormatHeader("%s skipping %s, test(s) %s disabled" %
112
                        (tstart, desc, testnames))
113

    
114

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

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

    
123

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

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

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

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

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

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

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

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

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

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

    
163

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

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

    
195

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

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

    
202

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

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

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

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

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

    
232

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
314

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

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

    
323

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

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

    
331

    
332
def RunNetworkTests():
333
  """Run tests for network management.
334

335
  """
336
  RunTestIf("network", qa_network.TestNetworkAddRemove)
337
  RunTestIf("network", qa_network.TestNetworkConnect)
338

    
339

    
340
def RunGroupRwTests():
341
  """Run tests for adding/removing/renaming groups.
342

343
  """
344
  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
345
  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
346
  RunTestIf("group-rwops", qa_group.TestGroupModify)
347
  RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups)
348
  RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
349
            qa_group.GetDefaultGroup())
350

    
351

    
352
def RunExportImportTests(instance, inodes):
353
  """Tries to export and import the instance.
354

355
  @type inodes: list of nodes
356
  @param inodes: current nodes of the instance
357

358
  """
359
  if qa_config.TestEnabled("instance-export"):
360
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)
361

    
362
    pnode = inodes[0]
363
    expnode = qa_config.AcquireNode(exclude=pnode)
364
    try:
365
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
366

    
367
      RunTest(qa_instance.TestBackupList, expnode)
368

    
369
      if qa_config.TestEnabled("instance-import"):
370
        newinst = qa_config.AcquireInstance()
371
        try:
372
          RunTest(qa_instance.TestInstanceImport, newinst, pnode,
373
                  expnode, name)
374
          # Check if starting the instance works
375
          RunTest(qa_instance.TestInstanceStartup, newinst)
376
          RunTest(qa_instance.TestInstanceRemove, newinst)
377
        finally:
378
          newinst.Release()
379
    finally:
380
      expnode.Release()
381

    
382
  if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
383
    newinst = qa_config.AcquireInstance()
384
    try:
385
      tnode = qa_config.AcquireNode(exclude=inodes)
386
      try:
387
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
388
                inodes, tnode)
389
      finally:
390
        tnode.Release()
391
    finally:
392
      newinst.Release()
393

    
394

    
395
def RunDaemonTests(instance):
396
  """Test the ganeti-watcher script.
397

398
  """
399
  RunTest(qa_daemon.TestPauseWatcher)
400

    
401
  RunTestIf("instance-automatic-restart",
402
            qa_daemon.TestInstanceAutomaticRestart, instance)
403
  RunTestIf("instance-consecutive-failures",
404
            qa_daemon.TestInstanceConsecutiveFailures, instance)
405

    
406
  RunTest(qa_daemon.TestResumeWatcher)
407

    
408

    
409
def RunHardwareFailureTests(instance, inodes):
410
  """Test cluster internal hardware failure recovery.
411

412
  """
413
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
414
  RunTestIf(["instance-failover", "rapi"],
415
            qa_rapi.TestRapiInstanceFailover, instance)
416

    
417
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
418
  RunTestIf(["instance-migrate", "rapi"],
419
            qa_rapi.TestRapiInstanceMigrate, instance)
420

    
421
  if qa_config.TestEnabled("instance-replace-disks"):
422
    # We just need alternative secondary nodes, hence "- 1"
423
    othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
424
    try:
425
      RunTestIf("rapi", qa_rapi.TestRapiInstanceReplaceDisks, instance)
426
      RunTest(qa_instance.TestReplaceDisks,
427
              instance, inodes, othernodes)
428
    finally:
429
      qa_config.ReleaseManyNodes(othernodes)
430
    del othernodes
431

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

    
451
  if len(inodes) >= 2:
452
    RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
453
    RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
454

    
455

    
456
def RunExclusiveStorageTests():
457
  """Test exclusive storage."""
458
  if not qa_config.TestEnabled("cluster-exclusive-storage"):
459
    return
460

    
461
  node = qa_config.AcquireNode()
462
  try:
463
    old_es = qa_cluster.TestSetExclStorCluster(False)
464
    qa_cluster.TestExclStorSingleNode(node)
465

    
466
    qa_cluster.TestSetExclStorCluster(True)
467
    qa_cluster.TestExclStorSharedPv(node)
468

    
469
    if qa_config.TestEnabled("instance-add-plain-disk"):
470
      # Make sure that the cluster doesn't have any pre-existing problem
471
      qa_cluster.AssertClusterVerify()
472

    
473
      # Create and allocate instances
474
      instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
475
      try:
476
        instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
477
        try:
478
          # cluster-verify checks that disks are allocated correctly
479
          qa_cluster.AssertClusterVerify()
480

    
481
          # Remove instances
482
          qa_instance.TestInstanceRemove(instance2)
483
          qa_instance.TestInstanceRemove(instance1)
484
        finally:
485
          instance2.Release()
486
      finally:
487
        instance1.Release()
488

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

    
507

    
508
def RunInstanceTests():
509
  """Create and exercise instances."""
510
  instance_tests = [
511
    ("instance-add-plain-disk", constants.DT_PLAIN,
512
     qa_instance.TestInstanceAddWithPlainDisk, 1),
513
    ("instance-add-drbd-disk", constants.DT_DRBD8,
514
     qa_instance.TestInstanceAddWithDrbdDisk, 2),
515
  ]
516

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

    
550

    
551
def RunQa():
552
  """Main QA body.
553

554
  """
555
  rapi_user = "ganeti-qa"
556
  rapi_secret = utils.GenerateSecret()
557

    
558
  RunEnvTests()
559
  SetupCluster(rapi_user, rapi_secret)
560

    
561
  # Load RAPI certificate
562
  qa_rapi.Setup(rapi_user, rapi_secret)
563

    
564
  RunClusterTests()
565
  RunOsTests()
566

    
567
  RunTestIf("tags", qa_tags.TestClusterTags)
568

    
569
  RunCommonNodeTests()
570
  RunGroupListTests()
571
  RunGroupRwTests()
572
  RunNetworkTests()
573

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

    
584
  # Make sure the cluster is clean before running instance tests
585
  qa_cluster.AssertClusterVerify()
586

    
587
  pnode = qa_config.AcquireNode()
588
  try:
589
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
590

    
591
    if qa_rapi.Enabled():
592
      RunTest(qa_rapi.TestNode, pnode)
593

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

    
606
  finally:
607
    pnode.Release()
608

    
609
  config_list = [
610
    ("default-instance-tests", lambda: None, lambda _: None),
611
    ("exclusive-storage-instance-tests",
612
     lambda: qa_cluster.TestSetExclStorCluster(True),
613
     qa_cluster.TestSetExclStorCluster),
614
  ]
615
  for (conf_name, setup_conf_f, restore_conf_f) in config_list:
616
    if qa_config.TestEnabled(conf_name):
617
      oldconf = setup_conf_f()
618
      RunInstanceTests()
619
      restore_conf_f(oldconf)
620

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

    
642
  finally:
643
    pnode.Release()
644

    
645
  RunExclusiveStorageTests()
646

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

    
665
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
666

    
667
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
668

    
669

    
670
@UsesRapiClient
671
def main():
672
  """Main program.
673

674
  """
675
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
676
  parser.add_option("--yes-do-it", dest="yes_do_it",
677
                    action="store_true",
678
                    help="Really execute the tests")
679
  (opts, args) = parser.parse_args()
680

    
681
  if len(args) == 1:
682
    (config_file, ) = args
683
  else:
684
    parser.error("Wrong number of arguments.")
685

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

    
692
  qa_config.Load(config_file)
693

    
694
  primary = qa_config.GetMasterNode().primary
695
  qa_utils.StartMultiplexer(primary)
696
  print ("SSH command for primary node: %s" %
697
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
698
  print ("SSH command for other nodes: %s" %
699
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
700
  try:
701
    RunQa()
702
  finally:
703
    qa_utils.CloseMultiplexers()
704

    
705
if __name__ == "__main__":
706
  main()