Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ e8ae0c20

History | View | Annotate | Download (7.7 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 main():
64
  """Main program.
65

66
  """
67
  parser = OptionParser(usage="%prog [options] <config-file> "
68
                              "<known-hosts-file>")
69
  parser.add_option('--dry-run', dest='dry_run',
70
      action="store_true",
71
      help="Show what would be done")
72
  parser.add_option('--yes-do-it', dest='yes_do_it',
73
      action="store_true",
74
      help="Really execute the tests")
75
  (qa_config.options, args) = parser.parse_args()
76

    
77
  if len(args) == 2:
78
    (config_file, known_hosts_file) = args
79
  else:
80
    parser.error("Not enough arguments.")
81

    
82
  if not qa_config.options.yes_do_it:
83
    print ("Executing this script irreversibly destroys any Ganeti\n"
84
           "configuration on all nodes involved. If you really want\n"
85
           "to start testing, supply the --yes-do-it option.")
86
    sys.exit(1)
87

    
88
  qa_config.Load(config_file)
89

    
90
  RunTest(qa_other.TestUploadKnownHostsFile, known_hosts_file)
91

    
92
  if qa_config.TestEnabled('env'):
93
    RunTest(qa_env.TestSshConnection)
94
    RunTest(qa_env.TestIcmpPing)
95
    RunTest(qa_env.TestGanetiCommands)
96

    
97
  RunTest(qa_cluster.TestClusterInit)
98

    
99
  RunTest(qa_node.TestNodeAddAll)
100

    
101
  if qa_config.TestEnabled('cluster-verify'):
102
    RunTest(qa_cluster.TestClusterVerify)
103

    
104
  if qa_config.TestEnabled('cluster-info'):
105
    RunTest(qa_cluster.TestClusterInfo)
106

    
107
  if qa_config.TestEnabled('cluster-getmaster'):
108
    RunTest(qa_cluster.TestClusterGetmaster)
109

    
110
  if qa_config.TestEnabled('cluster-version'):
111
    RunTest(qa_cluster.TestClusterVersion)
112

    
113
  if qa_config.TestEnabled('cluster-copyfile'):
114
    RunTest(qa_cluster.TestClusterCopyfile)
115

    
116
  if qa_config.TestEnabled('node-info'):
117
    RunTest(qa_node.TestNodeInfo)
118

    
119
  if qa_config.TestEnabled('cluster-burnin'):
120
    RunTest(qa_cluster.TestClusterBurnin)
121

    
122
  if qa_config.TestEnabled('cluster-master-failover'):
123
    RunTest(qa_cluster.TestClusterMasterFailover)
124

    
125
  if qa_config.TestEnabled('os'):
126
    RunTest(qa_os.TestOsList)
127
    RunTest(qa_os.TestOsDiagnose)
128
    RunTest(qa_os.TestOsValid)
129
    RunTest(qa_os.TestOsInvalid)
130
    RunTest(qa_os.TestOsPartiallyValid)
131

    
132
  node = qa_config.AcquireNode()
133
  try:
134
    if qa_config.TestEnabled('instance-add-plain-disk'):
135
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, node)
136

    
137
      if qa_config.TestEnabled('instance-shutdown'):
138
        RunTest(qa_instance.TestInstanceShutdown, instance)
139
        RunTest(qa_instance.TestInstanceStartup, instance)
140

    
141
      if qa_config.TestEnabled('instance-list'):
142
        RunTest(qa_instance.TestInstanceList)
143

    
144
      if qa_config.TestEnabled('instance-info'):
145
        RunTest(qa_instance.TestInstanceInfo, instance)
146

    
147
      automatic_restart = \
148
        qa_config.TestEnabled('instance-automatic-restart')
149
      consecutive_failures = \
150
        qa_config.TestEnabled('instance-consecutive-failures')
151

    
152
      if automatic_restart or consecutive_failures:
153
        qa_daemon.PrintCronWarning()
154

    
155
        if automatic_restart:
156
          RunTest(qa_daemon.TestInstanceAutomaticRestart, node, instance)
157

    
158
        if consecutive_failures:
159
          RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
160

    
161
      if qa_config.TestEnabled('instance-export'):
162
        expnode = qa_config.AcquireNode(exclude=node)
163
        try:
164
          name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
165

    
166
          RunTest(qa_instance.TestBackupList, expnode)
167

    
168
          if qa_config.TestEnabled('instance-import'):
169
            newinst = qa_config.AcquireInstance()
170
            try:
171
              RunTest(qa_instance.TestInstanceImport, node, newinst,
172
                      expnode, name)
173
              RunTest(qa_instance.TestInstanceRemove, newinst)
174
            finally:
175
              qa_config.ReleaseInstance(newinst)
176
        finally:
177
          qa_config.ReleaseNode(expnode)
178

    
179
      if qa_config.TestEnabled('instance-reinstall'):
180
        RunTest(qa_instance.TestInstanceShutdown, instance)
181
        RunTest(qa_instance.TestInstanceReinstall, instance)
182
        RunTest(qa_instance.TestInstanceStartup, instance)
183

    
184
      if qa_config.TestEnabled('node-volumes'):
185
        RunTest(qa_node.TestNodeVolumes)
186

    
187
      RunTest(qa_instance.TestInstanceRemove, instance)
188
      del instance
189

    
190
    if qa_config.TestEnabled('instance-add-local-mirror-disk'):
191
      instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, node)
192

    
193
      if qa_config.TestEnabled('instance-shutdown'):
194
        RunTest(qa_instance.TestInstanceShutdown, instance)
195
        RunTest(qa_instance.TestInstanceStartup, instance)
196

    
197
      if qa_config.TestEnabled('instance-info'):
198
        RunTest(qa_instance.TestInstanceInfo, instance)
199

    
200
      if qa_config.TestEnabled('node-volumes'):
201
        RunTest(qa_node.TestNodeVolumes)
202

    
203
      RunTest(qa_instance.TestInstanceRemove, instance)
204
      del instance
205

    
206
    if qa_config.TestEnabled('instance-add-remote-raid-disk'):
207
      node2 = qa_config.AcquireNode(exclude=node)
208
      try:
209
        instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk,
210
                           node, node2)
211

    
212
        if qa_config.TestEnabled('instance-shutdown'):
213
          RunTest(qa_instance.TestInstanceShutdown, instance)
214
          RunTest(qa_instance.TestInstanceStartup, instance)
215

    
216
        if qa_config.TestEnabled('instance-info'):
217
          RunTest(qa_instance.TestInstanceInfo, instance)
218

    
219
        if qa_config.TestEnabled('instance-failover'):
220
          RunTest(qa_instance.TestInstanceFailover, instance)
221

    
222
        if qa_config.TestEnabled('node-evacuate'):
223
          RunTest(qa_node.TestNodeEvacuate, node, node2)
224

    
225
        if qa_config.TestEnabled('node-failover'):
226
          RunTest(qa_node.TestNodeFailover, node, node2)
227

    
228
        if qa_config.TestEnabled('node-volumes'):
229
          RunTest(qa_node.TestNodeVolumes)
230

    
231
        if qa_config.TestEnabled('instance-disk-failure'):
232
          RunTest(qa_instance.TestInstanceMasterDiskFailure,
233
                  instance, node, node2)
234
          RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
235
                  instance, node, node2)
236

    
237
        RunTest(qa_instance.TestInstanceRemove, instance)
238
        del instance
239
      finally:
240
        qa_config.ReleaseNode(node2)
241

    
242
  finally:
243
    qa_config.ReleaseNode(node)
244

    
245
  RunTest(qa_node.TestNodeRemoveAll)
246

    
247
  if qa_config.TestEnabled('cluster-destroy'):
248
    RunTest(qa_cluster.TestClusterDestroy)
249

    
250

    
251
if __name__ == '__main__':
252
  main()