Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 1377433b

History | View | Annotate | Download (11.8 kB)

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

    
4
# Copyright (C) 2007 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-rename'):
110
    RunTest(qa_cluster.TestClusterRename)
111

    
112
  if qa_config.TestEnabled('cluster-info'):
113
    RunTest(qa_cluster.TestClusterVersion)
114
    RunTest(qa_cluster.TestClusterInfo)
115
    RunTest(qa_cluster.TestClusterGetmaster)
116

    
117
  if qa_config.TestEnabled('cluster-copyfile'):
118
    RunTest(qa_cluster.TestClusterCopyfile)
119

    
120
  if qa_config.TestEnabled('cluster-command'):
121
    RunTest(qa_cluster.TestClusterCommand)
122

    
123
  if qa_config.TestEnabled('cluster-burnin'):
124
    RunTest(qa_cluster.TestClusterBurnin)
125

    
126
  if qa_config.TestEnabled('cluster-master-failover'):
127
    RunTest(qa_cluster.TestClusterMasterFailover)
128

    
129
  if qa_rapi.Enabled():
130
    RunTest(qa_rapi.TestVersion)
131
    RunTest(qa_rapi.TestEmptyCluster)
132

    
133

    
134
def RunOsTests():
135
  """Runs all tests related to gnt-os.
136

137
  """
138
  if not qa_config.TestEnabled('os'):
139
    return
140

    
141
  RunTest(qa_os.TestOsList)
142
  RunTest(qa_os.TestOsDiagnose)
143
  RunTest(qa_os.TestOsValid)
144
  RunTest(qa_os.TestOsInvalid)
145
  RunTest(qa_os.TestOsPartiallyValid)
146
  RunTest(qa_os.TestOsModifyValid)
147
  RunTest(qa_os.TestOsModifyInvalid)
148

    
149

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

153
  """
154
  if qa_config.TestEnabled('instance-shutdown'):
155
    RunTest(qa_instance.TestInstanceShutdown, instance)
156
    RunTest(qa_instance.TestInstanceStartup, instance)
157

    
158
  if qa_config.TestEnabled('instance-list'):
159
    RunTest(qa_instance.TestInstanceList)
160

    
161
  if qa_config.TestEnabled('instance-info'):
162
    RunTest(qa_instance.TestInstanceInfo, instance)
163

    
164
  if qa_config.TestEnabled('instance-modify'):
165
    RunTest(qa_instance.TestInstanceModify, instance)
166
    if qa_rapi.Enabled():
167
      RunTest(qa_rapi.TestRapiInstanceModify, instance)
168

    
169
  if qa_config.TestEnabled('instance-console'):
170
    RunTest(qa_instance.TestInstanceConsole, instance)
171

    
172
  if qa_config.TestEnabled('instance-reinstall'):
173
    RunTest(qa_instance.TestInstanceShutdown, instance)
174
    RunTest(qa_instance.TestInstanceReinstall, instance)
175
    RunTest(qa_instance.TestInstanceStartup, instance)
176

    
177
  if qa_config.TestEnabled('instance-reboot'):
178
    RunTest(qa_instance.TestInstanceReboot, instance)
179

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

    
192
  if qa_config.TestEnabled('tags'):
193
    RunTest(qa_tags.TestInstanceTags, instance)
194

    
195
  if qa_config.TestEnabled('node-volumes'):
196
    RunTest(qa_node.TestNodeVolumes)
197

    
198
  if qa_config.TestEnabled("node-storage"):
199
    RunTest(qa_node.TestNodeStorage)
200

    
201
  if qa_rapi.Enabled():
202
    RunTest(qa_rapi.TestInstance, instance)
203

    
204

    
205
def RunExportImportTests(instance, pnode):
206
  """Tries to export and import the instance.
207

208
  """
209
  if qa_config.TestEnabled('instance-export'):
210
    RunTest(qa_instance.TestInstanceExportNoTarget, instance)
211

    
212
    expnode = qa_config.AcquireNode(exclude=pnode)
213
    try:
214
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
215

    
216
      RunTest(qa_instance.TestBackupList, expnode)
217

    
218
      if qa_config.TestEnabled('instance-import'):
219
        newinst = qa_config.AcquireInstance()
220
        try:
221
          RunTest(qa_instance.TestInstanceImport, pnode, newinst,
222
                  expnode, name)
223
          RunTest(qa_instance.TestInstanceRemove, newinst)
224
        finally:
225
          qa_config.ReleaseInstance(newinst)
226
    finally:
227
      qa_config.ReleaseNode(expnode)
228

    
229
  if (qa_rapi.Enabled() and
230
      qa_config.TestEnabled("inter-cluster-instance-move")):
231
    newinst = qa_config.AcquireInstance()
232
    try:
233
      pnode2 = qa_config.AcquireNode(exclude=pnode)
234
      try:
235
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
236
                pnode2, pnode)
237
      finally:
238
        qa_config.ReleaseNode(pnode2)
239
    finally:
240
      qa_config.ReleaseInstance(newinst)
241

    
242

    
243
def RunDaemonTests(instance, pnode):
244
  """Test the ganeti-watcher script.
245

246
  """
247
  automatic_restart = \
248
    qa_config.TestEnabled('instance-automatic-restart')
249
  consecutive_failures = \
250
    qa_config.TestEnabled('instance-consecutive-failures')
251

    
252
  if automatic_restart or consecutive_failures:
253
    qa_daemon.PrintCronWarning()
254

    
255
    if automatic_restart:
256
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
257

    
258
    if consecutive_failures:
259
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
260

    
261

    
262
def RunHardwareFailureTests(instance, pnode, snode):
263
  """Test cluster internal hardware failure recovery.
264

265
  """
266
  if qa_config.TestEnabled('instance-failover'):
267
    RunTest(qa_instance.TestInstanceFailover, instance)
268

    
269
  if qa_config.TestEnabled("instance-migrate"):
270
    RunTest(qa_instance.TestInstanceMigrate, instance)
271

    
272
    if qa_rapi.Enabled():
273
      RunTest(qa_rapi.TestRapiInstanceMigrate, instance)
274

    
275
  if qa_config.TestEnabled('instance-replace-disks'):
276
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
277
    try:
278
      RunTest(qa_instance.TestReplaceDisks,
279
              instance, pnode, snode, othernode)
280
    finally:
281
      qa_config.ReleaseNode(othernode)
282

    
283
  if qa_config.TestEnabled('node-evacuate'):
284
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
285

    
286
  if qa_config.TestEnabled('node-failover'):
287
    RunTest(qa_node.TestNodeFailover, pnode, snode)
288

    
289
  if qa_config.TestEnabled('instance-disk-failure'):
290
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
291
            instance, pnode, snode)
292
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
293
            instance, pnode, snode)
294

    
295

    
296
@rapi.client.UsesRapiClient
297
def main():
298
  """Main program.
299

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

    
307
  if len(args) == 1:
308
    (config_file, ) = args
309
  else:
310
    parser.error("Wrong number of arguments.")
311

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

    
318
  qa_config.Load(config_file)
319

    
320
  rapi_user = "ganeti-qa"
321
  rapi_secret = utils.GenerateSecret()
322

    
323
  RunEnvTests()
324
  SetupCluster(rapi_user, rapi_secret)
325

    
326
  # Load RAPI certificate
327
  qa_rapi.Setup(rapi_user, rapi_secret)
328

    
329
  RunClusterTests()
330
  RunOsTests()
331

    
332
  if qa_config.TestEnabled('tags'):
333
    RunTest(qa_tags.TestClusterTags)
334

    
335
  if qa_config.TestEnabled('node-readd'):
336
    master = qa_config.GetMasterNode()
337
    pnode = qa_config.AcquireNode(exclude=master)
338
    try:
339
      RunTest(qa_node.TestNodeReadd, pnode)
340
    finally:
341
      qa_config.ReleaseNode(pnode)
342

    
343
  pnode = qa_config.AcquireNode()
344
  try:
345
    if qa_config.TestEnabled('tags'):
346
      RunTest(qa_tags.TestNodeTags, pnode)
347

    
348
    if qa_rapi.Enabled():
349
      RunTest(qa_rapi.TestNode, pnode)
350

    
351
      if qa_config.TestEnabled("instance-add-plain-disk"):
352
        for use_client in [True, False]:
353
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
354
                                  use_client)
355
          RunCommonInstanceTests(rapi_instance)
356
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
357
          del rapi_instance
358

    
359
    if qa_config.TestEnabled('instance-add-plain-disk'):
360
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
361
      RunCommonInstanceTests(instance)
362
      RunExportImportTests(instance, pnode)
363
      RunDaemonTests(instance, pnode)
364
      RunTest(qa_instance.TestInstanceRemove, instance)
365
      del instance
366

    
367
    multinode_tests = [
368
      ('instance-add-drbd-disk',
369
       qa_instance.TestInstanceAddWithDrbdDisk),
370
    ]
371

    
372
    for name, func in multinode_tests:
373
      if qa_config.TestEnabled(name):
374
        snode = qa_config.AcquireNode(exclude=pnode)
375
        try:
376
          instance = RunTest(func, pnode, snode)
377
          RunCommonInstanceTests(instance)
378
          if qa_config.TestEnabled('instance-convert-disk'):
379
            RunTest(qa_instance.TestInstanceShutdown, instance)
380
            RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
381
            RunTest(qa_instance.TestInstanceStartup, instance)
382
          RunExportImportTests(instance, pnode)
383
          RunHardwareFailureTests(instance, pnode, snode)
384
          RunTest(qa_instance.TestInstanceRemove, instance)
385
          del instance
386
        finally:
387
          qa_config.ReleaseNode(snode)
388

    
389
    if (qa_config.TestEnabled('instance-add-plain-disk') and
390
        qa_config.TestEnabled("instance-export")):
391
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
392
      expnode = qa_config.AcquireNode(exclude=pnode)
393
      try:
394
        RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
395
        RunTest(qa_instance.TestBackupList, expnode)
396
      finally:
397
        qa_config.ReleaseNode(expnode)
398
      del expnode
399
      del instance
400

    
401
  finally:
402
    qa_config.ReleaseNode(pnode)
403

    
404
  if qa_config.TestEnabled('create-cluster'):
405
    RunTest(qa_node.TestNodeRemoveAll)
406

    
407
  if qa_config.TestEnabled('cluster-destroy'):
408
    RunTest(qa_cluster.TestClusterDestroy)
409

    
410

    
411
if __name__ == '__main__':
412
  main()