Revision 7d88f255

b/qa/ganeti-qa.py
44 44
import ganeti.rapi.client
45 45

  
46 46

  
47
def _FormatHeader(line, end=72, char="-"):
47
def _FormatHeader(line, end=72):
48 48
  """Fill a line up to the end column.
49 49

  
50 50
  """
......
54 54
  return line
55 55

  
56 56

  
57
def RunTest(fn, *args):
58
  """Runs a test after printing a header.
57
def _DescriptionOf(fn):
58
  """Computes the description of an item.
59 59

  
60 60
  """
61 61
  if fn.__doc__:
......
63 63
  else:
64 64
    desc = "%r" % fn
65 65

  
66
  desc = desc.rstrip(".")
66
  return desc.rstrip(".")
67

  
68
def RunTest(fn, *args):
69
  """Runs a test after printing a header.
70

  
71
  """
67 72

  
68 73
  tstart = datetime.datetime.now()
69 74

  
75
  desc = _DescriptionOf(fn)
76

  
70 77
  print
71 78
  print _FormatHeader("%s start %s" % (tstart, desc))
72 79

  
......
79 86
    print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
80 87

  
81 88

  
89
def RunTestIf(testnames, fn, *args):
90
  """Runs a test conditionally.
91

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

  
95
  """
96
  if qa_config.TestEnabled(testnames):
97
    RunTest(fn, *args)
98
  else:
99
    tstart = datetime.datetime.now()
100
    desc = _DescriptionOf(fn)
101
    print _FormatHeader("%s skipping %s, test(s) %s disabled" %
102
                        (tstart, desc, testnames))
103

  
104

  
82 105
def RunEnvTests():
83 106
  """Run several environment tests.
84 107

  
85 108
  """
86
  if not qa_config.TestEnabled('env'):
87
    return
88

  
89
  RunTest(qa_env.TestSshConnection)
90
  RunTest(qa_env.TestIcmpPing)
91
  RunTest(qa_env.TestGanetiCommands)
109
  RunTestIf("env", qa_env.TestSshConnection)
110
  RunTestIf("env", qa_env.TestIcmpPing)
111
  RunTestIf("env", qa_env.TestGanetiCommands)
92 112

  
93 113

  
94 114
def SetupCluster(rapi_user, rapi_secret):
......
98 118
  @param rapi_secret: Login secret for RAPI
99 119

  
100 120
  """
101
  if qa_config.TestEnabled('create-cluster'):
102
    RunTest(qa_cluster.TestClusterInit, rapi_user, rapi_secret)
103
    RunTest(qa_node.TestNodeAddAll)
104
  else:
121
  RunTestIf("create-cluster", qa_cluster.TestClusterInit,
122
            rapi_user, rapi_secret)
123
  RunTestIf("create-cluster", qa_node.TestNodeAddAll)
124
  if not qa_config.TestEnabled("create-cluster"):
105 125
    # consider the nodes are already there
106 126
    qa_node.MarkNodeAddedAll()
107 127

  
108
  if qa_config.TestEnabled("test-jobqueue"):
109
    RunTest(qa_cluster.TestJobqueue)
128
  RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
110 129

  
111 130
  # enable the watcher (unconditionally)
112 131
  RunTest(qa_daemon.TestResumeWatcher)
113 132

  
114
  if qa_config.TestEnabled('node-info'):
115
    RunTest(qa_node.TestNodeInfo)
133
  RunTestIf("node-info", qa_node.TestNodeInfo)
116 134

  
117 135

  
118 136
def RunClusterTests():
119 137
  """Runs tests related to gnt-cluster.
120 138

  
121 139
  """
122
  if qa_config.TestEnabled("cluster-renew-crypto"):
123
    RunTest(qa_cluster.TestClusterRenewCrypto)
124

  
125
  if qa_config.TestEnabled('cluster-verify'):
126
    RunTest(qa_cluster.TestClusterVerify)
127

  
128
  if qa_config.TestEnabled('cluster-reserved-lvs'):
129
    RunTest(qa_cluster.TestClusterReservedLvs)
130

  
131
  if qa_config.TestEnabled("cluster-modify"):
132
    RunTest(qa_cluster.TestClusterModifyBe)
140
  for test, fn in [
141
    ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
142
    ("cluster-verify", qa_cluster.TestClusterVerify),
143
    ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
133 144
    # TODO: add more cluster modify tests
134

  
135
  if qa_config.TestEnabled('cluster-rename'):
136
    RunTest(qa_cluster.TestClusterRename)
137

  
138
  if qa_config.TestEnabled('cluster-info'):
139
    RunTest(qa_cluster.TestClusterVersion)
140
    RunTest(qa_cluster.TestClusterInfo)
141
    RunTest(qa_cluster.TestClusterGetmaster)
142

  
143
  if qa_config.TestEnabled('cluster-copyfile'):
144
    RunTest(qa_cluster.TestClusterCopyfile)
145

  
146
  if qa_config.TestEnabled('cluster-command'):
147
    RunTest(qa_cluster.TestClusterCommand)
148

  
149
  if qa_config.TestEnabled('cluster-burnin'):
150
    RunTest(qa_cluster.TestClusterBurnin)
151

  
152
  if qa_config.TestEnabled('cluster-master-failover'):
153
    RunTest(qa_cluster.TestClusterMasterFailover)
154

  
155
  if qa_rapi.Enabled():
156
    RunTest(qa_rapi.TestVersion)
157
    RunTest(qa_rapi.TestEmptyCluster)
145
    ("cluster-modify", qa_cluster.TestClusterModifyBe),
146
    ("cluster-rename", qa_cluster.TestClusterRename),
147
    ("cluster-info", qa_cluster.TestClusterVersion),
148
    ("cluster-info", qa_cluster.TestClusterInfo),
149
    ("cluster-info", qa_cluster.TestClusterGetmaster),
150
    ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
151
    ("cluster-command", qa_cluster.TestClusterCommand),
152
    ("cluster-burnin", qa_cluster.TestClusterBurnin),
153
    ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
154
    ("rapi", qa_rapi.TestVersion),
155
    ("rapi", qa_rapi.TestEmptyCluster),
156
    ]:
157
    RunTestIf(test, fn)
158 158

  
159 159

  
160 160
def RunOsTests():
161 161
  """Runs all tests related to gnt-os.
162 162

  
163 163
  """
164
  if not qa_config.TestEnabled('os'):
165
    return
166

  
167
  RunTest(qa_os.TestOsList)
168
  RunTest(qa_os.TestOsDiagnose)
169
  RunTest(qa_os.TestOsValid)
170
  RunTest(qa_os.TestOsInvalid)
171
  RunTest(qa_os.TestOsPartiallyValid)
172
  RunTest(qa_os.TestOsModifyValid)
173
  RunTest(qa_os.TestOsModifyInvalid)
174
  RunTest(qa_os.TestOsStates)
164
  for fn in [
165
    qa_os.TestOsList,
166
    qa_os.TestOsDiagnose,
167
    qa_os.TestOsValid,
168
    qa_os.TestOsInvalid,
169
    qa_os.TestOsPartiallyValid,
170
    qa_os.TestOsModifyValid,
171
    qa_os.TestOsModifyInvalid,
172
    qa_os.TestOsStates,
173
    ]:
174
    RunTestIf("os", fn)
175 175

  
176 176

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

  
180 180
  """
181
  if qa_config.TestEnabled('instance-shutdown'):
182
    RunTest(qa_instance.TestInstanceShutdown, instance)
183
    RunTest(qa_instance.TestInstanceStartup, instance)
181
  RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
182
  RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
184 183

  
185
  if qa_config.TestEnabled('instance-list'):
186
    RunTest(qa_instance.TestInstanceList)
184
  RunTestIf("instance-list", qa_instance.TestInstanceList)
187 185

  
188
  if qa_config.TestEnabled('instance-info'):
189
    RunTest(qa_instance.TestInstanceInfo, instance)
186
  RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
190 187

  
191
  if qa_config.TestEnabled('instance-modify'):
192
    RunTest(qa_instance.TestInstanceModify, instance)
193
    if qa_rapi.Enabled():
194
      RunTest(qa_rapi.TestRapiInstanceModify, instance)
188
  RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
189
  RunTestIf(["instance-modify", "rapi"],
190
            qa_rapi.TestRapiInstanceModify, instance)
195 191

  
196
  if qa_config.TestEnabled('instance-console'):
197
    RunTest(qa_instance.TestInstanceConsole, instance)
192
  RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
198 193

  
199
  if qa_config.TestEnabled('instance-reinstall'):
200
    RunTest(qa_instance.TestInstanceShutdown, instance)
201
    RunTest(qa_instance.TestInstanceReinstall, instance)
202
    RunTest(qa_instance.TestInstanceStartup, instance)
194
  RunTestIf("instance-reinstall", qa_instance.TestInstanceShutdown, instance)
195
  RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
196
  RunTestIf("instance-reinstall", qa_instance.TestInstanceStartup, instance)
203 197

  
204
  if qa_config.TestEnabled('instance-reboot'):
205
    RunTest(qa_instance.TestInstanceReboot, instance)
198
  RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
206 199

  
207 200
  if qa_config.TestEnabled('instance-rename'):
208 201
    rename_target = qa_config.get("rename", None)
......
212 205
    else:
213 206
      RunTest(qa_instance.TestInstanceShutdown, instance)
214 207
      RunTest(qa_instance.TestInstanceRename, instance, rename_target)
215
      if qa_rapi.Enabled():
216
        RunTest(qa_rapi.TestRapiInstanceRename, instance, rename_target)
208
      RunTestIf("rapi", qa_rapi.TestRapiInstanceRename, instance, rename_target)
217 209
      RunTest(qa_instance.TestInstanceStartup, instance)
218 210

  
219
  if qa_config.TestEnabled('tags'):
220
    RunTest(qa_tags.TestInstanceTags, instance)
211
  RunTestIf("tags", qa_tags.TestInstanceTags, instance)
221 212

  
222
  if qa_rapi.Enabled():
223
    RunTest(qa_rapi.TestInstance, instance)
213
  RunTestIf("rapi", qa_rapi.TestInstance, instance)
224 214

  
225 215

  
226 216
def RunCommonNodeTests():
227 217
  """Run a few common node tests.
228 218

  
229 219
  """
230
  if qa_config.TestEnabled('node-volumes'):
231
    RunTest(qa_node.TestNodeVolumes)
232

  
233
  if qa_config.TestEnabled("node-storage"):
234
    RunTest(qa_node.TestNodeStorage)
220
  RunTestIf("node-volumes", qa_node.TestNodeVolumes)
221
  RunTestIf("node-storage", qa_node.TestNodeStorage)
235 222

  
236 223

  
237 224
def RunExportImportTests(instance, pnode, snode):
......
262 249
    finally:
263 250
      qa_config.ReleaseNode(expnode)
264 251

  
265
  if (qa_rapi.Enabled() and
266
      qa_config.TestEnabled("inter-cluster-instance-move")):
252
  if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
267 253
    newinst = qa_config.AcquireInstance()
268 254
    try:
269 255
      if snode is None:
......
284 270
  """Test the ganeti-watcher script.
285 271

  
286 272
  """
287
  automatic_restart = \
288
    qa_config.TestEnabled('instance-automatic-restart')
289
  consecutive_failures = \
290
    qa_config.TestEnabled('instance-consecutive-failures')
291

  
292 273
  RunTest(qa_daemon.TestPauseWatcher)
293
  if automatic_restart or consecutive_failures:
294

  
295
    if automatic_restart:
296
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
297 274

  
298
    if consecutive_failures:
299
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
275
  RunTestIf("instance-automatic-restart",
276
            qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
277
  RunTestIf("instance-consecutive-failures",
278
            qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
300 279

  
301 280
  RunTest(qa_daemon.TestResumeWatcher)
302 281

  
......
305 284
  """Test cluster internal hardware failure recovery.
306 285

  
307 286
  """
308
  if qa_config.TestEnabled('instance-failover'):
309
    RunTest(qa_instance.TestInstanceFailover, instance)
287
  RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
310 288

  
311
  if qa_config.TestEnabled("instance-migrate"):
312
    RunTest(qa_instance.TestInstanceMigrate, instance)
313

  
314
    if qa_rapi.Enabled():
315
      RunTest(qa_rapi.TestRapiInstanceMigrate, instance)
289
  RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
290
  RunTestIf(["instance-migrate", "rapi"],
291
            qa_rapi.TestRapiInstanceMigrate, instance)
316 292

  
317 293
  if qa_config.TestEnabled('instance-replace-disks'):
318 294
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
......
322 298
    finally:
323 299
      qa_config.ReleaseNode(othernode)
324 300

  
325
  if qa_config.TestEnabled('node-evacuate'):
326
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
301
  RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, pnode, snode)
327 302

  
328
  if qa_config.TestEnabled('node-failover'):
329
    RunTest(qa_node.TestNodeFailover, pnode, snode)
303
  RunTestIf("node-failover", qa_node.TestNodeFailover, pnode, snode)
330 304

  
331
  if qa_config.TestEnabled('instance-disk-failure'):
332
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
333
            instance, pnode, snode)
334
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
305
  RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
335 306
            instance, pnode, snode)
307
  RunTestIf("instance-disk-failure",
308
            qa_instance.TestInstanceSecondaryDiskFailure, instance,
309
            pnode, snode)
336 310

  
337 311

  
338 312
@rapi.client.UsesRapiClient
......
371 345
  RunClusterTests()
372 346
  RunOsTests()
373 347

  
374
  if qa_config.TestEnabled('tags'):
375
    RunTest(qa_tags.TestClusterTags)
348
  RunTestIf("tags", qa_tags.TestClusterTags)
376 349

  
377 350
  RunCommonNodeTests()
378 351

  
379 352
  pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
380 353
  try:
381
    if qa_config.TestEnabled('node-readd'):
382
      RunTest(qa_node.TestNodeReadd, pnode)
383

  
384
    if qa_config.TestEnabled("node-modify"):
385
      RunTest(qa_node.TestNodeModify, pnode)
354
    RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
355
    RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
386 356
  finally:
387 357
    qa_config.ReleaseNode(pnode)
388 358

  
389 359
  pnode = qa_config.AcquireNode()
390 360
  try:
391
    if qa_config.TestEnabled('tags'):
392
      RunTest(qa_tags.TestNodeTags, pnode)
361
    RunTestIf("tags", qa_tags.TestNodeTags, pnode)
393 362

  
394 363
    if qa_rapi.Enabled():
395 364
      RunTest(qa_rapi.TestNode, pnode)
......
420 389
        snode = qa_config.AcquireNode(exclude=pnode)
421 390
        try:
422 391
          instance = RunTest(func, pnode, snode)
423
          if qa_config.TestEnabled("cluster-verify"):
424
            RunTest(qa_cluster.TestClusterVerify)
392
          RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
425 393
          RunCommonInstanceTests(instance)
426 394
          if qa_config.TestEnabled('instance-convert-disk'):
427 395
            RunTest(qa_instance.TestInstanceShutdown, instance)
......
434 402
        finally:
435 403
          qa_config.ReleaseNode(snode)
436 404

  
437
    if (qa_config.TestEnabled('instance-add-plain-disk') and
438
        qa_config.TestEnabled("instance-export")):
405
    if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
439 406
      for shutdown in [False, True]:
440 407
        instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
441 408
        expnode = qa_config.AcquireNode(exclude=pnode)
......
453 420
  finally:
454 421
    qa_config.ReleaseNode(pnode)
455 422

  
456
  if qa_config.TestEnabled('create-cluster'):
457
    RunTest(qa_node.TestNodeRemoveAll)
423
  RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
458 424

  
459
  if qa_config.TestEnabled('cluster-destroy'):
460
    RunTest(qa_cluster.TestClusterDestroy)
425
  RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
461 426

  
462 427

  
463 428
if __name__ == '__main__':
b/qa/qa_config.py
26 26

  
27 27
from ganeti import utils
28 28
from ganeti import serializer
29
from ganeti import compat
29 30

  
30 31
import qa_error
31 32

  
......
59 60
  return cfg.get(name, default)
60 61

  
61 62

  
62
def TestEnabled(test):
63
  """Returns True if the given test is enabled.
63
def TestEnabled(tests):
64
  """Returns True if the given tests are enabled.
65

  
66
  @param tests: a single test, or a list of tests to check
64 67

  
65 68
  """
66
  return cfg.get("tests", {}).get(test, True)
69
  if isinstance(tests, basestring):
70
    tests = [tests]
71
  return compat.all(cfg.get("tests", {}).get(t, True) for t in tests)
67 72

  
68 73

  
69 74
def GetMasterNode():

Also available in: Unified diff