Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ 5d640672

History | View | Annotate | Download (6.2 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-copyfile'):
107
    RunTest(qa_cluster.TestClusterCopyfile)
108

    
109
  if qa_config.TestEnabled('node-info'):
110
    RunTest(qa_node.TestNodeInfo)
111

    
112
  if qa_config.TestEnabled('cluster-burnin'):
113
    RunTest(qa_cluster.TestClusterBurnin)
114

    
115
  if qa_config.TestEnabled('cluster-master-failover'):
116
    RunTest(qa_cluster.TestClusterMasterFailover)
117

    
118
  node = qa_config.AcquireNode()
119
  try:
120
    if qa_config.TestEnabled('instance-add-plain-disk'):
121
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, node)
122

    
123
      if qa_config.TestEnabled('instance-shutdown'):
124
        RunTest(qa_instance.TestInstanceShutdown, instance)
125
        RunTest(qa_instance.TestInstanceStartup, instance)
126

    
127
      if qa_config.TestEnabled('instance-info'):
128
        RunTest(qa_instance.TestInstanceInfo, instance)
129

    
130
      if qa_config.TestEnabled('instance-automatic-restart'):
131
        RunTest(qa_daemon.TestInstanceAutomaticRestart, node, instance)
132

    
133
      if qa_config.TestEnabled('instance-consecutive-failures'):
134
        RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
135

    
136
      if qa_config.TestEnabled('instance-export'):
137
        expnode = qa_config.AcquireNode(exclude=node)
138
        try:
139
          name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
140

    
141
          if qa_config.TestEnabled('instance-import'):
142
            newinst = qa_config.AcquireInstance()
143
            try:
144
              RunTest(qa_instance.TestInstanceImport, node, newinst,
145
                      expnode, name)
146
              RunTest(qa_instance.TestInstanceRemove, newinst)
147
            finally:
148
              qa_config.ReleaseInstance(newinst)
149
        finally:
150
          qa_config.ReleaseNode(expnode)
151

    
152
      if qa_config.TestEnabled('node-volumes'):
153
        RunTest(qa_node.TestNodeVolumes)
154

    
155
      RunTest(qa_instance.TestInstanceRemove, instance)
156
      del instance
157

    
158
    if qa_config.TestEnabled('instance-add-local-mirror-disk'):
159
      instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, node)
160

    
161
      if qa_config.TestEnabled('instance-shutdown'):
162
        RunTest(qa_instance.TestInstanceShutdown, instance)
163
        RunTest(qa_instance.TestInstanceStartup, instance)
164

    
165
      if qa_config.TestEnabled('instance-info'):
166
        RunTest(qa_instance.TestInstanceInfo, 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-remote-raid-disk'):
175
      node2 = qa_config.AcquireNode(exclude=node)
176
      try:
177
        instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk,
178
                           node, node2)
179

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

    
184
        if qa_config.TestEnabled('instance-info'):
185
          RunTest(qa_instance.TestInstanceInfo, instance)
186

    
187
        if qa_config.TestEnabled('instance-failover'):
188
          RunTest(qa_instance.TestInstanceFailover, instance)
189

    
190
        if qa_config.TestEnabled('node-volumes'):
191
          RunTest(qa_node.TestNodeVolumes)
192

    
193
        RunTest(qa_instance.TestInstanceRemove, instance)
194
        del instance
195
      finally:
196
        qa_config.ReleaseNode(node2)
197

    
198
  finally:
199
    qa_config.ReleaseNode(node)
200

    
201
  RunTest(qa_node.TestNodeRemoveAll)
202

    
203
  if qa_config.TestEnabled('cluster-destroy'):
204
    RunTest(qa_cluster.TestClusterDestroy)
205

    
206

    
207
if __name__ == '__main__':
208
  main()