Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 62843684

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

    
43

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

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

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

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

    
60
  return fn(*args)
61

    
62

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

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

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

    
74

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

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

    
84

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

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

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

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

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

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

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

    
109

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

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

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

    
123

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

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

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

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

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

    
143
  if qa_config.TestEnabled('node-volumes'):
144
    RunTest(qa_node.TestNodeVolumes)
145

    
146

    
147
def RunExportImportTests(instance, pnode):
148
  """Tries to export and import the instance.
149

150
  """
151
  if qa_config.TestEnabled('instance-export'):
152
    expnode = qa_config.AcquireNode(exclude=pnode)
153
    try:
154
      name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
155

    
156
      RunTest(qa_instance.TestBackupList, expnode)
157

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

    
169

    
170
def RunDaemonTests(instance, pnode):
171
  """Test the ganeti-watcher script.
172

173
  """
174
  automatic_restart = \
175
    qa_config.TestEnabled('instance-automatic-restart')
176
  consecutive_failures = \
177
    qa_config.TestEnabled('instance-consecutive-failures')
178

    
179
  if automatic_restart or consecutive_failures:
180
    qa_daemon.PrintCronWarning()
181

    
182
    if automatic_restart:
183
      RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
184

    
185
    if consecutive_failures:
186
      RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
187

    
188

    
189
def RunHardwareFailureTests(instance, pnode, snode):
190
  """Test cluster internal hardware failure recovery.
191

192
  """
193
  if qa_config.TestEnabled('instance-failover'):
194
    RunTest(qa_instance.TestInstanceFailover, instance)
195

    
196
  if qa_config.TestEnabled('node-evacuate'):
197
    RunTest(qa_node.TestNodeEvacuate, pnode, snode)
198

    
199
  if qa_config.TestEnabled('node-failover'):
200
    RunTest(qa_node.TestNodeFailover, pnode, snode)
201

    
202
  if qa_config.TestEnabled('instance-disk-failure'):
203
    RunTest(qa_instance.TestInstanceMasterDiskFailure,
204
            instance, pnode, snode)
205
    RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
206
            instance, pnode, snode)
207

    
208

    
209
def main():
210
  """Main program.
211

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

    
223
  if len(args) == 2:
224
    (config_file, known_hosts_file) = args
225
  else:
226
    parser.error("Not enough arguments.")
227

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

    
234
  qa_config.Load(config_file)
235

    
236
  RunTest(qa_other.UploadKnownHostsFile, known_hosts_file)
237

    
238
  RunEnvTests()
239
  SetupCluster()
240
  RunClusterTests()
241
  RunOsTests()
242

    
243
  pnode = qa_config.AcquireNode()
244
  try:
245
    if qa_config.TestEnabled('instance-add-plain-disk'):
246
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
247
      RunCommonInstanceTests(instance)
248
      RunExportImportTests(instance, pnode)
249
      RunDaemonTests(instance, pnode)
250
      RunTest(qa_instance.TestInstanceRemove, instance)
251
      del instance
252

    
253
    if qa_config.TestEnabled('instance-add-local-mirror-disk'):
254
      instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, pnode)
255
      RunCommonInstanceTests(instance)
256
      RunExportImportTests(instance, pnode)
257
      RunTest(qa_instance.TestInstanceRemove, instance)
258
      del instance
259

    
260
    if qa_config.TestEnabled('instance-add-remote-raid-disk'):
261
      snode = qa_config.AcquireNode(exclude=pnode)
262
      try:
263
        instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk,
264
                           pnode, snode)
265
        RunCommonInstanceTests(instance)
266
        RunExportImportTests(instance, pnode)
267
        RunHardwareFailureTests(instance, pnode, snode)
268
        RunTest(qa_instance.TestInstanceRemove, instance)
269
        del instance
270
      finally:
271
        qa_config.ReleaseNode(snode)
272

    
273
  finally:
274
    qa_config.ReleaseNode(pnode)
275

    
276
  RunTest(qa_node.TestNodeRemoveAll)
277

    
278
  if qa_config.TestEnabled('cluster-destroy'):
279
    RunTest(qa_cluster.TestClusterDestroy)
280

    
281

    
282
if __name__ == '__main__':
283
  main()