Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 102b115b

History | View | Annotate | Download (8.4 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
You can create the required known_hosts file using ssh-keyscan. It's mandatory
25
to use the full name of a node (FQDN). For security reasons, verify the keys
26
before using them.
27
Example: ssh-keyscan -t rsa node{1,2,3,4}.example.com > known_hosts
28
"""
29

    
30
import sys
31
import datetime
32
import optparse
33

    
34
import qa_cluster
35
import qa_config
36
import qa_daemon
37
import qa_env
38
import qa_instance
39
import qa_node
40
import qa_os
41
import qa_other
42
import qa_tags
43
import qa_utils
44

    
45

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

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

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

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

    
62
  return fn(*args)
63

    
64

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

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

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

    
76

    
77
def SetupCluster():
78
  """Initializes the cluster.
79

80
  """
81
  RunTest(qa_cluster.TestClusterInit)
82
  RunTest(qa_node.TestNodeAddAll)
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

    
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('tags'):
155
    RunTest(qa_tags.TestInstanceTags, instance)
156

    
157
  if qa_config.TestEnabled('node-volumes'):
158
    RunTest(qa_node.TestNodeVolumes)
159

    
160

    
161
def RunExportImportTests(instance, pnode):
162
  """Tries to export and import the instance.
163

164
  """
165
  if qa_config.TestEnabled('instance-export'):
166
    expnode = qa_config.AcquireNode(exclude=pnode)
167
    try:
168
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
169

    
170
      RunTest(qa_instance.TestBackupList, expnode)
171

    
172
      if qa_config.TestEnabled('instance-import'):
173
        newinst = qa_config.AcquireInstance()
174
        try:
175
          RunTest(qa_instance.TestInstanceImport, pnode, newinst,
176
                  expnode, name)
177
          RunTest(qa_instance.TestInstanceRemove, newinst)
178
        finally:
179
          qa_config.ReleaseInstance(newinst)
180
    finally:
181
      qa_config.ReleaseNode(expnode)
182

    
183

    
184
def RunDaemonTests(instance, pnode):
185
  """Test the ganeti-watcher script.
186

187
  """
188
  automatic_restart = \
189
    qa_config.TestEnabled('instance-automatic-restart')
190
  consecutive_failures = \
191
    qa_config.TestEnabled('instance-consecutive-failures')
192

    
193
  if automatic_restart or consecutive_failures:
194
    qa_daemon.PrintCronWarning()
195

    
196
    if automatic_restart:
197
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
198

    
199
    if consecutive_failures:
200
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
201

    
202

    
203
def RunHardwareFailureTests(instance, pnode, snode):
204
  """Test cluster internal hardware failure recovery.
205

206
  """
207
  if qa_config.TestEnabled('instance-failover'):
208
    RunTest(qa_instance.TestInstanceFailover, instance)
209

    
210
  if qa_config.TestEnabled('node-evacuate'):
211
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
212

    
213
  if qa_config.TestEnabled('node-failover'):
214
    RunTest(qa_node.TestNodeFailover, pnode, snode)
215

    
216
  if qa_config.TestEnabled('instance-disk-failure'):
217
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
218
            instance, pnode, snode)
219
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
220
            instance, pnode, snode)
221

    
222

    
223
def main():
224
  """Main program.
225

226
  """
227
  parser = optparse.OptionParser(usage="%prog [options] <config-file>"
228
                                       " <known-hosts-file>")
229
  parser.add_option('--dry-run', dest='dry_run',
230
      action="store_true",
231
      help="Show what would be done")
232
  parser.add_option('--yes-do-it', dest='yes_do_it',
233
      action="store_true",
234
      help="Really execute the tests")
235
  (qa_config.options, args) = parser.parse_args()
236

    
237
  if len(args) == 2:
238
    (config_file, known_hosts_file) = args
239
  else:
240
    parser.error("Not enough arguments.")
241

    
242
  if not qa_config.options.yes_do_it:
243
    print ("Executing this script irreversibly destroys any Ganeti\n"
244
           "configuration on all nodes involved. If you really want\n"
245
           "to start testing, supply the --yes-do-it option.")
246
    sys.exit(1)
247

    
248
  qa_config.Load(config_file)
249
  qa_utils.LoadHooks()
250

    
251
  RunTest(qa_other.UploadKnownHostsFile, known_hosts_file)
252

    
253
  RunEnvTests()
254
  SetupCluster()
255
  RunClusterTests()
256
  RunOsTests()
257

    
258
  if qa_config.TestEnabled('tags'):
259
    RunTest(qa_tags.TestClusterTags)
260

    
261
  if qa_config.TestEnabled('node-readd'):
262
    master = qa_config.GetMasterNode()
263
    pnode = qa_config.AcquireNode(exclude=master)
264
    try:
265
      RunTest(qa_node.TestNodeReadd, pnode)
266
    finally:
267
      qa_config.ReleaseNode(pnode)
268

    
269
  pnode = qa_config.AcquireNode()
270
  try:
271
    if qa_config.TestEnabled('tags'):
272
      RunTest(qa_tags.TestNodeTags, pnode)
273

    
274
    if qa_config.TestEnabled('instance-add-plain-disk'):
275
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
276
      RunCommonInstanceTests(instance)
277
      RunExportImportTests(instance, pnode)
278
      RunDaemonTests(instance, pnode)
279
      RunTest(qa_instance.TestInstanceRemove, instance)
280
      del instance
281

    
282
    multinode_tests = [
283
      ('instance-add-drbd-disk',
284
       qa_instance.TestInstanceAddWithDrbdDisk),
285
    ]
286

    
287
    for name, func in multinode_tests:
288
      if qa_config.TestEnabled(name):
289
        snode = qa_config.AcquireNode(exclude=pnode)
290
        try:
291
          instance = RunTest(func, pnode, snode)
292
          RunCommonInstanceTests(instance)
293
          RunExportImportTests(instance, pnode)
294
          RunHardwareFailureTests(instance, pnode, snode)
295
          RunTest(qa_instance.TestInstanceRemove, instance)
296
          del instance
297
        finally:
298
          qa_config.ReleaseNode(snode)
299

    
300
  finally:
301
    qa_config.ReleaseNode(pnode)
302

    
303
  RunTest(qa_node.TestNodeRemoveAll)
304

    
305
  if qa_config.TestEnabled('cluster-destroy'):
306
    RunTest(qa_cluster.TestClusterDestroy)
307

    
308

    
309
if __name__ == '__main__':
310
  main()