Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 452913ed

History | View | Annotate | Download (11.1 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
  else:
89
    # consider the nodes are already there
90
    qa_node.MarkNodeAddedAll()
91
  if qa_config.TestEnabled('node-info'):
92
    RunTest(qa_node.TestNodeInfo)
93

    
94

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

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

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

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

    
108
  if qa_config.TestEnabled('cluster-rename'):
109
    RunTest(qa_cluster.TestClusterRename)
110

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

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

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

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

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

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

    
132

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

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

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

    
148

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

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

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

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

    
163
  if qa_config.TestEnabled('instance-modify'):
164
    RunTest(qa_instance.TestInstanceModify, instance)
165

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

    
169
  if qa_config.TestEnabled('instance-reinstall'):
170
    RunTest(qa_instance.TestInstanceShutdown, instance)
171
    RunTest(qa_instance.TestInstanceReinstall, instance)
172
    RunTest(qa_instance.TestInstanceStartup, instance)
173

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

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

    
182
  if qa_config.TestEnabled('tags'):
183
    RunTest(qa_tags.TestInstanceTags, instance)
184

    
185
  if qa_config.TestEnabled('node-volumes'):
186
    RunTest(qa_node.TestNodeVolumes)
187

    
188
  if qa_config.TestEnabled("node-storage"):
189
    RunTest(qa_node.TestNodeStorage)
190

    
191
  if qa_rapi.Enabled():
192
    RunTest(qa_rapi.TestInstance, instance)
193

    
194

    
195
def RunExportImportTests(instance, pnode):
196
  """Tries to export and import the instance.
197

198
  """
199
  if qa_config.TestEnabled('instance-export'):
200
    expnode = qa_config.AcquireNode(exclude=pnode)
201
    try:
202
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
203

    
204
      RunTest(qa_instance.TestBackupList, expnode)
205

    
206
      if qa_config.TestEnabled('instance-import'):
207
        newinst = qa_config.AcquireInstance()
208
        try:
209
          RunTest(qa_instance.TestInstanceImport, pnode, newinst,
210
                  expnode, name)
211
          RunTest(qa_instance.TestInstanceRemove, newinst)
212
        finally:
213
          qa_config.ReleaseInstance(newinst)
214
    finally:
215
      qa_config.ReleaseNode(expnode)
216

    
217
  if (qa_rapi.Enabled() and
218
      qa_config.TestEnabled("inter-cluster-instance-move")):
219
    newinst = qa_config.AcquireInstance()
220
    try:
221
      pnode2 = qa_config.AcquireNode(exclude=pnode)
222
      try:
223
        RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
224
                pnode2, pnode)
225
      finally:
226
        qa_config.ReleaseNode(pnode2)
227
    finally:
228
      qa_config.ReleaseInstance(newinst)
229

    
230

    
231
def RunDaemonTests(instance, pnode):
232
  """Test the ganeti-watcher script.
233

234
  """
235
  automatic_restart = \
236
    qa_config.TestEnabled('instance-automatic-restart')
237
  consecutive_failures = \
238
    qa_config.TestEnabled('instance-consecutive-failures')
239

    
240
  if automatic_restart or consecutive_failures:
241
    qa_daemon.PrintCronWarning()
242

    
243
    if automatic_restart:
244
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
245

    
246
    if consecutive_failures:
247
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
248

    
249

    
250
def RunHardwareFailureTests(instance, pnode, snode):
251
  """Test cluster internal hardware failure recovery.
252

253
  """
254
  if qa_config.TestEnabled('instance-failover'):
255
    RunTest(qa_instance.TestInstanceFailover, instance)
256

    
257
  if qa_config.TestEnabled('instance-replace-disks'):
258
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
259
    try:
260
      RunTest(qa_instance.TestReplaceDisks,
261
              instance, pnode, snode, othernode)
262
    finally:
263
      qa_config.ReleaseNode(othernode)
264

    
265
  if qa_config.TestEnabled('node-evacuate'):
266
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
267

    
268
  if qa_config.TestEnabled('node-failover'):
269
    RunTest(qa_node.TestNodeFailover, pnode, snode)
270

    
271
  if qa_config.TestEnabled('instance-disk-failure'):
272
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
273
            instance, pnode, snode)
274
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
275
            instance, pnode, snode)
276

    
277

    
278
@rapi.client.UsesRapiClient
279
def main():
280
  """Main program.
281

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

    
289
  if len(args) == 1:
290
    (config_file, ) = args
291
  else:
292
    parser.error("Wrong number of arguments.")
293

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

    
300
  qa_config.Load(config_file)
301

    
302
  rapi_user = "ganeti-qa"
303
  rapi_secret = utils.GenerateSecret()
304

    
305
  RunEnvTests()
306
  SetupCluster(rapi_user, rapi_secret)
307

    
308
  # Load RAPI certificate
309
  qa_rapi.Setup(rapi_user, rapi_secret)
310

    
311
  RunClusterTests()
312
  RunOsTests()
313

    
314
  if qa_config.TestEnabled('tags'):
315
    RunTest(qa_tags.TestClusterTags)
316

    
317
  if qa_config.TestEnabled('node-readd'):
318
    master = qa_config.GetMasterNode()
319
    pnode = qa_config.AcquireNode(exclude=master)
320
    try:
321
      RunTest(qa_node.TestNodeReadd, pnode)
322
    finally:
323
      qa_config.ReleaseNode(pnode)
324

    
325
  pnode = qa_config.AcquireNode()
326
  try:
327
    if qa_config.TestEnabled('tags'):
328
      RunTest(qa_tags.TestNodeTags, pnode)
329

    
330
    if qa_rapi.Enabled():
331
      RunTest(qa_rapi.TestNode, pnode)
332

    
333
      if qa_config.TestEnabled("instance-add-plain-disk"):
334
        for use_client in [True, False]:
335
          rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
336
                                  use_client)
337
          RunCommonInstanceTests(rapi_instance)
338
          RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
339
          del rapi_instance
340

    
341
    if qa_config.TestEnabled('instance-add-plain-disk'):
342
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
343
      RunCommonInstanceTests(instance)
344
      RunExportImportTests(instance, pnode)
345
      RunDaemonTests(instance, pnode)
346
      RunTest(qa_instance.TestInstanceRemove, instance)
347
      del instance
348

    
349
    multinode_tests = [
350
      ('instance-add-drbd-disk',
351
       qa_instance.TestInstanceAddWithDrbdDisk),
352
    ]
353

    
354
    for name, func in multinode_tests:
355
      if qa_config.TestEnabled(name):
356
        snode = qa_config.AcquireNode(exclude=pnode)
357
        try:
358
          instance = RunTest(func, pnode, snode)
359
          RunCommonInstanceTests(instance)
360
          if qa_config.TestEnabled('instance-convert-disk'):
361
            RunTest(qa_instance.TestInstanceShutdown, instance)
362
            RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
363
            RunTest(qa_instance.TestInstanceStartup, instance)
364
          RunExportImportTests(instance, pnode)
365
          RunHardwareFailureTests(instance, pnode, snode)
366
          RunTest(qa_instance.TestInstanceRemove, instance)
367
          del instance
368
        finally:
369
          qa_config.ReleaseNode(snode)
370

    
371
    if (qa_config.TestEnabled('instance-add-plain-disk') and
372
        qa_config.TestEnabled("instance-export")):
373
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
374
      expnode = qa_config.AcquireNode(exclude=pnode)
375
      try:
376
        RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
377
        RunTest(qa_instance.TestBackupList, expnode)
378
      finally:
379
        qa_config.ReleaseNode(expnode)
380
      del expnode
381
      del instance
382

    
383
  finally:
384
    qa_config.ReleaseNode(pnode)
385

    
386
  if qa_config.TestEnabled('create-cluster'):
387
    RunTest(qa_node.TestNodeRemoveAll)
388

    
389
  if qa_config.TestEnabled('cluster-destroy'):
390
    RunTest(qa_cluster.TestClusterDestroy)
391

    
392

    
393
if __name__ == '__main__':
394
  main()