Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 283f9d4c

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

    
42

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

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

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

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

    
59
  return fn(*args)
60

    
61

    
62
def main():
63
  """Main program.
64

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

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

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

    
87
  qa_config.Load(config_file)
88

    
89
  RunTest(qa_other.TestUploadKnownHostsFile, known_hosts_file)
90

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

    
96
  RunTest(qa_cluster.TestClusterInit)
97

    
98
  RunTest(qa_node.TestNodeAddAll)
99

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

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

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

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

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

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

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

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

    
124
  node = qa_config.AcquireNode()
125
  try:
126
    if qa_config.TestEnabled('instance-add-plain-disk'):
127
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, node)
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-automatic-restart'):
140
        RunTest(qa_daemon.TestInstanceAutomaticRestart, node, instance)
141

    
142
      if qa_config.TestEnabled('instance-consecutive-failures'):
143
        RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
144

    
145
      if qa_config.TestEnabled('instance-export'):
146
        expnode = qa_config.AcquireNode(exclude=node)
147
        try:
148
          name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
149

    
150
          RunTest(qa_instance.TestBackupList, expnode)
151

    
152
          if qa_config.TestEnabled('instance-import'):
153
            newinst = qa_config.AcquireInstance()
154
            try:
155
              RunTest(qa_instance.TestInstanceImport, node, newinst,
156
                      expnode, name)
157
              RunTest(qa_instance.TestInstanceRemove, newinst)
158
            finally:
159
              qa_config.ReleaseInstance(newinst)
160
        finally:
161
          qa_config.ReleaseNode(expnode)
162

    
163
      if qa_config.TestEnabled('instance-reinstall'):
164
        RunTest(qa_instance.TestInstanceShutdown, instance)
165
        RunTest(qa_instance.TestInstanceReinstall, instance)
166
        RunTest(qa_instance.TestInstanceStartup, instance)
167

    
168
      if qa_config.TestEnabled('node-volumes'):
169
        RunTest(qa_node.TestNodeVolumes)
170

    
171
      RunTest(qa_instance.TestInstanceRemove, instance)
172
      del instance
173

    
174
    if qa_config.TestEnabled('instance-add-local-mirror-disk'):
175
      instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, node)
176

    
177
      if qa_config.TestEnabled('instance-shutdown'):
178
        RunTest(qa_instance.TestInstanceShutdown, instance)
179
        RunTest(qa_instance.TestInstanceStartup, instance)
180

    
181
      if qa_config.TestEnabled('instance-info'):
182
        RunTest(qa_instance.TestInstanceInfo, 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-remote-raid-disk'):
191
      node2 = qa_config.AcquireNode(exclude=node)
192
      try:
193
        instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk,
194
                           node, node2)
195

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

    
200
        if qa_config.TestEnabled('instance-info'):
201
          RunTest(qa_instance.TestInstanceInfo, instance)
202

    
203
        if qa_config.TestEnabled('instance-failover'):
204
          RunTest(qa_instance.TestInstanceFailover, instance)
205

    
206
        if qa_config.TestEnabled('node-volumes'):
207
          RunTest(qa_node.TestNodeVolumes)
208

    
209
        RunTest(qa_instance.TestInstanceRemove, instance)
210
        del instance
211
      finally:
212
        qa_config.ReleaseNode(node2)
213

    
214
  finally:
215
    qa_config.ReleaseNode(node)
216

    
217
  RunTest(qa_node.TestNodeRemoveAll)
218

    
219
  if qa_config.TestEnabled('cluster-destroy'):
220
    RunTest(qa_cluster.TestClusterDestroy)
221

    
222

    
223
if __name__ == '__main__':
224
  main()