Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 9738ca94

History | View | Annotate | Download (12.2 kB)

1
#!/usr/bin/python
2
#
3

    
4
# Copyright (C) 2007, 2008, 2009, 2010 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
import sys
27
import datetime
28
import optparse
29

    
30
import qa_cluster
31
import qa_config
32
import qa_daemon
33
import qa_env
34
import qa_instance
35
import qa_node
36
import qa_os
37
import qa_rapi
38
import qa_tags
39
import qa_utils
40

    
41
from ganeti import utils
42
from ganeti import rapi
43

    
44
import ganeti.rapi.client
45

    
46

    
47
def RunTest(fn, *args):
48
  """Runs a test after printing a header.
49

50
  """
51
  if fn.__doc__:
52
    desc = fn.__doc__.splitlines()[0].strip()
53
  else:
54
    desc = '%r' % fn
55

    
56
  now = str(datetime.datetime.now())
57

    
58
  print
59
  print '---', now, ('-' * (55 - len(now)))
60
  print desc
61
  print '-' * 60
62

    
63
  return fn(*args)
64

    
65

    
66
def RunEnvTests():
67
  """Run several environment tests.
68

69
  """
70
  if not qa_config.TestEnabled('env'):
71
    return
72

    
73
  RunTest(qa_env.TestSshConnection)
74
  RunTest(qa_env.TestIcmpPing)
75
  RunTest(qa_env.TestGanetiCommands)
76

    
77

    
78
def SetupCluster(rapi_user, rapi_secret):
79
  """Initializes the cluster.
80

81
  @param rapi_user: Login user for RAPI
82
  @param rapi_secret: Login secret for RAPI
83

84
  """
85
  if qa_config.TestEnabled('create-cluster'):
86
    RunTest(qa_cluster.TestClusterInit, rapi_user, rapi_secret)
87
    RunTest(qa_node.TestNodeAddAll)
88
    RunTest(qa_cluster.TestJobqueue)
89
  else:
90
    # consider the nodes are already there
91
    qa_node.MarkNodeAddedAll()
92
  if qa_config.TestEnabled('node-info'):
93
    RunTest(qa_node.TestNodeInfo)
94

    
95

    
96
def RunClusterTests():
97
  """Runs tests related to gnt-cluster.
98

99
  """
100
  if qa_config.TestEnabled("cluster-renew-crypto"):
101
    RunTest(qa_cluster.TestClusterRenewCrypto)
102

    
103
  if qa_config.TestEnabled('cluster-verify'):
104
    RunTest(qa_cluster.TestClusterVerify)
105

    
106
  if qa_config.TestEnabled('cluster-reserved-lvs'):
107
    RunTest(qa_cluster.TestClusterReservedLvs)
108

    
109
  if qa_config.TestEnabled("cluster-modify"):
110
    RunTest(qa_cluster.TestClusterModifyBe)
111
    # TODO: add more cluster modify tests
112

    
113
  if qa_config.TestEnabled('cluster-rename'):
114
    RunTest(qa_cluster.TestClusterRename)
115

    
116
  if qa_config.TestEnabled('cluster-info'):
117
    RunTest(qa_cluster.TestClusterVersion)
118
    RunTest(qa_cluster.TestClusterInfo)
119
    RunTest(qa_cluster.TestClusterGetmaster)
120

    
121
  if qa_config.TestEnabled('cluster-copyfile'):
122
    RunTest(qa_cluster.TestClusterCopyfile)
123

    
124
  if qa_config.TestEnabled('cluster-command'):
125
    RunTest(qa_cluster.TestClusterCommand)
126

    
127
  if qa_config.TestEnabled('cluster-burnin'):
128
    RunTest(qa_cluster.TestClusterBurnin)
129

    
130
  if qa_config.TestEnabled('cluster-master-failover'):
131
    RunTest(qa_cluster.TestClusterMasterFailover)
132

    
133
  if qa_rapi.Enabled():
134
    RunTest(qa_rapi.TestVersion)
135
    RunTest(qa_rapi.TestEmptyCluster)
136

    
137

    
138
def RunOsTests():
139
  """Runs all tests related to gnt-os.
140

141
  """
142
  if not qa_config.TestEnabled('os'):
143
    return
144

    
145
  RunTest(qa_os.TestOsList)
146
  RunTest(qa_os.TestOsDiagnose)
147
  RunTest(qa_os.TestOsValid)
148
  RunTest(qa_os.TestOsInvalid)
149
  RunTest(qa_os.TestOsPartiallyValid)
150
  RunTest(qa_os.TestOsModifyValid)
151
  RunTest(qa_os.TestOsModifyInvalid)
152
  RunTest(qa_os.TestOsStates)
153

    
154

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

158
  """
159
  if qa_config.TestEnabled('instance-shutdown'):
160
    RunTest(qa_instance.TestInstanceShutdown, instance)
161
    RunTest(qa_instance.TestInstanceStartup, instance)
162

    
163
  if qa_config.TestEnabled('instance-list'):
164
    RunTest(qa_instance.TestInstanceList)
165

    
166
  if qa_config.TestEnabled('instance-info'):
167
    RunTest(qa_instance.TestInstanceInfo, instance)
168

    
169
  if qa_config.TestEnabled('instance-modify'):
170
    RunTest(qa_instance.TestInstanceModify, instance)
171
    if qa_rapi.Enabled():
172
      RunTest(qa_rapi.TestRapiInstanceModify, instance)
173

    
174
  if qa_config.TestEnabled('instance-console'):
175
    RunTest(qa_instance.TestInstanceConsole, instance)
176

    
177
  if qa_config.TestEnabled('instance-reinstall'):
178
    RunTest(qa_instance.TestInstanceShutdown, instance)
179
    RunTest(qa_instance.TestInstanceReinstall, instance)
180
    RunTest(qa_instance.TestInstanceStartup, instance)
181

    
182
  if qa_config.TestEnabled('instance-reboot'):
183
    RunTest(qa_instance.TestInstanceReboot, instance)
184

    
185
  if qa_config.TestEnabled('instance-rename'):
186
    rename_target = qa_config.get("rename", None)
187
    if rename_target is None:
188
      print qa_utils.FormatError("Can rename instance, 'rename' entry is"
189
                                 " missing from configuration")
190
    else:
191
      RunTest(qa_instance.TestInstanceShutdown, instance)
192
      RunTest(qa_instance.TestInstanceRename, instance, rename_target)
193
      if qa_rapi.Enabled():
194
        RunTest(qa_rapi.TestRapiInstanceRename, instance, rename_target)
195
      RunTest(qa_instance.TestInstanceStartup, instance)
196

    
197
  if qa_config.TestEnabled('tags'):
198
    RunTest(qa_tags.TestInstanceTags, instance)
199

    
200
  if qa_config.TestEnabled('node-volumes'):
201
    RunTest(qa_node.TestNodeVolumes)
202

    
203
  if qa_config.TestEnabled("node-storage"):
204
    RunTest(qa_node.TestNodeStorage)
205

    
206
  if qa_rapi.Enabled():
207
    RunTest(qa_rapi.TestInstance, instance)
208

    
209

    
210
def RunExportImportTests(instance, pnode, snode):
211
  """Tries to export and import the instance.
212

213
  @param pnode: current primary node of the instance
214
  @param snode: current secondary node of the instance, if any,
215
      otherwise None
216

217
  """
218
  if qa_config.TestEnabled('instance-export'):
219
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)
220

    
221
    expnode = qa_config.AcquireNode(exclude=pnode)
222
    try:
223
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
224

    
225
      RunTest(qa_instance.TestBackupList, expnode)
226

    
227
      if qa_config.TestEnabled('instance-import'):
228
        newinst = qa_config.AcquireInstance()
229
        try:
230
          RunTest(qa_instance.TestInstanceImport, pnode, newinst,
231
                  expnode, name)
232
          RunTest(qa_instance.TestInstanceRemove, newinst)
233
        finally:
234
          qa_config.ReleaseInstance(newinst)
235
    finally:
236
      qa_config.ReleaseNode(expnode)
237

    
238
  if (qa_rapi.Enabled() and
239
      qa_config.TestEnabled("inter-cluster-instance-move")):
240
    newinst = qa_config.AcquireInstance()
241
    try:
242
      if snode is None:
243
        excl = [pnode]
244
      else:
245
        excl = [pnode, snode]
246
      tnode = qa_config.AcquireNode(exclude=excl)
247
      try:
248
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
249
                pnode, snode, tnode)
250
      finally:
251
        qa_config.ReleaseNode(tnode)
252
    finally:
253
      qa_config.ReleaseInstance(newinst)
254

    
255

    
256
def RunDaemonTests(instance, pnode):
257
  """Test the ganeti-watcher script.
258

259
  """
260
  automatic_restart = \
261
    qa_config.TestEnabled('instance-automatic-restart')
262
  consecutive_failures = \
263
    qa_config.TestEnabled('instance-consecutive-failures')
264

    
265
  if automatic_restart or consecutive_failures:
266
    qa_daemon.PrintCronWarning()
267

    
268
    if automatic_restart:
269
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
270

    
271
    if consecutive_failures:
272
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
273

    
274

    
275
def RunHardwareFailureTests(instance, pnode, snode):
276
  """Test cluster internal hardware failure recovery.
277

278
  """
279
  if qa_config.TestEnabled('instance-failover'):
280
    RunTest(qa_instance.TestInstanceFailover, instance)
281

    
282
  if qa_config.TestEnabled("instance-migrate"):
283
    RunTest(qa_instance.TestInstanceMigrate, instance)
284

    
285
    if qa_rapi.Enabled():
286
      RunTest(qa_rapi.TestRapiInstanceMigrate, instance)
287

    
288
  if qa_config.TestEnabled('instance-replace-disks'):
289
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
290
    try:
291
      RunTest(qa_instance.TestReplaceDisks,
292
              instance, pnode, snode, othernode)
293
    finally:
294
      qa_config.ReleaseNode(othernode)
295

    
296
  if qa_config.TestEnabled('node-evacuate'):
297
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
298

    
299
  if qa_config.TestEnabled('node-failover'):
300
    RunTest(qa_node.TestNodeFailover, pnode, snode)
301

    
302
  if qa_config.TestEnabled('instance-disk-failure'):
303
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
304
            instance, pnode, snode)
305
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
306
            instance, pnode, snode)
307

    
308

    
309
@rapi.client.UsesRapiClient
310
def main():
311
  """Main program.
312

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

    
320
  if len(args) == 1:
321
    (config_file, ) = args
322
  else:
323
    parser.error("Wrong number of arguments.")
324

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

    
331
  qa_config.Load(config_file)
332

    
333
  rapi_user = "ganeti-qa"
334
  rapi_secret = utils.GenerateSecret()
335

    
336
  RunEnvTests()
337
  SetupCluster(rapi_user, rapi_secret)
338

    
339
  # Load RAPI certificate
340
  qa_rapi.Setup(rapi_user, rapi_secret)
341

    
342
  RunClusterTests()
343
  RunOsTests()
344

    
345
  if qa_config.TestEnabled('tags'):
346
    RunTest(qa_tags.TestClusterTags)
347

    
348
  if qa_config.TestEnabled('node-readd'):
349
    master = qa_config.GetMasterNode()
350
    pnode = qa_config.AcquireNode(exclude=master)
351
    try:
352
      RunTest(qa_node.TestNodeReadd, pnode)
353
    finally:
354
      qa_config.ReleaseNode(pnode)
355

    
356
  pnode = qa_config.AcquireNode()
357
  try:
358
    if qa_config.TestEnabled('tags'):
359
      RunTest(qa_tags.TestNodeTags, pnode)
360

    
361
    if qa_rapi.Enabled():
362
      RunTest(qa_rapi.TestNode, pnode)
363

    
364
      if qa_config.TestEnabled("instance-add-plain-disk"):
365
        for use_client in [True, False]:
366
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
367
                                  use_client)
368
          RunCommonInstanceTests(rapi_instance)
369
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
370
          del rapi_instance
371

    
372
    if qa_config.TestEnabled('instance-add-plain-disk'):
373
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
374
      RunCommonInstanceTests(instance)
375
      RunExportImportTests(instance, pnode, None)
376
      RunDaemonTests(instance, pnode)
377
      RunTest(qa_instance.TestInstanceRemove, instance)
378
      del instance
379

    
380
    multinode_tests = [
381
      ('instance-add-drbd-disk',
382
       qa_instance.TestInstanceAddWithDrbdDisk),
383
    ]
384

    
385
    for name, func in multinode_tests:
386
      if qa_config.TestEnabled(name):
387
        snode = qa_config.AcquireNode(exclude=pnode)
388
        try:
389
          instance = RunTest(func, pnode, snode)
390
          RunCommonInstanceTests(instance)
391
          if qa_config.TestEnabled('instance-convert-disk'):
392
            RunTest(qa_instance.TestInstanceShutdown, instance)
393
            RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
394
            RunTest(qa_instance.TestInstanceStartup, instance)
395
          RunExportImportTests(instance, pnode, snode)
396
          RunHardwareFailureTests(instance, pnode, snode)
397
          RunTest(qa_instance.TestInstanceRemove, instance)
398
          del instance
399
        finally:
400
          qa_config.ReleaseNode(snode)
401

    
402
    if (qa_config.TestEnabled('instance-add-plain-disk') and
403
        qa_config.TestEnabled("instance-export")):
404
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
405
      expnode = qa_config.AcquireNode(exclude=pnode)
406
      try:
407
        RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
408
        RunTest(qa_instance.TestBackupList, expnode)
409
      finally:
410
        qa_config.ReleaseNode(expnode)
411
      del expnode
412
      del instance
413

    
414
  finally:
415
    qa_config.ReleaseNode(pnode)
416

    
417
  if qa_config.TestEnabled('create-cluster'):
418
    RunTest(qa_node.TestNodeRemoveAll)
419

    
420
  if qa_config.TestEnabled('cluster-destroy'):
421
    RunTest(qa_cluster.TestClusterDestroy)
422

    
423

    
424
if __name__ == '__main__':
425
  main()