ganeti-qa.py 7.42 KB
Newer Older
Iustin Pop's avatar
Iustin Pop committed
1
2
3
#!/usr/bin/python
#

4
# Copyright (C) 2007 Google Inc.
Iustin Pop's avatar
Iustin Pop committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


22
"""Script for doing QA on Ganeti.
23
24
25
26
27
28

You can create the required known_hosts file using ssh-keyscan. It's mandatory
to use the full name of a node (FQDN). For security reasons, verify the keys
before using them.
Example: ssh-keyscan -t rsa node{1,2,3,4}.example.com > known_hosts
"""
Iustin Pop's avatar
Iustin Pop committed
29
30
31
32
33

import sys
from datetime import datetime
from optparse import OptionParser

34
35
36
37
38
39
import qa_cluster
import qa_config
import qa_daemon
import qa_env
import qa_instance
import qa_node
40
import qa_os
41
import qa_other
Iustin Pop's avatar
Iustin Pop committed
42
43


44
def RunTest(fn, *args):
Iustin Pop's avatar
Iustin Pop committed
45
46
47
  """Runs a test after printing a header.

  """
48
49
  if fn.__doc__:
    desc = fn.__doc__.splitlines()[0].strip()
Iustin Pop's avatar
Iustin Pop committed
50
  else:
51
    desc = '%r' % fn
Iustin Pop's avatar
Iustin Pop committed
52
53
54
55
56
57
58
59

  now = str(datetime.now())

  print
  print '---', now, ('-' * (55 - len(now)))
  print desc
  print '-' * 60

60
  return fn(*args)
Iustin Pop's avatar
Iustin Pop committed
61
62


63
64
def main():
  """Main program.
Iustin Pop's avatar
Iustin Pop committed
65
66

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

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

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

88
  qa_config.Load(config_file)
Iustin Pop's avatar
Iustin Pop committed
89

90
  RunTest(qa_other.TestUploadKnownHostsFile, known_hosts_file)
91

92
93
94
95
  if qa_config.TestEnabled('env'):
    RunTest(qa_env.TestSshConnection)
    RunTest(qa_env.TestIcmpPing)
    RunTest(qa_env.TestGanetiCommands)
Iustin Pop's avatar
Iustin Pop committed
96

97
  RunTest(qa_cluster.TestClusterInit)
Iustin Pop's avatar
Iustin Pop committed
98

99
  RunTest(qa_node.TestNodeAddAll)
100

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

104
105
  if qa_config.TestEnabled('cluster-info'):
    RunTest(qa_cluster.TestClusterInfo)
Iustin Pop's avatar
Iustin Pop committed
106

Michael Hanselmann's avatar
Michael Hanselmann committed
107
108
109
110
111
112
  if qa_config.TestEnabled('cluster-getmaster'):
    RunTest(qa_cluster.TestClusterGetmaster)

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

113
114
  if qa_config.TestEnabled('cluster-copyfile'):
    RunTest(qa_cluster.TestClusterCopyfile)
Iustin Pop's avatar
Iustin Pop committed
115

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

119
120
  if qa_config.TestEnabled('cluster-burnin'):
    RunTest(qa_cluster.TestClusterBurnin)
Iustin Pop's avatar
Iustin Pop committed
121

122
123
  if qa_config.TestEnabled('cluster-master-failover'):
    RunTest(qa_cluster.TestClusterMasterFailover)
Iustin Pop's avatar
Iustin Pop committed
124

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

132
  node = qa_config.AcquireNode()
Iustin Pop's avatar
Iustin Pop committed
133
  try:
134
135
    if qa_config.TestEnabled('instance-add-plain-disk'):
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, node)
Michael Hanselmann's avatar
Michael Hanselmann committed
136
137
138
139

      if qa_config.TestEnabled('instance-shutdown'):
        RunTest(qa_instance.TestInstanceShutdown, instance)
        RunTest(qa_instance.TestInstanceStartup, instance)
Iustin Pop's avatar
Iustin Pop committed
140

Michael Hanselmann's avatar
Michael Hanselmann committed
141
142
143
      if qa_config.TestEnabled('instance-list'):
        RunTest(qa_instance.TestInstanceList)

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

Michael Hanselmann's avatar
Michael Hanselmann committed
147
148
149
150
      automatic_restart = \
        qa_config.TestEnabled('instance-automatic-restart')
      consecutive_failures = \
        qa_config.TestEnabled('instance-consecutive-failures')
Iustin Pop's avatar
Iustin Pop committed
151

Michael Hanselmann's avatar
Michael Hanselmann committed
152
153
154
155
156
157
158
159
      if automatic_restart or consecutive_failures:
        qa_daemon.PrintCronWarning()

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

        if consecutive_failures:
          RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
Iustin Pop's avatar
Iustin Pop committed
160

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

Michael Hanselmann's avatar
Michael Hanselmann committed
166
167
          RunTest(qa_instance.TestBackupList, expnode)

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

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

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

187
      RunTest(qa_instance.TestInstanceRemove, instance)
Iustin Pop's avatar
Iustin Pop committed
188
189
      del instance

190
191
    if qa_config.TestEnabled('instance-add-local-mirror-disk'):
      instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, node)
Michael Hanselmann's avatar
Michael Hanselmann committed
192
193
194
195

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

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

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

203
      RunTest(qa_instance.TestInstanceRemove, instance)
Iustin Pop's avatar
Iustin Pop committed
204
205
      del instance

206
207
    if qa_config.TestEnabled('instance-add-remote-raid-disk'):
      node2 = qa_config.AcquireNode(exclude=node)
Iustin Pop's avatar
Iustin Pop committed
208
      try:
209
210
        instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk,
                           node, node2)
Michael Hanselmann's avatar
Michael Hanselmann committed
211
212
213
214

        if qa_config.TestEnabled('instance-shutdown'):
          RunTest(qa_instance.TestInstanceShutdown, instance)
          RunTest(qa_instance.TestInstanceStartup, instance)
Iustin Pop's avatar
Iustin Pop committed
215

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

219
220
        if qa_config.TestEnabled('instance-failover'):
          RunTest(qa_instance.TestInstanceFailover, instance)
Iustin Pop's avatar
Iustin Pop committed
221

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

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

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

231
        RunTest(qa_instance.TestInstanceRemove, instance)
Iustin Pop's avatar
Iustin Pop committed
232
233
        del instance
      finally:
234
        qa_config.ReleaseNode(node2)
Iustin Pop's avatar
Iustin Pop committed
235
236

  finally:
237
    qa_config.ReleaseNode(node)
Iustin Pop's avatar
Iustin Pop committed
238

239
  RunTest(qa_node.TestNodeRemoveAll)
Iustin Pop's avatar
Iustin Pop committed
240

241
242
  if qa_config.TestEnabled('cluster-destroy'):
    RunTest(qa_cluster.TestClusterDestroy)
Iustin Pop's avatar
Iustin Pop committed
243

244
245
246

if __name__ == '__main__':
  main()