Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ ab4832d1

History | View | Annotate | Download (22.7 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 _BuildSpecDict(par, mn, st, mx):
488
  return {par: {"min": mn, "std": st, "max": mx}}
489

    
490

    
491
def TestIPolicyPlainInstance():
492
  """Test instance policy interaction with instances"""
493
  params = ["mem-size", "cpu-count", "disk-count", "disk-size", "nic-count"]
494
  if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
495
    print "Template %s not supported" % constants.DT_PLAIN
496
    return
497

    
498
  # This test assumes that the group policy is empty
499
  (_, old_specs) = qa_cluster.TestClusterSetISpecs({})
500
  node = qa_config.AcquireNode()
501
  try:
502
    instance = qa_instance.TestInstanceAddWithPlainDisk([node])
503
    try:
504
      policyerror = [constants.CV_EINSTANCEPOLICY]
505
      for par in params:
506
        qa_cluster.AssertClusterVerify()
507
        (iminval, imaxval) = qa_instance.GetInstanceSpec(instance["name"], par)
508
        # Some specs must be multiple of 4
509
        new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
510
        qa_cluster.TestClusterSetISpecs(new_spec)
511
        qa_cluster.AssertClusterVerify(warnings=policyerror)
512
        if iminval > 0:
513
          # Some specs must be multiple of 4
514
          if iminval >= 4:
515
            upper = iminval - 4
516
          else:
517
            upper = iminval - 1
518
          new_spec = _BuildSpecDict(par, 0, upper, upper)
519
          qa_cluster.TestClusterSetISpecs(new_spec)
520
          qa_cluster.AssertClusterVerify(warnings=policyerror)
521
        qa_cluster.TestClusterSetISpecs(old_specs)
522
      qa_instance.TestInstanceRemove(instance)
523
    finally:
524
      qa_config.ReleaseInstance(instance)
525
  finally:
526
    qa_config.ReleaseNode(node)
527

    
528

    
529
def RunInstanceTests():
530
  """Create and exercise instances."""
531
  instance_tests = [
532
    ("instance-add-plain-disk", constants.DT_PLAIN,
533
     qa_instance.TestInstanceAddWithPlainDisk, 1),
534
    ("instance-add-drbd-disk", constants.DT_DRBD8,
535
     qa_instance.TestInstanceAddWithDrbdDisk, 2),
536
  ]
537

    
538
  for (test_name, templ, create_fun, num_nodes) in instance_tests:
539
    if (qa_config.TestEnabled(test_name) and
540
        qa_config.IsTemplateSupported(templ)):
541
      inodes = qa_config.AcquireManyNodes(num_nodes)
542
      try:
543
        instance = RunTest(create_fun, inodes)
544

    
545
        RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
546
        RunDaemonTests(instance)
547
        for node in inodes:
548
          RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
549
        if len(inodes) > 1:
550
          RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
551
                    constants.INITIAL_NODE_GROUP_NAME,
552
                    inodes[0]["primary"], inodes[1]["primary"])
553
        if qa_config.TestEnabled("instance-convert-disk"):
554
          RunTest(qa_instance.TestInstanceShutdown, instance)
555
          RunTest(qa_instance.TestInstanceConvertDiskToPlain, instance, inodes)
556
          RunTest(qa_instance.TestInstanceStartup, instance)
557
        RunCommonInstanceTests(instance)
558
        RunGroupListTests()
559
        RunExportImportTests(instance, inodes)
560
        RunHardwareFailureTests(instance, inodes)
561
        RunRepairDiskSizes()
562
        RunTest(qa_instance.TestInstanceRemove, instance)
563
        del instance
564
      finally:
565
        qa_config.ReleaseManyNodes(inodes)
566
      qa_cluster.AssertClusterVerify()
567

    
568

    
569
def RunQa():
570
  """Main QA body.
571

572
  """
573
  rapi_user = "ganeti-qa"
574
  rapi_secret = utils.GenerateSecret()
575

    
576
  RunEnvTests()
577
  SetupCluster(rapi_user, rapi_secret)
578

    
579
  # Load RAPI certificate
580
  qa_rapi.Setup(rapi_user, rapi_secret)
581

    
582
  RunClusterTests()
583
  RunOsTests()
584

    
585
  RunTestIf("tags", qa_tags.TestClusterTags)
586

    
587
  RunCommonNodeTests()
588
  RunGroupListTests()
589
  RunGroupRwTests()
590

    
591
  # The master shouldn't be readded or put offline; "delay" needs a non-master
592
  # node to test
593
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
594
  try:
595
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
596
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
597
    RunTestIf("delay", qa_cluster.TestDelay, pnode)
598
  finally:
599
    qa_config.ReleaseNode(pnode)
600

    
601
  # Make sure the cluster is clean before running instance tests
602
  qa_cluster.AssertClusterVerify()
603

    
604
  pnode = qa_config.AcquireNode()
605
  try:
606
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
607

    
608
    if qa_rapi.Enabled():
609
      RunTest(qa_rapi.TestNode, pnode)
610

    
611
      if qa_config.TestEnabled("instance-add-plain-disk"):
612
        for use_client in [True, False]:
613
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
614
                                  use_client)
615
          if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
616
            RunCommonInstanceTests(rapi_instance)
617
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
618
          del rapi_instance
619

    
620
  finally:
621
    qa_config.ReleaseNode(pnode)
622

    
623
  config_list = [
624
    ("default-instance-tests", lambda: None, lambda _: None),
625
    ("exclusive-storage-instance-tests",
626
     lambda: qa_cluster.TestSetExclStorCluster(True),
627
     qa_cluster.TestSetExclStorCluster),
628
  ]
629
  for (conf_name, setup_conf_f, restore_conf_f) in config_list:
630
    if qa_config.TestEnabled(conf_name):
631
      oldconf = setup_conf_f()
632
      RunInstanceTests()
633
      restore_conf_f(oldconf)
634

    
635
  pnode = qa_config.AcquireNode()
636
  try:
637
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
638
      for shutdown in [False, True]:
639
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
640
        expnode = qa_config.AcquireNode(exclude=pnode)
641
        try:
642
          if shutdown:
643
            # Stop instance before exporting and removing it
644
            RunTest(qa_instance.TestInstanceShutdown, instance)
645
          RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
646
          RunTest(qa_instance.TestBackupList, expnode)
647
        finally:
648
          qa_config.ReleaseNode(expnode)
649
        del expnode
650
        del instance
651
      qa_cluster.AssertClusterVerify()
652

    
653
  finally:
654
    qa_config.ReleaseNode(pnode)
655

    
656
  RunExclusiveStorageTests()
657
  RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"],
658
            TestIPolicyPlainInstance)
659

    
660
  # Test removing instance with offline drbd secondary
661
  if qa_config.TestEnabled("instance-remove-drbd-offline"):
662
    # Make sure the master is not put offline
663
    snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
664
    try:
665
      pnode = qa_config.AcquireNode(exclude=snode)
666
      try:
667
        instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
668
        set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
669
        set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
670
        RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
671
                set_offline, set_online)
672
      finally:
673
        qa_config.ReleaseNode(pnode)
674
    finally:
675
      qa_config.ReleaseNode(snode)
676
    qa_cluster.AssertClusterVerify()
677

    
678
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
679

    
680
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
681

    
682

    
683
@UsesRapiClient
684
def main():
685
  """Main program.
686

687
  """
688
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
689
  parser.add_option("--yes-do-it", dest="yes_do_it",
690
                    action="store_true",
691
                    help="Really execute the tests")
692
  (qa_config.options, args) = parser.parse_args()
693

    
694
  if len(args) == 1:
695
    (config_file, ) = args
696
  else:
697
    parser.error("Wrong number of arguments.")
698

    
699
  if not qa_config.options.yes_do_it:
700
    print ("Executing this script irreversibly destroys any Ganeti\n"
701
           "configuration on all nodes involved. If you really want\n"
702
           "to start testing, supply the --yes-do-it option.")
703
    sys.exit(1)
704

    
705
  qa_config.Load(config_file)
706

    
707
  primary = qa_config.GetMasterNode()["primary"]
708
  qa_utils.StartMultiplexer(primary)
709
  print ("SSH command for primary node: %s" %
710
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
711
  print ("SSH command for other nodes: %s" %
712
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
713
  try:
714
    RunQa()
715
  finally:
716
    qa_utils.CloseMultiplexers()
717

    
718
if __name__ == "__main__":
719
  main()