Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ d74c2ca1

History | View | Annotate | Download (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
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
from datetime import datetime
32
from optparse import OptionParser
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

    
44

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

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

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

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

    
61
  return fn(*args)
62

    
63

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

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

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

    
75

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

79
  """
80
  RunTest(qa_cluster.TestClusterInit)
81
  RunTest(qa_node.TestNodeAddAll)
82
  if qa_config.TestEnabled('node-info'):
83
    RunTest(qa_node.TestNodeInfo)
84

    
85

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

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

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

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

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

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

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

    
110

    
111
def RunOsTests():
112
  """Runs all tests related to gnt-os.
113

114
  """
115
  if not qa_config.TestEnabled('os'):
116
    return
117

    
118
  RunTest(qa_os.TestOsList)
119
  RunTest(qa_os.TestOsDiagnose)
120
  RunTest(qa_os.TestOsValid)
121
  RunTest(qa_os.TestOsInvalid)
122
  RunTest(qa_os.TestOsPartiallyValid)
123

    
124

    
125
def RunCommonInstanceTests(instance):
126
  """Runs a few tests that are common to all disk types.
127

128
  """
129
  if qa_config.TestEnabled('instance-shutdown'):
130
    RunTest(qa_instance.TestInstanceShutdown, instance)
131
    RunTest(qa_instance.TestInstanceStartup, instance)
132

    
133
  if qa_config.TestEnabled('instance-list'):
134
    RunTest(qa_instance.TestInstanceList)
135

    
136
  if qa_config.TestEnabled('instance-info'):
137
    RunTest(qa_instance.TestInstanceInfo, instance)
138

    
139
  if qa_config.TestEnabled('instance-reinstall'):
140
    RunTest(qa_instance.TestInstanceShutdown, instance)
141
    RunTest(qa_instance.TestInstanceReinstall, instance)
142
    RunTest(qa_instance.TestInstanceStartup, instance)
143

    
144
  if qa_config.TestEnabled('tags'):
145
    RunTest(qa_tags.TestInstanceTags, instance)
146

    
147
  if qa_config.TestEnabled('node-volumes'):
148
    RunTest(qa_node.TestNodeVolumes)
149

    
150

    
151
def RunExportImportTests(instance, pnode):
152
  """Tries to export and import the instance.
153

154
  """
155
  if qa_config.TestEnabled('instance-export'):
156
    expnode = qa_config.AcquireNode(exclude=pnode)
157
    try:
158
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
159

    
160
      RunTest(qa_instance.TestBackupList, expnode)
161

    
162
      if qa_config.TestEnabled('instance-import'):
163
        newinst = qa_config.AcquireInstance()
164
        try:
165
          RunTest(qa_instance.TestInstanceImport, pnode, newinst,
166
                  expnode, name)
167
          RunTest(qa_instance.TestInstanceRemove, newinst)
168
        finally:
169
          qa_config.ReleaseInstance(newinst)
170
    finally:
171
      qa_config.ReleaseNode(expnode)
172

    
173

    
174
def RunDaemonTests(instance, pnode):
175
  """Test the ganeti-watcher script.
176

177
  """
178
  automatic_restart = \
179
    qa_config.TestEnabled('instance-automatic-restart')
180
  consecutive_failures = \
181
    qa_config.TestEnabled('instance-consecutive-failures')
182

    
183
  if automatic_restart or consecutive_failures:
184
    qa_daemon.PrintCronWarning()
185

    
186
    if automatic_restart:
187
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
188

    
189
    if consecutive_failures:
190
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
191

    
192

    
193
def RunHardwareFailureTests(instance, pnode, snode):
194
  """Test cluster internal hardware failure recovery.
195

196
  """
197
  if qa_config.TestEnabled('instance-failover'):
198
    RunTest(qa_instance.TestInstanceFailover, instance)
199

    
200
  if qa_config.TestEnabled('node-evacuate'):
201
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
202

    
203
  if qa_config.TestEnabled('node-failover'):
204
    RunTest(qa_node.TestNodeFailover, pnode, snode)
205

    
206
  if qa_config.TestEnabled('instance-disk-failure'):
207
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
208
            instance, pnode, snode)
209
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
210
            instance, pnode, snode)
211

    
212

    
213
def main():
214
  """Main program.
215

216
  """
217
  parser = OptionParser(usage="%prog [options] <config-file> "
218
                              "<known-hosts-file>")
219
  parser.add_option('--dry-run', dest='dry_run',
220
      action="store_true",
221
      help="Show what would be done")
222
  parser.add_option('--yes-do-it', dest='yes_do_it',
223
      action="store_true",
224
      help="Really execute the tests")
225
  (qa_config.options, args) = parser.parse_args()
226

    
227
  if len(args) == 2:
228
    (config_file, known_hosts_file) = args
229
  else:
230
    parser.error("Not enough arguments.")
231

    
232
  if not qa_config.options.yes_do_it:
233
    print ("Executing this script irreversibly destroys any Ganeti\n"
234
           "configuration on all nodes involved. If you really want\n"
235
           "to start testing, supply the --yes-do-it option.")
236
    sys.exit(1)
237

    
238
  qa_config.Load(config_file)
239

    
240
  RunTest(qa_other.UploadKnownHostsFile, known_hosts_file)
241

    
242
  RunEnvTests()
243
  SetupCluster()
244
  RunClusterTests()
245
  RunOsTests()
246

    
247
  if qa_config.TestEnabled('tags'):
248
    RunTest(qa_tags.TestClusterTags)
249

    
250
  pnode = qa_config.AcquireNode()
251
  try:
252
    if qa_config.TestEnabled('tags'):
253
      RunTest(qa_tags.TestNodeTags, pnode)
254

    
255
    if qa_config.TestEnabled('instance-add-plain-disk'):
256
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
257
      RunCommonInstanceTests(instance)
258
      RunExportImportTests(instance, pnode)
259
      RunDaemonTests(instance, pnode)
260
      RunTest(qa_instance.TestInstanceRemove, instance)
261
      del instance
262

    
263
    if qa_config.TestEnabled('instance-add-local-mirror-disk'):
264
      instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, pnode)
265
      RunCommonInstanceTests(instance)
266
      RunExportImportTests(instance, pnode)
267
      RunTest(qa_instance.TestInstanceRemove, instance)
268
      del instance
269

    
270
    if qa_config.TestEnabled('instance-add-remote-raid-disk'):
271
      snode = qa_config.AcquireNode(exclude=pnode)
272
      try:
273
        instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk,
274
                           pnode, snode)
275
        RunCommonInstanceTests(instance)
276
        RunExportImportTests(instance, pnode)
277
        RunHardwareFailureTests(instance, pnode, snode)
278
        RunTest(qa_instance.TestInstanceRemove, instance)
279
        del instance
280
      finally:
281
        qa_config.ReleaseNode(snode)
282

    
283
  finally:
284
    qa_config.ReleaseNode(pnode)
285

    
286
  RunTest(qa_node.TestNodeRemoveAll)
287

    
288
  if qa_config.TestEnabled('cluster-destroy'):
289
    RunTest(qa_cluster.TestClusterDestroy)
290

    
291

    
292
if __name__ == '__main__':
293
  main()