Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 8d8d650c

History | View | Annotate | Download (9.2 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

    
42
def RunTest(fn, *args):
43
  """Runs a test after printing a header.
44

45
  """
46
  if fn.__doc__:
47
    desc = fn.__doc__.splitlines()[0].strip()
48
  else:
49
    desc = '%r' % fn
50

    
51
  now = str(datetime.datetime.now())
52

    
53
  print
54
  print '---', now, ('-' * (55 - len(now)))
55
  print desc
56
  print '-' * 60
57

    
58
  return fn(*args)
59

    
60

    
61
def RunEnvTests():
62
  """Run several environment tests.
63

64
  """
65
  if not qa_config.TestEnabled('env'):
66
    return
67

    
68
  RunTest(qa_env.TestSshConnection)
69
  RunTest(qa_env.TestIcmpPing)
70
  RunTest(qa_env.TestGanetiCommands)
71

    
72

    
73
def SetupCluster():
74
  """Initializes the cluster.
75

76
  """
77
  if qa_config.TestEnabled('create-cluster'):
78
    RunTest(qa_cluster.TestClusterInit)
79
    RunTest(qa_node.TestNodeAddAll)
80
  else:
81
    # consider the nodes are already there
82
    qa_node.MarkNodeAddedAll()
83
  if qa_config.TestEnabled('node-info'):
84
    RunTest(qa_node.TestNodeInfo)
85

    
86

    
87
def RunClusterTests():
88
  """Runs tests related to gnt-cluster.
89

90
  """
91
  if qa_config.TestEnabled('cluster-verify'):
92
    RunTest(qa_cluster.TestClusterVerify)
93

    
94
  if qa_config.TestEnabled('cluster-rename'):
95
    RunTest(qa_cluster.TestClusterRename)
96

    
97
  if qa_config.TestEnabled('cluster-info'):
98
    RunTest(qa_cluster.TestClusterVersion)
99
    RunTest(qa_cluster.TestClusterInfo)
100
    RunTest(qa_cluster.TestClusterGetmaster)
101

    
102
  if qa_config.TestEnabled('cluster-copyfile'):
103
    RunTest(qa_cluster.TestClusterCopyfile)
104

    
105
  if qa_config.TestEnabled('cluster-command'):
106
    RunTest(qa_cluster.TestClusterCommand)
107

    
108
  if qa_config.TestEnabled('cluster-burnin'):
109
    RunTest(qa_cluster.TestClusterBurnin)
110

    
111
  if qa_config.TestEnabled('cluster-master-failover'):
112
    RunTest(qa_cluster.TestClusterMasterFailover)
113

    
114
  if qa_rapi.Enabled():
115
    RunTest(qa_rapi.TestVersion)
116
    RunTest(qa_rapi.TestEmptyCluster)
117

    
118
def RunOsTests():
119
  """Runs all tests related to gnt-os.
120

121
  """
122
  if not qa_config.TestEnabled('os'):
123
    return
124

    
125
  RunTest(qa_os.TestOsList)
126
  RunTest(qa_os.TestOsDiagnose)
127
  RunTest(qa_os.TestOsValid)
128
  RunTest(qa_os.TestOsInvalid)
129
  RunTest(qa_os.TestOsPartiallyValid)
130

    
131

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

135
  """
136
  if qa_config.TestEnabled('instance-shutdown'):
137
    RunTest(qa_instance.TestInstanceShutdown, instance)
138
    RunTest(qa_instance.TestInstanceStartup, instance)
139

    
140
  if qa_config.TestEnabled('instance-list'):
141
    RunTest(qa_instance.TestInstanceList)
142

    
143
  if qa_config.TestEnabled('instance-info'):
144
    RunTest(qa_instance.TestInstanceInfo, instance)
145

    
146
  if qa_config.TestEnabled('instance-modify'):
147
    RunTest(qa_instance.TestInstanceModify, instance)
148

    
149
  if qa_config.TestEnabled('instance-console'):
150
    RunTest(qa_instance.TestInstanceConsole, instance)
151

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

    
157
  if qa_config.TestEnabled('instance-reboot'):
158
    RunTest(qa_instance.TestInstanceReboot, instance)
159

    
160
  if qa_config.TestEnabled('tags'):
161
    RunTest(qa_tags.TestInstanceTags, instance)
162

    
163
  if qa_config.TestEnabled('node-volumes'):
164
    RunTest(qa_node.TestNodeVolumes)
165

    
166
  if qa_config.TestEnabled("node-storage"):
167
    RunTest(qa_node.TestNodeStorage)
168

    
169
  if qa_rapi.Enabled():
170
    RunTest(qa_rapi.TestInstance, instance)
171

    
172

    
173
def RunExportImportTests(instance, pnode):
174
  """Tries to export and import the instance.
175

176
  """
177
  if qa_config.TestEnabled('instance-export'):
178
    expnode = qa_config.AcquireNode(exclude=pnode)
179
    try:
180
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
181

    
182
      RunTest(qa_instance.TestBackupList, expnode)
183

    
184
      if qa_config.TestEnabled('instance-import'):
185
        newinst = qa_config.AcquireInstance()
186
        try:
187
          RunTest(qa_instance.TestInstanceImport, pnode, newinst,
188
                  expnode, name)
189
          RunTest(qa_instance.TestInstanceRemove, newinst)
190
        finally:
191
          qa_config.ReleaseInstance(newinst)
192
    finally:
193
      qa_config.ReleaseNode(expnode)
194

    
195

    
196
def RunDaemonTests(instance, pnode):
197
  """Test the ganeti-watcher script.
198

199
  """
200
  automatic_restart = \
201
    qa_config.TestEnabled('instance-automatic-restart')
202
  consecutive_failures = \
203
    qa_config.TestEnabled('instance-consecutive-failures')
204

    
205
  if automatic_restart or consecutive_failures:
206
    qa_daemon.PrintCronWarning()
207

    
208
    if automatic_restart:
209
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
210

    
211
    if consecutive_failures:
212
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
213

    
214

    
215
def RunHardwareFailureTests(instance, pnode, snode):
216
  """Test cluster internal hardware failure recovery.
217

218
  """
219
  if qa_config.TestEnabled('instance-failover'):
220
    RunTest(qa_instance.TestInstanceFailover, instance)
221

    
222
  if qa_config.TestEnabled('instance-replace-disks'):
223
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
224
    try:
225
      RunTest(qa_instance.TestReplaceDisks,
226
              instance, pnode, snode, othernode)
227
    finally:
228
      qa_config.ReleaseNode(othernode)
229

    
230
  if qa_config.TestEnabled('node-evacuate'):
231
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
232

    
233
  if qa_config.TestEnabled('node-failover'):
234
    RunTest(qa_node.TestNodeFailover, pnode, snode)
235

    
236
  if qa_config.TestEnabled('instance-disk-failure'):
237
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
238
            instance, pnode, snode)
239
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
240
            instance, pnode, snode)
241

    
242

    
243
def main():
244
  """Main program.
245

246
  """
247
  parser = optparse.OptionParser(usage="%prog [options] <config-file>")
248
  parser.add_option('--yes-do-it', dest='yes_do_it',
249
      action="store_true",
250
      help="Really execute the tests")
251
  (qa_config.options, args) = parser.parse_args()
252

    
253
  if len(args) == 1:
254
    (config_file, ) = args
255
  else:
256
    parser.error("Wrong number of arguments.")
257

    
258
  if not qa_config.options.yes_do_it:
259
    print ("Executing this script irreversibly destroys any Ganeti\n"
260
           "configuration on all nodes involved. If you really want\n"
261
           "to start testing, supply the --yes-do-it option.")
262
    sys.exit(1)
263

    
264
  qa_config.Load(config_file)
265

    
266
  RunEnvTests()
267
  SetupCluster()
268
  RunClusterTests()
269
  RunOsTests()
270

    
271
  if qa_config.TestEnabled('tags'):
272
    RunTest(qa_tags.TestClusterTags)
273

    
274
  if qa_config.TestEnabled('node-readd'):
275
    master = qa_config.GetMasterNode()
276
    pnode = qa_config.AcquireNode(exclude=master)
277
    try:
278
      RunTest(qa_node.TestNodeReadd, pnode)
279
    finally:
280
      qa_config.ReleaseNode(pnode)
281

    
282
  pnode = qa_config.AcquireNode()
283
  try:
284
    if qa_config.TestEnabled('tags'):
285
      RunTest(qa_tags.TestNodeTags, pnode)
286

    
287
    if qa_rapi.Enabled():
288
      RunTest(qa_rapi.TestNode, pnode)
289

    
290
    if qa_config.TestEnabled('instance-add-plain-disk'):
291
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
292
      RunCommonInstanceTests(instance)
293
      RunExportImportTests(instance, pnode)
294
      RunDaemonTests(instance, pnode)
295
      RunTest(qa_instance.TestInstanceRemove, instance)
296
      del instance
297

    
298
    multinode_tests = [
299
      ('instance-add-drbd-disk',
300
       qa_instance.TestInstanceAddWithDrbdDisk),
301
    ]
302

    
303
    for name, func in multinode_tests:
304
      if qa_config.TestEnabled(name):
305
        snode = qa_config.AcquireNode(exclude=pnode)
306
        try:
307
          instance = RunTest(func, pnode, snode)
308
          RunCommonInstanceTests(instance)
309
          RunExportImportTests(instance, pnode)
310
          RunHardwareFailureTests(instance, pnode, snode)
311
          RunTest(qa_instance.TestInstanceRemove, instance)
312
          del instance
313
        finally:
314
          qa_config.ReleaseNode(snode)
315

    
316
    if (qa_config.TestEnabled('instance-add-plain-disk') and
317
        qa_config.TestEnabled("instance-export")):
318
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
319
      expnode = qa_config.AcquireNode(exclude=pnode)
320
      try:
321
        RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
322
        RunTest(qa_instance.TestBackupList, expnode)
323
      finally:
324
        qa_config.ReleaseNode(expnode)
325
      del expnode
326
      del instance
327

    
328
  finally:
329
    qa_config.ReleaseNode(pnode)
330

    
331
  if qa_config.TestEnabled('create-cluster'):
332
    RunTest(qa_node.TestNodeRemoveAll)
333

    
334
  if qa_config.TestEnabled('cluster-destroy'):
335
    RunTest(qa_cluster.TestClusterDestroy)
336

    
337

    
338
if __name__ == '__main__':
339
  main()