ganeti-qa.py 17.8 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, 2012 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

26
# pylint: disable=C0103
Iustin Pop's avatar
Iustin Pop committed
27
28
# 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
41
import qa_job
Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
42
import qa_rapi
Michael Hanselmann's avatar
Michael Hanselmann committed
43
import qa_tags
44
import qa_utils
Iustin Pop's avatar
Iustin Pop committed
45

46
from ganeti import utils
47
from ganeti import rapi # pylint: disable=W0611
48
from ganeti import constants
49

50
import ganeti.rapi.client # pylint: disable=W0611
51
from ganeti.rapi.client import UsesRapiClient
52

Iustin Pop's avatar
Iustin Pop committed
53

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

  """
  line = "---- " + line + " "
Andrea Spadaccini's avatar
Andrea Spadaccini committed
59
  line += "-" * (end - len(line))
Iustin Pop's avatar
Iustin Pop committed
60
61
62
63
  line = line.rstrip()
  return line


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

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

Iustin Pop's avatar
Iustin Pop committed
73
74
  return desc.rstrip(".")

75

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

  """
Iustin Pop's avatar
Iustin Pop committed
80

Iustin Pop's avatar
Iustin Pop committed
81
  tstart = datetime.datetime.now()
Iustin Pop's avatar
Iustin Pop committed
82

Iustin Pop's avatar
Iustin Pop committed
83
84
  desc = _DescriptionOf(fn)

Iustin Pop's avatar
Iustin Pop committed
85
86
87
88
  print
  print _FormatHeader("%s start %s" % (tstart, desc))

  try:
89
    retval = fn(*args, **kwargs)
Iustin Pop's avatar
Iustin Pop committed
90
91
92
93
94
    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
95
96


97
def RunTestIf(testnames, fn, *args, **kwargs):
Iustin Pop's avatar
Iustin Pop committed
98
99
100
101
102
103
104
  """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):
105
    RunTest(fn, *args, **kwargs)
Iustin Pop's avatar
Iustin Pop committed
106
107
108
109
110
111
112
  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
113
114
def RunEnvTests():
  """Run several environment tests.
Iustin Pop's avatar
Iustin Pop committed
115
116

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

121

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

125
126
127
  @param rapi_user: Login user for RAPI
  @param rapi_secret: Login secret for RAPI

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

  # Test on empty cluster
  RunTestIf("node-list", qa_node.TestNodeList)
  RunTestIf("instance-list", qa_instance.TestInstanceList)
135
  RunTestIf("job-list", qa_job.TestJobList)
136

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

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

144
145
146
  # enable the watcher (unconditionally)
  RunTest(qa_daemon.TestResumeWatcher)

147
148
  RunTestIf("node-list", qa_node.TestNodeList)

149
150
151
  # Test listing fields
  RunTestIf("node-list", qa_node.TestNodeListFields)
  RunTestIf("instance-list", qa_instance.TestInstanceListFields)
152
  RunTestIf("job-list", qa_job.TestJobListFields)
153
  RunTestIf("instance-export", qa_instance.TestBackupListFields)
154

Iustin Pop's avatar
Iustin Pop committed
155
  RunTestIf("node-info", qa_node.TestNodeInfo)
Michael Hanselmann's avatar
Michael Hanselmann committed
156
157
158
159


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

Michael Hanselmann's avatar
Michael Hanselmann committed
161
  """
Iustin Pop's avatar
Iustin Pop committed
162
  for test, fn in [
163
    ("create-cluster", qa_cluster.TestClusterInitDisk),
Iustin Pop's avatar
Iustin Pop committed
164
165
166
    ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
    ("cluster-verify", qa_cluster.TestClusterVerify),
    ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
167
    # TODO: add more cluster modify tests
168
    ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
Iustin Pop's avatar
Iustin Pop committed
169
    ("cluster-modify", qa_cluster.TestClusterModifyBe),
170
    ("cluster-modify", qa_cluster.TestClusterModifyDisk),
Iustin Pop's avatar
Iustin Pop committed
171
172
173
174
    ("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
175
    ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
Iustin Pop's avatar
Iustin Pop committed
176
177
178
179
    ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
    ("cluster-command", qa_cluster.TestClusterCommand),
    ("cluster-burnin", qa_cluster.TestClusterBurnin),
    ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
180
181
    ("cluster-master-failover",
     qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
Iustin Pop's avatar
Iustin Pop committed
182
    ("cluster-oob", qa_cluster.TestClusterOob),
Iustin Pop's avatar
Iustin Pop committed
183
184
    ("rapi", qa_rapi.TestVersion),
    ("rapi", qa_rapi.TestEmptyCluster),
185
    ("rapi", qa_rapi.TestRapiQuery),
Iustin Pop's avatar
Iustin Pop committed
186
187
    ]:
    RunTestIf(test, fn)
188

189

190
191
192
193
194
195
196
def RunRepairDiskSizes():
  """Run the repair disk-sizes test.

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


Michael Hanselmann's avatar
Michael Hanselmann committed
197
198
def RunOsTests():
  """Runs all tests related to gnt-os.
Michael Hanselmann's avatar
Michael Hanselmann committed
199

Michael Hanselmann's avatar
Michael Hanselmann committed
200
  """
201
202
203
204
205
  if qa_config.TestEnabled("rapi"):
    rapi_getos = qa_rapi.GetOperatingSystems
  else:
    rapi_getos = None

Iustin Pop's avatar
Iustin Pop committed
206
207
208
  for fn in [
    qa_os.TestOsList,
    qa_os.TestOsDiagnose,
209
210
211
212
    ]:
    RunTestIf("os", fn)

  for fn in [
Iustin Pop's avatar
Iustin Pop committed
213
214
215
    qa_os.TestOsValid,
    qa_os.TestOsInvalid,
    qa_os.TestOsPartiallyValid,
216
217
218
219
    ]:
    RunTestIf("os", fn, rapi_getos)

  for fn in [
Iustin Pop's avatar
Iustin Pop committed
220
221
    qa_os.TestOsModifyValid,
    qa_os.TestOsModifyInvalid,
222
    qa_os.TestOsStatesNonExisting,
Iustin Pop's avatar
Iustin Pop committed
223
224
    ]:
    RunTestIf("os", fn)
Michael Hanselmann's avatar
Michael Hanselmann committed
225
226
227
228
229
230


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

  """
Iustin Pop's avatar
Iustin Pop committed
231
  RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
232
233
  RunTestIf(["instance-shutdown", "instance-console", "rapi"],
            qa_rapi.TestRapiStoppedInstanceConsole, instance)
234
235
  RunTestIf(["instance-shutdown", "instance-modify"],
            qa_instance.TestInstanceStoppedModify, instance)
Iustin Pop's avatar
Iustin Pop committed
236
  RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
Iustin Pop's avatar
Iustin Pop committed
237

238
239
240
241
242
243
  # Test shutdown/start via RAPI
  RunTestIf(["instance-shutdown", "rapi"],
            qa_rapi.TestRapiInstanceShutdown, instance)
  RunTestIf(["instance-shutdown", "rapi"],
            qa_rapi.TestRapiInstanceStartup, instance)

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

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

Iustin Pop's avatar
Iustin Pop committed
248
249
250
  RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
  RunTestIf(["instance-modify", "rapi"],
            qa_rapi.TestRapiInstanceModify, instance)
251

Iustin Pop's avatar
Iustin Pop committed
252
  RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
253
254
  RunTestIf(["instance-console", "rapi"],
            qa_rapi.TestRapiInstanceConsole, instance)
255

256
257
258
259
260
261
  DOWN_TESTS = qa_config.Either([
    "instance-reinstall",
    "instance-rename",
    "instance-grow-disk",
    ])

Iustin Pop's avatar
Iustin Pop committed
262
263
264
265
  # shutdown instance for any 'down' tests
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)

  # now run the 'down' state tests
Iustin Pop's avatar
Iustin Pop committed
266
  RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
267
268
  RunTestIf(["instance-reinstall", "rapi"],
            qa_rapi.TestRapiInstanceReinstall, instance)
269

Iustin Pop's avatar
Iustin Pop committed
270
  if qa_config.TestEnabled("instance-rename"):
271
272
273
274
275
    tgt_instance = qa_config.AcquireInstance()
    try:
      rename_source = instance["name"]
      rename_target = tgt_instance["name"]
      # perform instance rename to the same name
Iustin Pop's avatar
Iustin Pop committed
276
      RunTest(qa_instance.TestInstanceRenameAndBack,
277
              rename_source, rename_source)
Iustin Pop's avatar
Iustin Pop committed
278
      RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
279
280
281
282
                rename_source, rename_source)
      if rename_target is not None:
        # perform instance rename to a different name, if we have one configured
        RunTest(qa_instance.TestInstanceRenameAndBack,
283
                rename_source, rename_target)
284
285
286
287
        RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
                  rename_source, rename_target)
    finally:
      qa_config.ReleaseInstance(tgt_instance)
Iustin Pop's avatar
Iustin Pop committed
288

Iustin Pop's avatar
Iustin Pop committed
289
290
  RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)

Iustin Pop's avatar
Iustin Pop committed
291
292
293
294
  # and now start the instance again
  RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)

  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
295

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

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

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

302
303
304
  # Lists instances, too
  RunTestIf("node-list", qa_node.TestNodeList)

305
306
307
  # Some jobs have been run, let's test listing them
  RunTestIf("job-list", qa_job.TestJobList)

308
309
310
311
312

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

  """
Iustin Pop's avatar
Iustin Pop committed
313
314
  RunTestIf("node-volumes", qa_node.TestNodeVolumes)
  RunTestIf("node-storage", qa_node.TestNodeStorage)
315
  RunTestIf("node-oob", qa_node.TestOutOfBand)
316

317

318
319
320
321
def RunGroupListTests():
  """Run tests for listing node groups.

  """
322
323
  RunTestIf("group-list", qa_group.TestGroupList)
  RunTestIf("group-list", qa_group.TestGroupListFields)
324
325


326
327
328
329
330
def RunGroupRwTests():
  """Run tests for adding/removing/renaming groups.

  """
  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
331
332
  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
  RunTestIf("group-rwops", qa_group.TestGroupModify)
333
  RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups)
334
335
  RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
            qa_group.GetDefaultGroup())
336

337

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

341
342
343
344
  @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
345
  """
Iustin Pop's avatar
Iustin Pop committed
346
  if qa_config.TestEnabled("instance-export"):
347
348
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)

Michael Hanselmann's avatar
Michael Hanselmann committed
349
350
351
352
353
354
    expnode = qa_config.AcquireNode(exclude=pnode)
    try:
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)

      RunTest(qa_instance.TestBackupList, expnode)

Iustin Pop's avatar
Iustin Pop committed
355
      if qa_config.TestEnabled("instance-import"):
Michael Hanselmann's avatar
Michael Hanselmann committed
356
        newinst = qa_config.AcquireInstance()
Michael Hanselmann's avatar
Michael Hanselmann committed
357
        try:
358
          RunTest(qa_instance.TestInstanceImport, newinst, pnode,
Michael Hanselmann's avatar
Michael Hanselmann committed
359
                  expnode, name)
360
361
          # Check if starting the instance works
          RunTest(qa_instance.TestInstanceStartup, newinst)
Michael Hanselmann's avatar
Michael Hanselmann committed
362
          RunTest(qa_instance.TestInstanceRemove, newinst)
Michael Hanselmann's avatar
Michael Hanselmann committed
363
        finally:
Michael Hanselmann's avatar
Michael Hanselmann committed
364
365
366
          qa_config.ReleaseInstance(newinst)
    finally:
      qa_config.ReleaseNode(expnode)
Michael Hanselmann's avatar
Michael Hanselmann committed
367

Iustin Pop's avatar
Iustin Pop committed
368
  if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
369
370
    newinst = qa_config.AcquireInstance()
    try:
371
372
373
374
375
      if snode is None:
        excl = [pnode]
      else:
        excl = [pnode, snode]
      tnode = qa_config.AcquireNode(exclude=excl)
376
377
      try:
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
378
                pnode, snode, tnode)
379
      finally:
380
        qa_config.ReleaseNode(tnode)
381
382
383
    finally:
      qa_config.ReleaseInstance(newinst)

Michael Hanselmann's avatar
Michael Hanselmann committed
384

385
def RunDaemonTests(instance):
Michael Hanselmann's avatar
Michael Hanselmann committed
386
  """Test the ganeti-watcher script.
387

Michael Hanselmann's avatar
Michael Hanselmann committed
388
  """
389
  RunTest(qa_daemon.TestPauseWatcher)
390

Iustin Pop's avatar
Iustin Pop committed
391
  RunTestIf("instance-automatic-restart",
392
            qa_daemon.TestInstanceAutomaticRestart, instance)
Iustin Pop's avatar
Iustin Pop committed
393
  RunTestIf("instance-consecutive-failures",
394
            qa_daemon.TestInstanceConsecutiveFailures, instance)
395

396
397
  RunTest(qa_daemon.TestResumeWatcher)

398

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

Michael Hanselmann's avatar
Michael Hanselmann committed
402
  """
Iustin Pop's avatar
Iustin Pop committed
403
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
404
405
  RunTestIf(["instance-failover", "rapi"],
            qa_rapi.TestRapiInstanceFailover, instance)
Michael Hanselmann's avatar
Michael Hanselmann committed
406

Iustin Pop's avatar
Iustin Pop committed
407
408
409
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
  RunTestIf(["instance-migrate", "rapi"],
            qa_rapi.TestRapiInstanceMigrate, instance)
410

Iustin Pop's avatar
Iustin Pop committed
411
  if qa_config.TestEnabled("instance-replace-disks"):
412
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
413
    try:
414
      RunTestIf("rapi", qa_rapi.TestRapiInstanceReplaceDisks, instance)
415
416
417
418
419
      RunTest(qa_instance.TestReplaceDisks,
              instance, pnode, snode, othernode)
    finally:
      qa_config.ReleaseNode(othernode)

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

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

Iustin Pop's avatar
Iustin Pop committed
424
  RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
Michael Hanselmann's avatar
Michael Hanselmann committed
425
            instance, pnode, snode)
Iustin Pop's avatar
Iustin Pop committed
426
427
428
  RunTestIf("instance-disk-failure",
            qa_instance.TestInstanceSecondaryDiskFailure, instance,
            pnode, snode)
Michael Hanselmann's avatar
Michael Hanselmann committed
429
430


431
432
def RunQa():
  """Main QA body.
Michael Hanselmann's avatar
Michael Hanselmann committed
433
434

  """
435
436
437
  rapi_user = "ganeti-qa"
  rapi_secret = utils.GenerateSecret()

Michael Hanselmann's avatar
Michael Hanselmann committed
438
  RunEnvTests()
439
  SetupCluster(rapi_user, rapi_secret)
Michael Hanselmann's avatar
Michael Hanselmann committed
440
441

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

Michael Hanselmann's avatar
Michael Hanselmann committed
444
445
  RunClusterTests()
  RunOsTests()
446

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

449
  RunCommonNodeTests()
450
  RunGroupListTests()
451
  RunGroupRwTests()
452

453
454
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
  try:
Iustin Pop's avatar
Iustin Pop committed
455
456
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
457
    RunTestIf("delay", qa_cluster.TestDelay, pnode)
458
459
  finally:
    qa_config.ReleaseNode(pnode)
460

Michael Hanselmann's avatar
Michael Hanselmann committed
461
462
  pnode = qa_config.AcquireNode()
  try:
Iustin Pop's avatar
Iustin Pop committed
463
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
Michael Hanselmann's avatar
Michael Hanselmann committed
464

Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
465
466
467
    if qa_rapi.Enabled():
      RunTest(qa_rapi.TestNode, pnode)

468
      if qa_config.TestEnabled("instance-add-plain-disk"):
469
470
471
        for use_client in [True, False]:
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
                                  use_client)
472
473
          if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
            RunCommonInstanceTests(rapi_instance)
474
475
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
          del rapi_instance
476

477
    if qa_config.TestEnabled("instance-add-plain-disk"):
Michael Hanselmann's avatar
Michael Hanselmann committed
478
479
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
      RunCommonInstanceTests(instance)
480
      RunGroupListTests()
481
      RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
482
      RunExportImportTests(instance, pnode, None)
483
      RunDaemonTests(instance)
484
      RunRepairDiskSizes()
Michael Hanselmann's avatar
Michael Hanselmann committed
485
486
      RunTest(qa_instance.TestInstanceRemove, instance)
      del instance
487

488
    multinode_tests = [
Iustin Pop's avatar
Iustin Pop committed
489
      ("instance-add-drbd-disk",
490
491
492
493
494
495
496
497
       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)
498
499
          RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, pnode)
          RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, snode)
500
          RunCommonInstanceTests(instance)
501
          RunGroupListTests()
502
503
504
          RunTest(qa_group.TestAssignNodesIncludingSplit,
                  constants.INITIAL_NODE_GROUP_NAME,
                  pnode["primary"], snode["primary"])
Iustin Pop's avatar
Iustin Pop committed
505
          if qa_config.TestEnabled("instance-convert-disk"):
506
            RunTest(qa_instance.TestInstanceShutdown, instance)
507
            RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
508
            RunTest(qa_instance.TestInstanceStartup, instance)
509
          RunExportImportTests(instance, pnode, snode)
510
          RunHardwareFailureTests(instance, pnode, snode)
511
          RunRepairDiskSizes()
512
513
514
515
          RunTest(qa_instance.TestInstanceRemove, instance)
          del instance
        finally:
          qa_config.ReleaseNode(snode)
Iustin Pop's avatar
Iustin Pop committed
516

517
518
519
520
521
522
523
524
525
526
527
528
    # Test removing instance with offline drbd secondary
    if qa_config.TestEnabled("instance-remove-drbd-offline"):
      snode = qa_config.AcquireNode(exclude=pnode)
      instance = \
        qa_instance.TestInstanceAddWithDrbdDisk(pnode, snode)
      try:
        qa_node.MakeNodeOffline(snode, "yes")
        RunTest(qa_instance.TestInstanceRemove, instance)
      finally:
        qa_node.MakeNodeOffline(snode, "no")
        qa_config.ReleaseNode(snode)

Iustin Pop's avatar
Iustin Pop committed
529
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
530
531
532
533
534
535
536
537
538
539
540
541
542
      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
543

Iustin Pop's avatar
Iustin Pop committed
544
  finally:
Michael Hanselmann's avatar
Michael Hanselmann committed
545
    qa_config.ReleaseNode(pnode)
Iustin Pop's avatar
Iustin Pop committed
546

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

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

551

552
@UsesRapiClient
553
554
555
556
557
def main():
  """Main program.

  """
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
Iustin Pop's avatar
Iustin Pop committed
558
  parser.add_option("--yes-do-it", dest="yes_do_it",
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
      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)

576
577
578
579
580
581
  primary = qa_config.GetMasterNode()["primary"]
  qa_utils.StartMultiplexer(primary)
  print ("SSH command for primary node: %s" %
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
  print ("SSH command for other nodes: %s" %
         utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
582
583
584
585
586
  try:
    RunQa()
  finally:
    qa_utils.CloseMultiplexers()

Iustin Pop's avatar
Iustin Pop committed
587
if __name__ == "__main__":
588
  main()