root / snf-tools / synnefo_tools / burnin / __init__.py @ 8c67f82e
History | View | Annotate | Download (10.1 kB)
1 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
"""
|
35 |
Burnin: functional tests for Synnefo
|
36 |
|
37 |
"""
|
38 |
|
39 |
import sys |
40 |
import optparse |
41 |
|
42 |
from synnefo_tools import version |
43 |
from synnefo_tools.burnin import common |
44 |
from synnefo_tools.burnin.astakos_tests import AstakosTestSuite |
45 |
from synnefo_tools.burnin.images_tests import \ |
46 |
FlavorsTestSuite, ImagesTestSuite |
47 |
from synnefo_tools.burnin.pithos_tests import PithosTestSuite |
48 |
from synnefo_tools.burnin.server_tests import ServerTestSuite |
49 |
from synnefo_tools.burnin.stale_tests import \ |
50 |
StaleServersTestSuite, StaleNetworksTestSuite |
51 |
|
52 |
|
53 |
# --------------------------------------------------------------------
|
54 |
# Define our TestSuites
|
55 |
TESTSUITES = [ |
56 |
AstakosTestSuite, |
57 |
FlavorsTestSuite, |
58 |
ImagesTestSuite, |
59 |
PithosTestSuite, |
60 |
ServerTestSuite, |
61 |
] |
62 |
TSUITES_NAMES = [tsuite.__name__ for tsuite in TESTSUITES] |
63 |
|
64 |
STALE_TESTSUITES = [ |
65 |
# Must be runned in this order
|
66 |
StaleServersTestSuite, |
67 |
StaleNetworksTestSuite, |
68 |
] |
69 |
STALE_TSUITES_NAMES = [tsuite.__name__ for tsuite in STALE_TESTSUITES] |
70 |
|
71 |
|
72 |
def string_to_class(names): |
73 |
"""Convert class namesto class objects"""
|
74 |
return [eval(name) for name in names] |
75 |
|
76 |
|
77 |
# --------------------------------------------------------------------
|
78 |
# Parse arguments
|
79 |
def parse_comma(option, _, value, parser): |
80 |
"""Parse comma separated arguments"""
|
81 |
parse_input = [p.strip() for p in value.split(',')] |
82 |
setattr(parser.values, option.dest, parse_input)
|
83 |
|
84 |
|
85 |
def parse_arguments(args): |
86 |
"""Parse burnin arguments"""
|
87 |
kwargs = {} |
88 |
kwargs["usage"] = "%prog [options]" |
89 |
kwargs["description"] = \
|
90 |
"%prog runs a number of test scenarios on a Synnefo deployment."
|
91 |
|
92 |
# Used * or ** magic. pylint: disable-msg=W0142
|
93 |
parser = optparse.OptionParser(**kwargs) |
94 |
parser.disable_interspersed_args() |
95 |
|
96 |
parser.add_option( |
97 |
"--auth-url", action="store", |
98 |
type="string", default=None, dest="auth_url", |
99 |
help="The AUTH URI to use to reach the Synnefo API")
|
100 |
parser.add_option( |
101 |
"--token", action="store", |
102 |
type="string", default=None, dest="token", |
103 |
help="The token to use for authentication to the API")
|
104 |
parser.add_option( |
105 |
"--failfast", action="store_true", |
106 |
default=False, dest="failfast", |
107 |
help="Fail immediately if one of the tests fails")
|
108 |
parser.add_option( |
109 |
"--no-ipv6", action="store_false", |
110 |
default=True, dest="use_ipv6", |
111 |
help="Disable IPv6 related tests")
|
112 |
parser.add_option( |
113 |
"--action-timeout", action="store", |
114 |
type="int", default=300, dest="action_timeout", metavar="TIMEOUT", |
115 |
help="Wait TIMEOUT seconds for a server action to complete, "
|
116 |
"then the test is considered failed")
|
117 |
parser.add_option( |
118 |
"--action-warning", action="store", |
119 |
type="int", default=120, dest="action_warning", metavar="TIMEOUT", |
120 |
help="Warn if TIMEOUT seconds have passed and a server action "
|
121 |
"has not been completed yet")
|
122 |
parser.add_option( |
123 |
"--query-interval", action="store", |
124 |
type="int", default=3, dest="query_interval", metavar="INTERVAL", |
125 |
help="Query server status when requests are pending "
|
126 |
"every INTERVAL seconds")
|
127 |
parser.add_option( |
128 |
"--flavors", action="callback", callback=parse_comma, |
129 |
type="string", default=None, dest="flavors", metavar="FLAVORS", |
130 |
help="Force all server creations to use one of the specified FLAVORS "
|
131 |
"instead of a randomly chosen one. Supports both search by name "
|
132 |
"(reg expression) with \"name:flavor name\" or by id with "
|
133 |
"\"id:flavor id\"")
|
134 |
parser.add_option( |
135 |
"--images", action="callback", callback=parse_comma, |
136 |
type="string", default=None, dest="images", metavar="IMAGES", |
137 |
help="Force all server creations to use one of the specified IMAGES "
|
138 |
"instead of the default one (a Debian Base image). Just like the "
|
139 |
"--flavors option, it supports both search by name and id")
|
140 |
parser.add_option( |
141 |
"--system-user", action="store", |
142 |
type="string", default=None, dest="system_user", |
143 |
help="Owner of system images (typed option in the form of "
|
144 |
"\"name:user_name\" or \"id:uuuid\")")
|
145 |
parser.add_option( |
146 |
"--show-stale", action="store_true", |
147 |
default=False, dest="show_stale", |
148 |
help="Show stale servers from previous runs. A server is considered "
|
149 |
"stale if its name starts with `%s'. If stale servers are found, "
|
150 |
"exit with exit status 1." % common.SNF_TEST_PREFIX)
|
151 |
parser.add_option( |
152 |
"--delete-stale", action="store_true", |
153 |
default=False, dest="delete_stale", |
154 |
help="Delete stale servers from previous runs")
|
155 |
parser.add_option( |
156 |
"--log-folder", action="store", |
157 |
type="string", default="/var/log/burnin/", dest="log_folder", |
158 |
help="Define the absolute path where the output log is stored")
|
159 |
parser.add_option( |
160 |
"--verbose", "-v", action="store", |
161 |
type="int", default=1, dest="verbose", |
162 |
help="Print detailed output messages")
|
163 |
parser.add_option( |
164 |
"--version", action="store_true", |
165 |
default=False, dest="show_version", |
166 |
help="Show version and exit")
|
167 |
parser.add_option( |
168 |
"--set-tests", action="callback", callback=parse_comma, |
169 |
type="string", default="all", dest="tests", |
170 |
help="Set comma separated tests for this run. Available tests: %s"
|
171 |
% ", ".join(TSUITES_NAMES))
|
172 |
parser.add_option( |
173 |
"--exclude-tests", action="callback", callback=parse_comma, |
174 |
type="string", default=None, dest="exclude_tests", |
175 |
help="Set comma separated tests to be excluded for this run.")
|
176 |
parser.add_option( |
177 |
"--no-colors", action="store_false", |
178 |
default=True, dest="use_colors", |
179 |
help="Disable colorful output")
|
180 |
parser.add_option( |
181 |
"--quiet", action="store_true", |
182 |
default=False, dest="quiet", |
183 |
help="Turn off log output")
|
184 |
parser.add_option( |
185 |
"--final-report-only", action="store_true", |
186 |
default=False, dest="final_report", |
187 |
help="Turn off log output and only print the contents of the log "
|
188 |
"file at the end of the test. Useful when burnin is used in "
|
189 |
"script files and it's output is to be sent using email")
|
190 |
|
191 |
(opts, args) = parser.parse_args(args) |
192 |
|
193 |
# ----------------------------------
|
194 |
# Verify arguments
|
195 |
# If `version' is given show version and exit
|
196 |
if opts.show_version:
|
197 |
show_version() |
198 |
sys.exit(0)
|
199 |
|
200 |
# `delete_stale' implies `show_stale'
|
201 |
if opts.delete_stale:
|
202 |
opts.show_stale = True
|
203 |
|
204 |
# `quiet' implies not `final_report'
|
205 |
if opts.quiet:
|
206 |
opts.final_report = False
|
207 |
# `final_report' implies `quiet'
|
208 |
if opts.final_report:
|
209 |
opts.quiet = True
|
210 |
|
211 |
# Check `--set-tests' and `--exclude-tests' options
|
212 |
if opts.tests != "all" and \ |
213 |
not (set(opts.tests)).issubset(set(TSUITES_NAMES)): |
214 |
raise optparse.OptionValueError("The selected set of tests is invalid") |
215 |
if opts.exclude_tests is not None and \ |
216 |
not (set(opts.exclude_tests)).issubset(set(TSUITES_NAMES)): |
217 |
raise optparse.OptionValueError("The selected set of tests is invalid") |
218 |
|
219 |
# `token' is mandatory
|
220 |
mandatory_argument(opts.token, "--token")
|
221 |
# `auth_url' is mandatory
|
222 |
mandatory_argument(opts.auth_url, "--auth-url")
|
223 |
|
224 |
return (opts, args)
|
225 |
|
226 |
|
227 |
def show_version(): |
228 |
"""Show burnin's version"""
|
229 |
sys.stdout.write("Burnin: version %s\n" % version.__version__)
|
230 |
|
231 |
|
232 |
def mandatory_argument(value, arg_name): |
233 |
"""Check if a mandatory argument is given"""
|
234 |
if (value is None) or (value == ""): |
235 |
sys.stderr.write("The " + arg_name + " argument is mandatory.\n") |
236 |
sys.exit("Invalid input")
|
237 |
|
238 |
|
239 |
# --------------------------------------------------------------------
|
240 |
# Burnin main function
|
241 |
def main(): |
242 |
"""Assemble test cases into a test suite, and run it
|
243 |
|
244 |
IMPORTANT: Tests have dependencies and have to be run in the specified
|
245 |
order inside a single test case. They communicate through attributes of the
|
246 |
corresponding TestCase class (shared fixtures). Distinct subclasses of
|
247 |
TestCase MAY SHARE NO DATA, since they are run in parallel, in distinct
|
248 |
test runner processes.
|
249 |
|
250 |
"""
|
251 |
|
252 |
# Parse arguments using `optparse'
|
253 |
(opts, _) = parse_arguments(sys.argv[1:])
|
254 |
|
255 |
# Initialize burnin
|
256 |
testsuites = common.initialize(opts, TSUITES_NAMES, STALE_TSUITES_NAMES) |
257 |
testsuites = string_to_class(testsuites) |
258 |
|
259 |
# Run burnin
|
260 |
# The return value denotes the success status
|
261 |
return common.run_burnin(testsuites, failfast=opts.failfast,
|
262 |
final_report=opts.final_report) |
263 |
|
264 |
|
265 |
if __name__ == "__main__": |
266 |
sys.exit(main()) |