Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (8.6 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
  if qa_config.TestEnabled('node-info'):
81
    RunTest(qa_node.TestNodeInfo)
82

    
83

    
84
def RunClusterTests():
85
  """Runs tests related to gnt-cluster.
86

87
  """
88
  if qa_config.TestEnabled('cluster-verify'):
89
    RunTest(qa_cluster.TestClusterVerify)
90

    
91
  if qa_config.TestEnabled('cluster-rename'):
92
    RunTest(qa_cluster.TestClusterRename)
93

    
94
  if qa_config.TestEnabled('cluster-info'):
95
    RunTest(qa_cluster.TestClusterVersion)
96
    RunTest(qa_cluster.TestClusterInfo)
97
    RunTest(qa_cluster.TestClusterGetmaster)
98

    
99
  if qa_config.TestEnabled('cluster-copyfile'):
100
    RunTest(qa_cluster.TestClusterCopyfile)
101

    
102
  if qa_config.TestEnabled('cluster-command'):
103
    RunTest(qa_cluster.TestClusterCommand)
104

    
105
  if qa_config.TestEnabled('cluster-burnin'):
106
    RunTest(qa_cluster.TestClusterBurnin)
107

    
108
  if qa_config.TestEnabled('cluster-master-failover'):
109
    RunTest(qa_cluster.TestClusterMasterFailover)
110

    
111
  if qa_rapi.Enabled():
112
    RunTest(qa_rapi.TestVersion)
113
    RunTest(qa_rapi.TestEmptyCluster)
114

    
115
def RunOsTests():
116
  """Runs all tests related to gnt-os.
117

118
  """
119
  if not qa_config.TestEnabled('os'):
120
    return
121

    
122
  RunTest(qa_os.TestOsList)
123
  RunTest(qa_os.TestOsDiagnose)
124
  RunTest(qa_os.TestOsValid)
125
  RunTest(qa_os.TestOsInvalid)
126
  RunTest(qa_os.TestOsPartiallyValid)
127

    
128

    
129
def RunCommonInstanceTests(instance):
130
  """Runs a few tests that are common to all disk types.
131

132
  """
133
  if qa_config.TestEnabled('instance-shutdown'):
134
    RunTest(qa_instance.TestInstanceShutdown, instance)
135
    RunTest(qa_instance.TestInstanceStartup, instance)
136

    
137
  if qa_config.TestEnabled('instance-list'):
138
    RunTest(qa_instance.TestInstanceList)
139

    
140
  if qa_config.TestEnabled('instance-info'):
141
    RunTest(qa_instance.TestInstanceInfo, instance)
142

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

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

    
149
  if qa_config.TestEnabled('instance-reinstall'):
150
    RunTest(qa_instance.TestInstanceShutdown, instance)
151
    RunTest(qa_instance.TestInstanceReinstall, instance)
152
    RunTest(qa_instance.TestInstanceStartup, instance)
153

    
154
  if qa_config.TestEnabled('instance-reboot'):
155
    RunTest(qa_instance.TestInstanceReboot, instance)
156

    
157
  if qa_config.TestEnabled('tags'):
158
    RunTest(qa_tags.TestInstanceTags, instance)
159

    
160
  if qa_config.TestEnabled('node-volumes'):
161
    RunTest(qa_node.TestNodeVolumes)
162

    
163
  if qa_config.TestEnabled("node-storage"):
164
    RunTest(qa_node.TestNodeStorage)
165

    
166
  if qa_rapi.Enabled():
167
    RunTest(qa_rapi.TestInstance, instance)
168

    
169
def RunExportImportTests(instance, pnode):
170
  """Tries to export and import the instance.
171

172
  """
173
  if qa_config.TestEnabled('instance-export'):
174
    expnode = qa_config.AcquireNode(exclude=pnode)
175
    try:
176
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
177

    
178
      RunTest(qa_instance.TestBackupList, expnode)
179

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

    
191

    
192
def RunDaemonTests(instance, pnode):
193
  """Test the ganeti-watcher script.
194

195
  """
196
  automatic_restart = \
197
    qa_config.TestEnabled('instance-automatic-restart')
198
  consecutive_failures = \
199
    qa_config.TestEnabled('instance-consecutive-failures')
200

    
201
  if automatic_restart or consecutive_failures:
202
    qa_daemon.PrintCronWarning()
203

    
204
    if automatic_restart:
205
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
206

    
207
    if consecutive_failures:
208
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
209

    
210

    
211
def RunHardwareFailureTests(instance, pnode, snode):
212
  """Test cluster internal hardware failure recovery.
213

214
  """
215
  if qa_config.TestEnabled('instance-failover'):
216
    RunTest(qa_instance.TestInstanceFailover, instance)
217

    
218
  if qa_config.TestEnabled('instance-replace-disks'):
219
    othernode = qa_config.AcquireNode(exclude=[pnode, snode])
220
    try:
221
      RunTest(qa_instance.TestReplaceDisks,
222
              instance, pnode, snode, othernode)
223
    finally:
224
      qa_config.ReleaseNode(othernode)
225

    
226
  if qa_config.TestEnabled('node-evacuate'):
227
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
228

    
229
  if qa_config.TestEnabled('node-failover'):
230
    RunTest(qa_node.TestNodeFailover, pnode, snode)
231

    
232
  if qa_config.TestEnabled('instance-disk-failure'):
233
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
234
            instance, pnode, snode)
235
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
236
            instance, pnode, snode)
237

    
238

    
239
def main():
240
  """Main program.
241

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

    
249
  if len(args) == 1:
250
    (config_file, ) = args
251
  else:
252
    parser.error("Wrong number of arguments.")
253

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

    
260
  qa_config.Load(config_file)
261

    
262
  RunEnvTests()
263
  SetupCluster()
264
  RunClusterTests()
265
  RunOsTests()
266

    
267
  if qa_config.TestEnabled('tags'):
268
    RunTest(qa_tags.TestClusterTags)
269

    
270
  if qa_config.TestEnabled('node-readd'):
271
    master = qa_config.GetMasterNode()
272
    pnode = qa_config.AcquireNode(exclude=master)
273
    try:
274
      RunTest(qa_node.TestNodeReadd, pnode)
275
    finally:
276
      qa_config.ReleaseNode(pnode)
277

    
278
  pnode = qa_config.AcquireNode()
279
  try:
280
    if qa_config.TestEnabled('tags'):
281
      RunTest(qa_tags.TestNodeTags, pnode)
282

    
283
    if qa_rapi.Enabled():
284
      RunTest(qa_rapi.TestNode, pnode)
285

    
286
    if qa_config.TestEnabled('instance-add-plain-disk'):
287
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
288
      RunCommonInstanceTests(instance)
289
      RunExportImportTests(instance, pnode)
290
      RunDaemonTests(instance, pnode)
291
      RunTest(qa_instance.TestInstanceRemove, instance)
292
      del instance
293

    
294
    multinode_tests = [
295
      ('instance-add-drbd-disk',
296
       qa_instance.TestInstanceAddWithDrbdDisk),
297
    ]
298

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

    
312
  finally:
313
    qa_config.ReleaseNode(pnode)
314

    
315
  if qa_config.TestEnabled('create-cluster'):
316
    RunTest(qa_node.TestNodeRemoveAll)
317

    
318
  if qa_config.TestEnabled('cluster-destroy'):
319
    RunTest(qa_cluster.TestClusterDestroy)
320

    
321

    
322
if __name__ == '__main__':
323
  main()