Statistics
| Branch: | Tag: | Revision:

root / qa / ganeti-qa.py @ d7e49c13

History | View | Annotate | Download (7.2 kB)

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

24 94508060 Michael Hanselmann
You can create the required known_hosts file using ssh-keyscan. It's mandatory
25 94508060 Michael Hanselmann
to use the full name of a node (FQDN). For security reasons, verify the keys
26 94508060 Michael Hanselmann
before using them.
27 94508060 Michael Hanselmann
Example: ssh-keyscan -t rsa node{1,2,3,4}.example.com > known_hosts
28 94508060 Michael Hanselmann
"""
29 a8083063 Iustin Pop
30 a8083063 Iustin Pop
import sys
31 a8083063 Iustin Pop
from datetime import datetime
32 a8083063 Iustin Pop
from optparse import OptionParser
33 a8083063 Iustin Pop
34 cec9845c Michael Hanselmann
import qa_cluster
35 cec9845c Michael Hanselmann
import qa_config
36 cec9845c Michael Hanselmann
import qa_daemon
37 cec9845c Michael Hanselmann
import qa_env
38 cec9845c Michael Hanselmann
import qa_instance
39 cec9845c Michael Hanselmann
import qa_node
40 cec9845c Michael Hanselmann
import qa_other
41 a8083063 Iustin Pop
42 a8083063 Iustin Pop
43 cec9845c Michael Hanselmann
def RunTest(fn, *args):
44 a8083063 Iustin Pop
  """Runs a test after printing a header.
45 a8083063 Iustin Pop

46 a8083063 Iustin Pop
  """
47 cec9845c Michael Hanselmann
  if fn.__doc__:
48 cec9845c Michael Hanselmann
    desc = fn.__doc__.splitlines()[0].strip()
49 a8083063 Iustin Pop
  else:
50 cec9845c Michael Hanselmann
    desc = '%r' % fn
51 a8083063 Iustin Pop
52 a8083063 Iustin Pop
  now = str(datetime.now())
53 a8083063 Iustin Pop
54 a8083063 Iustin Pop
  print
55 a8083063 Iustin Pop
  print '---', now, ('-' * (55 - len(now)))
56 a8083063 Iustin Pop
  print desc
57 a8083063 Iustin Pop
  print '-' * 60
58 a8083063 Iustin Pop
59 cec9845c Michael Hanselmann
  return fn(*args)
60 a8083063 Iustin Pop
61 a8083063 Iustin Pop
62 cec9845c Michael Hanselmann
def main():
63 cec9845c Michael Hanselmann
  """Main program.
64 a8083063 Iustin Pop

65 a8083063 Iustin Pop
  """
66 94508060 Michael Hanselmann
  parser = OptionParser(usage="%prog [options] <config-file> "
67 94508060 Michael Hanselmann
                              "<known-hosts-file>")
68 a8083063 Iustin Pop
  parser.add_option('--dry-run', dest='dry_run',
69 a8083063 Iustin Pop
      action="store_true",
70 a8083063 Iustin Pop
      help="Show what would be done")
71 a8083063 Iustin Pop
  parser.add_option('--yes-do-it', dest='yes_do_it',
72 a8083063 Iustin Pop
      action="store_true",
73 a8083063 Iustin Pop
      help="Really execute the tests")
74 cec9845c Michael Hanselmann
  (qa_config.options, args) = parser.parse_args()
75 a8083063 Iustin Pop
76 94508060 Michael Hanselmann
  if len(args) == 2:
77 94508060 Michael Hanselmann
    (config_file, known_hosts_file) = args
78 a8083063 Iustin Pop
  else:
79 94508060 Michael Hanselmann
    parser.error("Not enough arguments.")
80 a8083063 Iustin Pop
81 cec9845c Michael Hanselmann
  if not qa_config.options.yes_do_it:
82 a8083063 Iustin Pop
    print ("Executing this script irreversibly destroys any Ganeti\n"
83 a8083063 Iustin Pop
           "configuration on all nodes involved. If you really want\n"
84 a8083063 Iustin Pop
           "to start testing, supply the --yes-do-it option.")
85 a8083063 Iustin Pop
    sys.exit(1)
86 a8083063 Iustin Pop
87 cec9845c Michael Hanselmann
  qa_config.Load(config_file)
88 a8083063 Iustin Pop
89 cec9845c Michael Hanselmann
  RunTest(qa_other.TestUploadKnownHostsFile, known_hosts_file)
90 94508060 Michael Hanselmann
91 cec9845c Michael Hanselmann
  if qa_config.TestEnabled('env'):
92 cec9845c Michael Hanselmann
    RunTest(qa_env.TestSshConnection)
93 cec9845c Michael Hanselmann
    RunTest(qa_env.TestIcmpPing)
94 cec9845c Michael Hanselmann
    RunTest(qa_env.TestGanetiCommands)
95 a8083063 Iustin Pop
96 cec9845c Michael Hanselmann
  RunTest(qa_cluster.TestClusterInit)
97 a8083063 Iustin Pop
98 cec9845c Michael Hanselmann
  RunTest(qa_node.TestNodeAddAll)
99 180bdd1f Michael Hanselmann
100 cec9845c Michael Hanselmann
  if qa_config.TestEnabled('cluster-verify'):
101 cec9845c Michael Hanselmann
    RunTest(qa_cluster.TestClusterVerify)
102 e9e35aaa Michael Hanselmann
103 cec9845c Michael Hanselmann
  if qa_config.TestEnabled('cluster-info'):
104 cec9845c Michael Hanselmann
    RunTest(qa_cluster.TestClusterInfo)
105 a8083063 Iustin Pop
106 283f9d4c Michael Hanselmann
  if qa_config.TestEnabled('cluster-getmaster'):
107 283f9d4c Michael Hanselmann
    RunTest(qa_cluster.TestClusterGetmaster)
108 283f9d4c Michael Hanselmann
109 283f9d4c Michael Hanselmann
  if qa_config.TestEnabled('cluster-version'):
110 283f9d4c Michael Hanselmann
    RunTest(qa_cluster.TestClusterVersion)
111 283f9d4c Michael Hanselmann
112 cec9845c Michael Hanselmann
  if qa_config.TestEnabled('cluster-copyfile'):
113 cec9845c Michael Hanselmann
    RunTest(qa_cluster.TestClusterCopyfile)
114 a8083063 Iustin Pop
115 cec9845c Michael Hanselmann
  if qa_config.TestEnabled('node-info'):
116 cec9845c Michael Hanselmann
    RunTest(qa_node.TestNodeInfo)
117 e9e35aaa Michael Hanselmann
118 cec9845c Michael Hanselmann
  if qa_config.TestEnabled('cluster-burnin'):
119 cec9845c Michael Hanselmann
    RunTest(qa_cluster.TestClusterBurnin)
120 a8083063 Iustin Pop
121 cec9845c Michael Hanselmann
  if qa_config.TestEnabled('cluster-master-failover'):
122 cec9845c Michael Hanselmann
    RunTest(qa_cluster.TestClusterMasterFailover)
123 a8083063 Iustin Pop
124 cec9845c Michael Hanselmann
  node = qa_config.AcquireNode()
125 a8083063 Iustin Pop
  try:
126 cec9845c Michael Hanselmann
    if qa_config.TestEnabled('instance-add-plain-disk'):
127 cec9845c Michael Hanselmann
      instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, node)
128 5d640672 Michael Hanselmann
129 5d640672 Michael Hanselmann
      if qa_config.TestEnabled('instance-shutdown'):
130 5d640672 Michael Hanselmann
        RunTest(qa_instance.TestInstanceShutdown, instance)
131 5d640672 Michael Hanselmann
        RunTest(qa_instance.TestInstanceStartup, instance)
132 a8083063 Iustin Pop
133 283f9d4c Michael Hanselmann
      if qa_config.TestEnabled('instance-list'):
134 283f9d4c Michael Hanselmann
        RunTest(qa_instance.TestInstanceList)
135 283f9d4c Michael Hanselmann
136 cec9845c Michael Hanselmann
      if qa_config.TestEnabled('instance-info'):
137 cec9845c Michael Hanselmann
        RunTest(qa_instance.TestInstanceInfo, instance)
138 e9e35aaa Michael Hanselmann
139 23269c5b Michael Hanselmann
      automatic_restart = \
140 23269c5b Michael Hanselmann
        qa_config.TestEnabled('instance-automatic-restart')
141 23269c5b Michael Hanselmann
      consecutive_failures = \
142 23269c5b Michael Hanselmann
        qa_config.TestEnabled('instance-consecutive-failures')
143 a8083063 Iustin Pop
144 23269c5b Michael Hanselmann
      if automatic_restart or consecutive_failures:
145 23269c5b Michael Hanselmann
        qa_daemon.PrintCronWarning()
146 23269c5b Michael Hanselmann
147 23269c5b Michael Hanselmann
        if automatic_restart:
148 23269c5b Michael Hanselmann
          RunTest(qa_daemon.TestInstanceAutomaticRestart, node, instance)
149 23269c5b Michael Hanselmann
150 23269c5b Michael Hanselmann
        if consecutive_failures:
151 23269c5b Michael Hanselmann
          RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
152 a8083063 Iustin Pop
153 5d640672 Michael Hanselmann
      if qa_config.TestEnabled('instance-export'):
154 5d640672 Michael Hanselmann
        expnode = qa_config.AcquireNode(exclude=node)
155 5d640672 Michael Hanselmann
        try:
156 5d640672 Michael Hanselmann
          name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
157 5d640672 Michael Hanselmann
158 283f9d4c Michael Hanselmann
          RunTest(qa_instance.TestBackupList, expnode)
159 283f9d4c Michael Hanselmann
160 5d640672 Michael Hanselmann
          if qa_config.TestEnabled('instance-import'):
161 5d640672 Michael Hanselmann
            newinst = qa_config.AcquireInstance()
162 5d640672 Michael Hanselmann
            try:
163 5d640672 Michael Hanselmann
              RunTest(qa_instance.TestInstanceImport, node, newinst,
164 5d640672 Michael Hanselmann
                      expnode, name)
165 5d640672 Michael Hanselmann
              RunTest(qa_instance.TestInstanceRemove, newinst)
166 5d640672 Michael Hanselmann
            finally:
167 5d640672 Michael Hanselmann
              qa_config.ReleaseInstance(newinst)
168 5d640672 Michael Hanselmann
        finally:
169 5d640672 Michael Hanselmann
          qa_config.ReleaseNode(expnode)
170 5d640672 Michael Hanselmann
171 283f9d4c Michael Hanselmann
      if qa_config.TestEnabled('instance-reinstall'):
172 283f9d4c Michael Hanselmann
        RunTest(qa_instance.TestInstanceShutdown, instance)
173 283f9d4c Michael Hanselmann
        RunTest(qa_instance.TestInstanceReinstall, instance)
174 283f9d4c Michael Hanselmann
        RunTest(qa_instance.TestInstanceStartup, instance)
175 283f9d4c Michael Hanselmann
176 cec9845c Michael Hanselmann
      if qa_config.TestEnabled('node-volumes'):
177 cec9845c Michael Hanselmann
        RunTest(qa_node.TestNodeVolumes)
178 9df6d173 Michael Hanselmann
179 cec9845c Michael Hanselmann
      RunTest(qa_instance.TestInstanceRemove, instance)
180 a8083063 Iustin Pop
      del instance
181 a8083063 Iustin Pop
182 cec9845c Michael Hanselmann
    if qa_config.TestEnabled('instance-add-local-mirror-disk'):
183 cec9845c Michael Hanselmann
      instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, node)
184 5d640672 Michael Hanselmann
185 5d640672 Michael Hanselmann
      if qa_config.TestEnabled('instance-shutdown'):
186 5d640672 Michael Hanselmann
        RunTest(qa_instance.TestInstanceShutdown, instance)
187 5d640672 Michael Hanselmann
        RunTest(qa_instance.TestInstanceStartup, instance)
188 e9e35aaa Michael Hanselmann
189 cec9845c Michael Hanselmann
      if qa_config.TestEnabled('instance-info'):
190 cec9845c Michael Hanselmann
        RunTest(qa_instance.TestInstanceInfo, instance)
191 e9e35aaa Michael Hanselmann
192 cec9845c Michael Hanselmann
      if qa_config.TestEnabled('node-volumes'):
193 cec9845c Michael Hanselmann
        RunTest(qa_node.TestNodeVolumes)
194 9df6d173 Michael Hanselmann
195 cec9845c Michael Hanselmann
      RunTest(qa_instance.TestInstanceRemove, instance)
196 a8083063 Iustin Pop
      del instance
197 a8083063 Iustin Pop
198 cec9845c Michael Hanselmann
    if qa_config.TestEnabled('instance-add-remote-raid-disk'):
199 cec9845c Michael Hanselmann
      node2 = qa_config.AcquireNode(exclude=node)
200 a8083063 Iustin Pop
      try:
201 cec9845c Michael Hanselmann
        instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk,
202 cec9845c Michael Hanselmann
                           node, node2)
203 5d640672 Michael Hanselmann
204 5d640672 Michael Hanselmann
        if qa_config.TestEnabled('instance-shutdown'):
205 5d640672 Michael Hanselmann
          RunTest(qa_instance.TestInstanceShutdown, instance)
206 5d640672 Michael Hanselmann
          RunTest(qa_instance.TestInstanceStartup, instance)
207 a8083063 Iustin Pop
208 cec9845c Michael Hanselmann
        if qa_config.TestEnabled('instance-info'):
209 cec9845c Michael Hanselmann
          RunTest(qa_instance.TestInstanceInfo, instance)
210 e9e35aaa Michael Hanselmann
211 cec9845c Michael Hanselmann
        if qa_config.TestEnabled('instance-failover'):
212 cec9845c Michael Hanselmann
          RunTest(qa_instance.TestInstanceFailover, instance)
213 a8083063 Iustin Pop
214 4b62db14 Michael Hanselmann
        if qa_config.TestEnabled('node-evacuate'):
215 4b62db14 Michael Hanselmann
          RunTest(qa_node.TestNodeEvacuate, node, node2)
216 4b62db14 Michael Hanselmann
217 4b62db14 Michael Hanselmann
        if qa_config.TestEnabled('node-failover'):
218 4b62db14 Michael Hanselmann
          RunTest(qa_node.TestNodeFailover, node, node2)
219 4b62db14 Michael Hanselmann
220 cec9845c Michael Hanselmann
        if qa_config.TestEnabled('node-volumes'):
221 cec9845c Michael Hanselmann
          RunTest(qa_node.TestNodeVolumes)
222 9df6d173 Michael Hanselmann
223 cec9845c Michael Hanselmann
        RunTest(qa_instance.TestInstanceRemove, instance)
224 a8083063 Iustin Pop
        del instance
225 a8083063 Iustin Pop
      finally:
226 cec9845c Michael Hanselmann
        qa_config.ReleaseNode(node2)
227 a8083063 Iustin Pop
228 a8083063 Iustin Pop
  finally:
229 cec9845c Michael Hanselmann
    qa_config.ReleaseNode(node)
230 a8083063 Iustin Pop
231 cec9845c Michael Hanselmann
  RunTest(qa_node.TestNodeRemoveAll)
232 a8083063 Iustin Pop
233 cec9845c Michael Hanselmann
  if qa_config.TestEnabled('cluster-destroy'):
234 cec9845c Michael Hanselmann
    RunTest(qa_cluster.TestClusterDestroy)
235 a8083063 Iustin Pop
236 cec9845c Michael Hanselmann
237 cec9845c Michael Hanselmann
if __name__ == '__main__':
238 cec9845c Michael Hanselmann
  main()