ganeti-qa.py 15.5 KB
Newer Older
Iustin Pop's avatar
Iustin Pop committed
1
#!/usr/bin/python -u
Iustin Pop's avatar
Iustin Pop committed
2
3
#

4
# Copyright (C) 2007, 2008, 2009, 2010, 2011 Google Inc.
Iustin Pop's avatar
Iustin Pop committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


22
"""Script for doing QA on Ganeti.
23
24

"""
Iustin Pop's avatar
Iustin Pop committed
25

Iustin Pop's avatar
Iustin Pop committed
26
27
28
# pylint: disable-msg=C0103
# due to invalid name

Iustin Pop's avatar
Iustin Pop committed
29
import sys
30
31
import datetime
import optparse
Iustin Pop's avatar
Iustin Pop committed
32

33
34
35
36
import qa_cluster
import qa_config
import qa_daemon
import qa_env
37
import qa_group
38
39
import qa_instance
import qa_node
40
import qa_os
Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
41
import qa_rapi
Michael Hanselmann's avatar
Michael Hanselmann committed
42
import qa_tags
43
import qa_utils
Iustin Pop's avatar
Iustin Pop committed
44

45
from ganeti import utils
46
from ganeti import rapi
47
from ganeti import constants
48

Iustin Pop's avatar
Iustin Pop committed
49
import ganeti.rapi.client # pylint: disable-msg=W0611
50

Iustin Pop's avatar
Iustin Pop committed
51

Iustin Pop's avatar
Iustin Pop committed
52
def _FormatHeader(line, end=72):
Iustin Pop's avatar
Iustin Pop committed
53
54
55
56
57
58
59
60
61
  """Fill a line up to the end column.

  """
  line = "---- " + line + " "
  line += "-" * (end-len(line))
  line = line.rstrip()
  return line


Iustin Pop's avatar
Iustin Pop committed
62
63
def _DescriptionOf(fn):
  """Computes the description of an item.
Iustin Pop's avatar
Iustin Pop committed
64
65

  """
66
67
  if fn.__doc__:
    desc = fn.__doc__.splitlines()[0].strip()
Iustin Pop's avatar
Iustin Pop committed
68
  else:
Iustin Pop's avatar
Iustin Pop committed
69
    desc = "%r" % fn
Iustin Pop's avatar
Iustin Pop committed
70

Iustin Pop's avatar
Iustin Pop committed
71
72
  return desc.rstrip(".")

73

Iustin Pop's avatar
Iustin Pop committed
74
75
76
77
def RunTest(fn, *args):
  """Runs a test after printing a header.

  """
Iustin Pop's avatar
Iustin Pop committed
78

Iustin Pop's avatar
Iustin Pop committed
79
  tstart = datetime.datetime.now()
Iustin Pop's avatar
Iustin Pop committed
80

Iustin Pop's avatar
Iustin Pop committed
81
82
  desc = _DescriptionOf(fn)

Iustin Pop's avatar
Iustin Pop committed
83
84
85
86
87
88
89
90
91
92
  print
  print _FormatHeader("%s start %s" % (tstart, desc))

  try:
    retval = fn(*args)
    return retval
  finally:
    tstop = datetime.datetime.now()
    tdelta = tstop - tstart
    print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
Iustin Pop's avatar
Iustin Pop committed
93
94


Iustin Pop's avatar
Iustin Pop committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
def RunTestIf(testnames, fn, *args):
  """Runs a test conditionally.

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

  """
  if qa_config.TestEnabled(testnames):
    RunTest(fn, *args)
  else:
    tstart = datetime.datetime.now()
    desc = _DescriptionOf(fn)
    print _FormatHeader("%s skipping %s, test(s) %s disabled" %
                        (tstart, desc, testnames))


Michael Hanselmann's avatar
Michael Hanselmann committed
111
112
def RunEnvTests():
  """Run several environment tests.
Iustin Pop's avatar
Iustin Pop committed
113
114

  """
Iustin Pop's avatar
Iustin Pop committed
115
116
117
  RunTestIf("env", qa_env.TestSshConnection)
  RunTestIf("env", qa_env.TestIcmpPing)
  RunTestIf("env", qa_env.TestGanetiCommands)
Iustin Pop's avatar
Iustin Pop committed
118

119

120
def SetupCluster(rapi_user, rapi_secret):
Michael Hanselmann's avatar
Michael Hanselmann committed
121
  """Initializes the cluster.
Iustin Pop's avatar
Iustin Pop committed
122

123
124
125
  @param rapi_user: Login user for RAPI
  @param rapi_secret: Login secret for RAPI

Michael Hanselmann's avatar
Michael Hanselmann committed
126
  """
Iustin Pop's avatar
Iustin Pop committed
127
128
  RunTestIf("create-cluster", qa_cluster.TestClusterInit,
            rapi_user, rapi_secret)
129
130
131
132
133

  # Test on empty cluster
  RunTestIf("node-list", qa_node.TestNodeList)
  RunTestIf("instance-list", qa_instance.TestInstanceList)

Iustin Pop's avatar
Iustin Pop committed
134
135
  RunTestIf("create-cluster", qa_node.TestNodeAddAll)
  if not qa_config.TestEnabled("create-cluster"):
136
137
    # consider the nodes are already there
    qa_node.MarkNodeAddedAll()
138

Iustin Pop's avatar
Iustin Pop committed
139
  RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
140

141
142
143
  # enable the watcher (unconditionally)
  RunTest(qa_daemon.TestResumeWatcher)

144
145
  RunTestIf("node-list", qa_node.TestNodeList)

146
147
148
149
  # Test listing fields
  RunTestIf("node-list", qa_node.TestNodeListFields)
  RunTestIf("instance-list", qa_instance.TestInstanceListFields)

Iustin Pop's avatar
Iustin Pop committed
150
  RunTestIf("node-info", qa_node.TestNodeInfo)
Michael Hanselmann's avatar
Michael Hanselmann committed
151
152
153
154


def RunClusterTests():
  """Runs tests related to gnt-cluster.
155

Michael Hanselmann's avatar
Michael Hanselmann committed
156
  """
Iustin Pop's avatar
Iustin Pop committed
157
158
159
160
  for test, fn in [
    ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
    ("cluster-verify", qa_cluster.TestClusterVerify),
    ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
161
    # TODO: add more cluster modify tests
Iustin Pop's avatar
Iustin Pop committed
162
163
164
165
166
    ("cluster-modify", qa_cluster.TestClusterModifyBe),
    ("cluster-rename", qa_cluster.TestClusterRename),
    ("cluster-info", qa_cluster.TestClusterVersion),
    ("cluster-info", qa_cluster.TestClusterInfo),
    ("cluster-info", qa_cluster.TestClusterGetmaster),
Iustin Pop's avatar
Iustin Pop committed
167
    ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
Iustin Pop's avatar
Iustin Pop committed
168
169
170
171
    ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
    ("cluster-command", qa_cluster.TestClusterCommand),
    ("cluster-burnin", qa_cluster.TestClusterBurnin),
    ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
172
173
    ("cluster-master-failover",
     qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
Iustin Pop's avatar
Iustin Pop committed
174
    ("cluster-oob", qa_cluster.TestClusterOob),
Iustin Pop's avatar
Iustin Pop committed
175
176
    ("rapi", qa_rapi.TestVersion),
    ("rapi", qa_rapi.TestEmptyCluster),
177
    ("rapi", qa_rapi.TestRapiQuery),
Iustin Pop's avatar
Iustin Pop committed
178
179
    ]:
    RunTestIf(test, fn)
180

181

182
183
184
185
186
187
188
def RunRepairDiskSizes():
  """Run the repair disk-sizes test.

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


Michael Hanselmann's avatar
Michael Hanselmann committed
189
190
def RunOsTests():
  """Runs all tests related to gnt-os.
Michael Hanselmann's avatar
Michael Hanselmann committed
191

Michael Hanselmann's avatar
Michael Hanselmann committed
192
  """
193
194
195
196
197
  if qa_config.TestEnabled("rapi"):
    rapi_getos = qa_rapi.GetOperatingSystems
  else:
    rapi_getos = None

Iustin Pop's avatar
Iustin Pop committed
198
199
200
  for fn in [
    qa_os.TestOsList,
    qa_os.TestOsDiagnose,
201
202
203
204
    ]:
    RunTestIf("os", fn)

  for fn in [
Iustin Pop's avatar
Iustin Pop committed
205
206
207
    qa_os.TestOsValid,
    qa_os.TestOsInvalid,
    qa_os.TestOsPartiallyValid,
208
209
210
211
    ]:
    RunTestIf("os", fn, rapi_getos)

  for fn in [
Iustin Pop's avatar
Iustin Pop committed
212
213
    qa_os.TestOsModifyValid,
    qa_os.TestOsModifyInvalid,
214
    qa_os.TestOsStatesNonExisting,
Iustin Pop's avatar
Iustin Pop committed
215
216
    ]:
    RunTestIf("os", fn)
Michael Hanselmann's avatar
Michael Hanselmann committed
217
218
219
220
221
222


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

  """
Iustin Pop's avatar
Iustin Pop committed
223
  RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
224
225
  RunTestIf(["instance-shutdown", "instance-console", "rapi"],
            qa_rapi.TestRapiStoppedInstanceConsole, instance)
Iustin Pop's avatar
Iustin Pop committed
226
  RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
Iustin Pop's avatar
Iustin Pop committed
227

Iustin Pop's avatar
Iustin Pop committed
228
  RunTestIf("instance-list", qa_instance.TestInstanceList)
Michael Hanselmann's avatar
Michael Hanselmann committed
229

Iustin Pop's avatar
Iustin Pop committed
230
  RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
231

Iustin Pop's avatar
Iustin Pop committed
232
233
234
  RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
  RunTestIf(["instance-modify", "rapi"],
            qa_rapi.TestRapiInstanceModify, instance)
235

Iustin Pop's avatar
Iustin Pop committed
236
  RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
237
238
  RunTestIf(["instance-console", "rapi"],
            qa_rapi.TestRapiInstanceConsole, instance)
239

Iustin Pop's avatar
Iustin Pop committed
240
241
  RunTestIf("instance-reinstall", qa_instance.TestInstanceShutdown, instance)
  RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
242
243
  RunTestIf(["instance-reinstall", "rapi"],
            qa_rapi.TestRapiInstanceReinstall, instance)
Iustin Pop's avatar
Iustin Pop committed
244
  RunTestIf("instance-reinstall", qa_instance.TestInstanceStartup, instance)
Iustin Pop's avatar
Iustin Pop committed
245

Iustin Pop's avatar
Iustin Pop committed
246
  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
247

248
  if qa_config.TestEnabled('instance-rename'):
249
    rename_source = instance["name"]
250
    rename_target = qa_config.get("rename", None)
251
252
253
    RunTest(qa_instance.TestInstanceShutdown, instance)
    # perform instance rename to the same name
    RunTest(qa_instance.TestInstanceRename, rename_source, rename_source)
254
255
    RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
              rename_source, rename_source)
256
257
    if rename_target is not None:
      # perform instance rename to a different name, if we have one configured
258
259
      RunTest(qa_instance.TestInstanceRename, rename_source, rename_target)
      RunTest(qa_instance.TestInstanceRename, rename_target, rename_source)
260
261
262
263
      RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
                rename_source, rename_target)
      RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
                rename_target, rename_source)
264
    RunTest(qa_instance.TestInstanceStartup, instance)
265

Iustin Pop's avatar
Iustin Pop committed
266
  RunTestIf("tags", qa_tags.TestInstanceTags, instance)
Michael Hanselmann's avatar
Michael Hanselmann committed
267

Michael Hanselmann's avatar
Michael Hanselmann committed
268
  RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
Michael Hanselmann's avatar
Michael Hanselmann committed
269

Iustin Pop's avatar
Iustin Pop committed
270
  RunTestIf("rapi", qa_rapi.TestInstance, instance)
271

272
273
274
  # Lists instances, too
  RunTestIf("node-list", qa_node.TestNodeList)

275
276
277
278
279

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

  """
Iustin Pop's avatar
Iustin Pop committed
280
281
  RunTestIf("node-volumes", qa_node.TestNodeVolumes)
  RunTestIf("node-storage", qa_node.TestNodeStorage)
282
  RunTestIf("node-oob", qa_node.TestOutOfBand)
283

284

285
286
287
288
def RunGroupListTests():
  """Run tests for listing node groups.

  """
289
290
  RunTestIf("group-list", qa_group.TestGroupList)
  RunTestIf("group-list", qa_group.TestGroupListFields)
291
292


293
294
295
296
297
def RunGroupRwTests():
  """Run tests for adding/removing/renaming groups.

  """
  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
298
299
  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
  RunTestIf("group-rwops", qa_group.TestGroupModify)
300
  RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups)
301

302

303
def RunExportImportTests(instance, pnode, snode):
Michael Hanselmann's avatar
Michael Hanselmann committed
304
  """Tries to export and import the instance.
Iustin Pop's avatar
Iustin Pop committed
305

306
307
308
309
  @param pnode: current primary node of the instance
  @param snode: current secondary node of the instance, if any,
      otherwise None

Michael Hanselmann's avatar
Michael Hanselmann committed
310
311
  """
  if qa_config.TestEnabled('instance-export'):
312
313
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)

Michael Hanselmann's avatar
Michael Hanselmann committed
314
315
316
317
318
319
320
321
    expnode = qa_config.AcquireNode(exclude=pnode)
    try:
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)

      RunTest(qa_instance.TestBackupList, expnode)

      if qa_config.TestEnabled('instance-import'):
        newinst = qa_config.AcquireInstance()
Michael Hanselmann's avatar
Michael Hanselmann committed
322
        try:
Michael Hanselmann's avatar
Michael Hanselmann committed
323
324
325
          RunTest(qa_instance.TestInstanceImport, pnode, newinst,
                  expnode, name)
          RunTest(qa_instance.TestInstanceRemove, newinst)
Michael Hanselmann's avatar
Michael Hanselmann committed
326
        finally:
Michael Hanselmann's avatar
Michael Hanselmann committed
327
328
329
          qa_config.ReleaseInstance(newinst)
    finally:
      qa_config.ReleaseNode(expnode)
Michael Hanselmann's avatar
Michael Hanselmann committed
330

Iustin Pop's avatar
Iustin Pop committed
331
  if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
332
333
    newinst = qa_config.AcquireInstance()
    try:
334
335
336
337
338
      if snode is None:
        excl = [pnode]
      else:
        excl = [pnode, snode]
      tnode = qa_config.AcquireNode(exclude=excl)
339
340
      try:
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
341
                pnode, snode, tnode)
342
      finally:
343
        qa_config.ReleaseNode(tnode)
344
345
346
    finally:
      qa_config.ReleaseInstance(newinst)

Michael Hanselmann's avatar
Michael Hanselmann committed
347

Michael Hanselmann's avatar
Michael Hanselmann committed
348
349
def RunDaemonTests(instance, pnode):
  """Test the ganeti-watcher script.
350

Michael Hanselmann's avatar
Michael Hanselmann committed
351
  """
352
  RunTest(qa_daemon.TestPauseWatcher)
353

Iustin Pop's avatar
Iustin Pop committed
354
355
356
357
  RunTestIf("instance-automatic-restart",
            qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
  RunTestIf("instance-consecutive-failures",
            qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
358

359
360
  RunTest(qa_daemon.TestResumeWatcher)

361

Michael Hanselmann's avatar
Michael Hanselmann committed
362
363
def RunHardwareFailureTests(instance, pnode, snode):
  """Test cluster internal hardware failure recovery.
Iustin Pop's avatar
Iustin Pop committed
364

Michael Hanselmann's avatar
Michael Hanselmann committed
365
  """
Iustin Pop's avatar
Iustin Pop committed
366
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
Michael Hanselmann's avatar
Michael Hanselmann committed
367

Iustin Pop's avatar
Iustin Pop committed
368
369
370
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
  RunTestIf(["instance-migrate", "rapi"],
            qa_rapi.TestRapiInstanceMigrate, instance)
371

372
  if qa_config.TestEnabled('instance-replace-disks'):
373
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
374
375
376
377
378
379
    try:
      RunTest(qa_instance.TestReplaceDisks,
              instance, pnode, snode, othernode)
    finally:
      qa_config.ReleaseNode(othernode)

Iustin Pop's avatar
Iustin Pop committed
380
  RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, pnode, snode)
Michael Hanselmann's avatar
Michael Hanselmann committed
381

Iustin Pop's avatar
Iustin Pop committed
382
  RunTestIf("node-failover", qa_node.TestNodeFailover, pnode, snode)
Michael Hanselmann's avatar
Michael Hanselmann committed
383

Iustin Pop's avatar
Iustin Pop committed
384
  RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
Michael Hanselmann's avatar
Michael Hanselmann committed
385
            instance, pnode, snode)
Iustin Pop's avatar
Iustin Pop committed
386
387
388
  RunTestIf("instance-disk-failure",
            qa_instance.TestInstanceSecondaryDiskFailure, instance,
            pnode, snode)
Michael Hanselmann's avatar
Michael Hanselmann committed
389
390


391
392
def RunQa():
  """Main QA body.
Michael Hanselmann's avatar
Michael Hanselmann committed
393
394

  """
395
396
397
  rapi_user = "ganeti-qa"
  rapi_secret = utils.GenerateSecret()

Michael Hanselmann's avatar
Michael Hanselmann committed
398
  RunEnvTests()
399
  SetupCluster(rapi_user, rapi_secret)
Michael Hanselmann's avatar
Michael Hanselmann committed
400
401

  # Load RAPI certificate
402
  qa_rapi.Setup(rapi_user, rapi_secret)
Michael Hanselmann's avatar
Michael Hanselmann committed
403

Michael Hanselmann's avatar
Michael Hanselmann committed
404
405
  RunClusterTests()
  RunOsTests()
406

Iustin Pop's avatar
Iustin Pop committed
407
  RunTestIf("tags", qa_tags.TestClusterTags)
Michael Hanselmann's avatar
Michael Hanselmann committed
408

409
  RunCommonNodeTests()
410
  RunGroupListTests()
411
  RunGroupRwTests()
412

413
414
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
  try:
Iustin Pop's avatar
Iustin Pop committed
415
416
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
417
418
  finally:
    qa_config.ReleaseNode(pnode)
419

Michael Hanselmann's avatar
Michael Hanselmann committed
420
421
  pnode = qa_config.AcquireNode()
  try:
Iustin Pop's avatar
Iustin Pop committed
422
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
Michael Hanselmann's avatar
Michael Hanselmann committed
423

Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
424
425
426
    if qa_rapi.Enabled():
      RunTest(qa_rapi.TestNode, pnode)

427
      if qa_config.TestEnabled("instance-add-plain-disk"):
428
429
430
431
432
433
        for use_client in [True, False]:
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
                                  use_client)
          RunCommonInstanceTests(rapi_instance)
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
          del rapi_instance
434

435
    if qa_config.TestEnabled("instance-add-plain-disk"):
Michael Hanselmann's avatar
Michael Hanselmann committed
436
437
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
      RunCommonInstanceTests(instance)
438
      RunGroupListTests()
439
      RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
440
      RunExportImportTests(instance, pnode, None)
Michael Hanselmann's avatar
Michael Hanselmann committed
441
      RunDaemonTests(instance, pnode)
442
      RunRepairDiskSizes()
Michael Hanselmann's avatar
Michael Hanselmann committed
443
444
      RunTest(qa_instance.TestInstanceRemove, instance)
      del instance
445

446
447
448
449
450
451
452
453
454
455
456
    multinode_tests = [
      ('instance-add-drbd-disk',
       qa_instance.TestInstanceAddWithDrbdDisk),
    ]

    for name, func in multinode_tests:
      if qa_config.TestEnabled(name):
        snode = qa_config.AcquireNode(exclude=pnode)
        try:
          instance = RunTest(func, pnode, snode)
          RunCommonInstanceTests(instance)
457
          RunGroupListTests()
458
459
460
          RunTest(qa_group.TestAssignNodesIncludingSplit,
                  constants.INITIAL_NODE_GROUP_NAME,
                  pnode["primary"], snode["primary"])
461
          if qa_config.TestEnabled('instance-convert-disk'):
462
            RunTest(qa_instance.TestInstanceShutdown, instance)
463
            RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
464
            RunTest(qa_instance.TestInstanceStartup, instance)
465
          RunExportImportTests(instance, pnode, snode)
466
          RunHardwareFailureTests(instance, pnode, snode)
467
          RunRepairDiskSizes()
468
469
470
471
          RunTest(qa_instance.TestInstanceRemove, instance)
          del instance
        finally:
          qa_config.ReleaseNode(snode)
Iustin Pop's avatar
Iustin Pop committed
472

Iustin Pop's avatar
Iustin Pop committed
473
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
474
475
476
477
478
479
480
481
482
483
484
485
486
      for shutdown in [False, True]:
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
        expnode = qa_config.AcquireNode(exclude=pnode)
        try:
          if shutdown:
            # Stop instance before exporting and removing it
            RunTest(qa_instance.TestInstanceShutdown, instance)
          RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
          RunTest(qa_instance.TestBackupList, expnode)
        finally:
          qa_config.ReleaseNode(expnode)
        del expnode
        del instance
487

Iustin Pop's avatar
Iustin Pop committed
488
  finally:
Michael Hanselmann's avatar
Michael Hanselmann committed
489
    qa_config.ReleaseNode(pnode)
Iustin Pop's avatar
Iustin Pop committed
490

Iustin Pop's avatar
Iustin Pop committed
491
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
Iustin Pop's avatar
Iustin Pop committed
492

Iustin Pop's avatar
Iustin Pop committed
493
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
Iustin Pop's avatar
Iustin Pop committed
494

495

496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
@rapi.client.UsesRapiClient
def main():
  """Main program.

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

  if len(args) == 1:
    (config_file, ) = args
  else:
    parser.error("Wrong number of arguments.")

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

  qa_config.Load(config_file)

  qa_utils.StartMultiplexer(qa_config.GetMasterNode()["primary"])
  try:
    RunQa()
  finally:
    qa_utils.CloseMultiplexers()

526
527
if __name__ == '__main__':
  main()