Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 1672a0d1

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

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

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

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

    
125

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

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

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

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

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

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

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

    
151

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

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

    
161
      RunTest(qa_instance.TestBackupList, expnode)
162

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

    
174

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

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

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

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

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

    
193

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

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

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

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

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

    
213

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

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

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

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

    
239
  qa_config.Load(config_file)
240
  qa_utils.LoadHooks()
241

    
242
  RunTest(qa_other.UploadKnownHostsFile, known_hosts_file)
243

    
244
  RunEnvTests()
245
  SetupCluster()
246
  RunClusterTests()
247
  RunOsTests()
248

    
249
  if qa_config.TestEnabled('tags'):
250
    RunTest(qa_tags.TestClusterTags)
251

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

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

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

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

    
285
  finally:
286
    qa_config.ReleaseNode(pnode)
287

    
288
  RunTest(qa_node.TestNodeRemoveAll)
289

    
290
  if qa_config.TestEnabled('cluster-destroy'):
291
    RunTest(qa_cluster.TestClusterDestroy)
292

    
293

    
294
if __name__ == '__main__':
295
  main()