Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ c072e788

History | View | Annotate | Download (21.6 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_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
      tgt_instance.Release()
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 RunNetworkTests():
334
  """Run tests for network management.
335

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

    
340

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

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

    
352

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

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

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

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

    
368
      RunTest(qa_instance.TestBackupList, expnode)
369

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

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

    
395

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

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

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

    
407
  RunTest(qa_daemon.TestResumeWatcher)
408

    
409

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

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

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

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

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

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

    
456

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

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

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

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

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

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

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

    
508

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

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

    
551

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

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

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

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

    
565
  RunClusterTests()
566
  RunOsTests()
567

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

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

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

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

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

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

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

    
607
  finally:
608
    pnode.Release()
609

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

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

    
643
  finally:
644
    pnode.Release()
645

    
646
  RunExclusiveStorageTests()
647

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

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

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

    
670

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

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

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

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

    
693
  qa_config.Load(config_file)
694

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

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