Statistics
| Branch: | Tag: | Revision:

root / snf-tools / synnefo_tools / burnin / __init__.py @ 100feeda

History | View | Annotate | Download (10.5 kB)

1 12ef696f Ilias Tsitsimpis
# Copyright 2013 GRNET S.A. All rights reserved.
2 12ef696f Ilias Tsitsimpis
#
3 12ef696f Ilias Tsitsimpis
# Redistribution and use in source and binary forms, with or
4 12ef696f Ilias Tsitsimpis
# without modification, are permitted provided that the following
5 12ef696f Ilias Tsitsimpis
# conditions are met:
6 12ef696f Ilias Tsitsimpis
#
7 12ef696f Ilias Tsitsimpis
#   1. Redistributions of source code must retain the above
8 12ef696f Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
9 12ef696f Ilias Tsitsimpis
#      disclaimer.
10 12ef696f Ilias Tsitsimpis
#
11 12ef696f Ilias Tsitsimpis
#   2. Redistributions in binary form must reproduce the above
12 12ef696f Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
13 12ef696f Ilias Tsitsimpis
#      disclaimer in the documentation and/or other materials
14 12ef696f Ilias Tsitsimpis
#      provided with the distribution.
15 12ef696f Ilias Tsitsimpis
#
16 12ef696f Ilias Tsitsimpis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 12ef696f Ilias Tsitsimpis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 12ef696f Ilias Tsitsimpis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 12ef696f Ilias Tsitsimpis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 12ef696f Ilias Tsitsimpis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 12ef696f Ilias Tsitsimpis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 12ef696f Ilias Tsitsimpis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 12ef696f Ilias Tsitsimpis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 12ef696f Ilias Tsitsimpis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 12ef696f Ilias Tsitsimpis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 12ef696f Ilias Tsitsimpis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 12ef696f Ilias Tsitsimpis
# POSSIBILITY OF SUCH DAMAGE.
28 12ef696f Ilias Tsitsimpis
#
29 12ef696f Ilias Tsitsimpis
# The views and conclusions contained in the software and
30 12ef696f Ilias Tsitsimpis
# documentation are those of the authors and should not be
31 12ef696f Ilias Tsitsimpis
# interpreted as representing official policies, either expressed
32 12ef696f Ilias Tsitsimpis
# or implied, of GRNET S.A.
33 12ef696f Ilias Tsitsimpis
34 12ef696f Ilias Tsitsimpis
"""
35 12ef696f Ilias Tsitsimpis
Burnin: functional tests for Synnefo
36 12ef696f Ilias Tsitsimpis

37 12ef696f Ilias Tsitsimpis
"""
38 12ef696f Ilias Tsitsimpis
39 12ef696f Ilias Tsitsimpis
import sys
40 12ef696f Ilias Tsitsimpis
import optparse
41 12ef696f Ilias Tsitsimpis
42 12ef696f Ilias Tsitsimpis
from synnefo_tools import version
43 12ef696f Ilias Tsitsimpis
from synnefo_tools.burnin import common
44 6f2b9836 Ilias Tsitsimpis
from synnefo_tools.burnin.astakos_tests import AstakosTestSuite
45 f772699c Ilias Tsitsimpis
from synnefo_tools.burnin.images_tests import \
46 f772699c Ilias Tsitsimpis
    FlavorsTestSuite, ImagesTestSuite
47 79a5c431 Ilias Tsitsimpis
from synnefo_tools.burnin.pithos_tests import PithosTestSuite
48 6c78720b Ilias Tsitsimpis
from synnefo_tools.burnin.server_tests import ServerTestSuite
49 3eaf0ec5 Ilias Tsitsimpis
from synnefo_tools.burnin.network_tests import NetworkTestSuite
50 8c67f82e Ilias Tsitsimpis
from synnefo_tools.burnin.stale_tests import \
51 60a80953 Ilias Tsitsimpis
    StaleServersTestSuite, StaleFloatingIPsTestSuite, StaleNetworksTestSuite
52 12ef696f Ilias Tsitsimpis
53 12ef696f Ilias Tsitsimpis
54 12ef696f Ilias Tsitsimpis
# --------------------------------------------------------------------
55 12ef696f Ilias Tsitsimpis
# Define our TestSuites
56 12ef696f Ilias Tsitsimpis
TESTSUITES = [
57 fe15cd00 Ilias Tsitsimpis
    AstakosTestSuite,
58 79a5c431 Ilias Tsitsimpis
    FlavorsTestSuite,
59 f772699c Ilias Tsitsimpis
    ImagesTestSuite,
60 79a5c431 Ilias Tsitsimpis
    PithosTestSuite,
61 6c78720b Ilias Tsitsimpis
    ServerTestSuite,
62 3eaf0ec5 Ilias Tsitsimpis
    NetworkTestSuite,
63 8c67f82e Ilias Tsitsimpis
]
64 12ef696f Ilias Tsitsimpis
TSUITES_NAMES = [tsuite.__name__ for tsuite in TESTSUITES]
65 12ef696f Ilias Tsitsimpis
66 8c67f82e Ilias Tsitsimpis
STALE_TESTSUITES = [
67 8c67f82e Ilias Tsitsimpis
    # Must be runned in this order
68 8c67f82e Ilias Tsitsimpis
    StaleServersTestSuite,
69 60a80953 Ilias Tsitsimpis
    StaleFloatingIPsTestSuite,
70 8c67f82e Ilias Tsitsimpis
    StaleNetworksTestSuite,
71 8c67f82e Ilias Tsitsimpis
]
72 8c67f82e Ilias Tsitsimpis
STALE_TSUITES_NAMES = [tsuite.__name__ for tsuite in STALE_TESTSUITES]
73 8c67f82e Ilias Tsitsimpis
74 12ef696f Ilias Tsitsimpis
75 12ef696f Ilias Tsitsimpis
def string_to_class(names):
76 12ef696f Ilias Tsitsimpis
    """Convert class namesto class objects"""
77 12ef696f Ilias Tsitsimpis
    return [eval(name) for name in names]
78 12ef696f Ilias Tsitsimpis
79 12ef696f Ilias Tsitsimpis
80 12ef696f Ilias Tsitsimpis
# --------------------------------------------------------------------
81 12ef696f Ilias Tsitsimpis
# Parse arguments
82 12ef696f Ilias Tsitsimpis
def parse_comma(option, _, value, parser):
83 12ef696f Ilias Tsitsimpis
    """Parse comma separated arguments"""
84 6c78720b Ilias Tsitsimpis
    parse_input = [p.strip() for p in value.split(',')]
85 6c78720b Ilias Tsitsimpis
    setattr(parser.values, option.dest, parse_input)
86 12ef696f Ilias Tsitsimpis
87 12ef696f Ilias Tsitsimpis
88 12ef696f Ilias Tsitsimpis
def parse_arguments(args):
89 12ef696f Ilias Tsitsimpis
    """Parse burnin arguments"""
90 12ef696f Ilias Tsitsimpis
    kwargs = {}
91 12ef696f Ilias Tsitsimpis
    kwargs["usage"] = "%prog [options]"
92 12ef696f Ilias Tsitsimpis
    kwargs["description"] = \
93 12ef696f Ilias Tsitsimpis
        "%prog runs a number of test scenarios on a Synnefo deployment."
94 12ef696f Ilias Tsitsimpis
95 12ef696f Ilias Tsitsimpis
    # Used * or ** magic. pylint: disable-msg=W0142
96 12ef696f Ilias Tsitsimpis
    parser = optparse.OptionParser(**kwargs)
97 12ef696f Ilias Tsitsimpis
    parser.disable_interspersed_args()
98 12ef696f Ilias Tsitsimpis
99 12ef696f Ilias Tsitsimpis
    parser.add_option(
100 12ef696f Ilias Tsitsimpis
        "--auth-url", action="store",
101 12ef696f Ilias Tsitsimpis
        type="string", default=None, dest="auth_url",
102 12ef696f Ilias Tsitsimpis
        help="The AUTH URI to use to reach the Synnefo API")
103 12ef696f Ilias Tsitsimpis
    parser.add_option(
104 12ef696f Ilias Tsitsimpis
        "--token", action="store",
105 12ef696f Ilias Tsitsimpis
        type="string", default=None, dest="token",
106 12ef696f Ilias Tsitsimpis
        help="The token to use for authentication to the API")
107 12ef696f Ilias Tsitsimpis
    parser.add_option(
108 12ef696f Ilias Tsitsimpis
        "--failfast", action="store_true",
109 12ef696f Ilias Tsitsimpis
        default=False, dest="failfast",
110 12ef696f Ilias Tsitsimpis
        help="Fail immediately if one of the tests fails")
111 12ef696f Ilias Tsitsimpis
    parser.add_option(
112 12ef696f Ilias Tsitsimpis
        "--no-ipv6", action="store_false",
113 12ef696f Ilias Tsitsimpis
        default=True, dest="use_ipv6",
114 12ef696f Ilias Tsitsimpis
        help="Disable IPv6 related tests")
115 12ef696f Ilias Tsitsimpis
    parser.add_option(
116 12ef696f Ilias Tsitsimpis
        "--action-timeout", action="store",
117 60a80953 Ilias Tsitsimpis
        type="int", default=420, dest="action_timeout", metavar="TIMEOUT",
118 12ef696f Ilias Tsitsimpis
        help="Wait TIMEOUT seconds for a server action to complete, "
119 12ef696f Ilias Tsitsimpis
             "then the test is considered failed")
120 12ef696f Ilias Tsitsimpis
    parser.add_option(
121 12ef696f Ilias Tsitsimpis
        "--action-warning", action="store",
122 60a80953 Ilias Tsitsimpis
        type="int", default=180, dest="action_warning", metavar="TIMEOUT",
123 12ef696f Ilias Tsitsimpis
        help="Warn if TIMEOUT seconds have passed and a server action "
124 12ef696f Ilias Tsitsimpis
             "has not been completed yet")
125 12ef696f Ilias Tsitsimpis
    parser.add_option(
126 12ef696f Ilias Tsitsimpis
        "--query-interval", action="store",
127 12ef696f Ilias Tsitsimpis
        type="int", default=3, dest="query_interval", metavar="INTERVAL",
128 12ef696f Ilias Tsitsimpis
        help="Query server status when requests are pending "
129 12ef696f Ilias Tsitsimpis
             "every INTERVAL seconds")
130 12ef696f Ilias Tsitsimpis
    parser.add_option(
131 6c78720b Ilias Tsitsimpis
        "--flavors", action="callback", callback=parse_comma,
132 6c78720b Ilias Tsitsimpis
        type="string", default=None, dest="flavors", metavar="FLAVORS",
133 6c78720b Ilias Tsitsimpis
        help="Force all server creations to use one of the specified FLAVORS "
134 12ef696f Ilias Tsitsimpis
             "instead of a randomly chosen one. Supports both search by name "
135 12ef696f Ilias Tsitsimpis
             "(reg expression) with \"name:flavor name\" or by id with "
136 12ef696f Ilias Tsitsimpis
             "\"id:flavor id\"")
137 12ef696f Ilias Tsitsimpis
    parser.add_option(
138 6c78720b Ilias Tsitsimpis
        "--images", action="callback", callback=parse_comma,
139 6c78720b Ilias Tsitsimpis
        type="string", default=None, dest="images", metavar="IMAGES",
140 6c78720b Ilias Tsitsimpis
        help="Force all server creations to use one of the specified IMAGES "
141 12ef696f Ilias Tsitsimpis
             "instead of the default one (a Debian Base image). Just like the "
142 6c78720b Ilias Tsitsimpis
             "--flavors option, it supports both search by name and id")
143 12ef696f Ilias Tsitsimpis
    parser.add_option(
144 f772699c Ilias Tsitsimpis
        "--system-user", action="store",
145 f772699c Ilias Tsitsimpis
        type="string", default=None, dest="system_user",
146 f772699c Ilias Tsitsimpis
        help="Owner of system images (typed option in the form of "
147 f772699c Ilias Tsitsimpis
             "\"name:user_name\" or \"id:uuuid\")")
148 f772699c Ilias Tsitsimpis
    parser.add_option(
149 12ef696f Ilias Tsitsimpis
        "--show-stale", action="store_true",
150 12ef696f Ilias Tsitsimpis
        default=False, dest="show_stale",
151 12ef696f Ilias Tsitsimpis
        help="Show stale servers from previous runs. A server is considered "
152 12ef696f Ilias Tsitsimpis
             "stale if its name starts with `%s'. If stale servers are found, "
153 12ef696f Ilias Tsitsimpis
             "exit with exit status 1." % common.SNF_TEST_PREFIX)
154 12ef696f Ilias Tsitsimpis
    parser.add_option(
155 12ef696f Ilias Tsitsimpis
        "--delete-stale", action="store_true",
156 12ef696f Ilias Tsitsimpis
        default=False, dest="delete_stale",
157 12ef696f Ilias Tsitsimpis
        help="Delete stale servers from previous runs")
158 12ef696f Ilias Tsitsimpis
    parser.add_option(
159 12ef696f Ilias Tsitsimpis
        "--log-folder", action="store",
160 12ef696f Ilias Tsitsimpis
        type="string", default="/var/log/burnin/", dest="log_folder",
161 12ef696f Ilias Tsitsimpis
        help="Define the absolute path where the output log is stored")
162 12ef696f Ilias Tsitsimpis
    parser.add_option(
163 12ef696f Ilias Tsitsimpis
        "--verbose", "-v", action="store",
164 12ef696f Ilias Tsitsimpis
        type="int", default=1, dest="verbose",
165 12ef696f Ilias Tsitsimpis
        help="Print detailed output messages")
166 12ef696f Ilias Tsitsimpis
    parser.add_option(
167 12ef696f Ilias Tsitsimpis
        "--version", action="store_true",
168 12ef696f Ilias Tsitsimpis
        default=False, dest="show_version",
169 12ef696f Ilias Tsitsimpis
        help="Show version and exit")
170 12ef696f Ilias Tsitsimpis
    parser.add_option(
171 12ef696f Ilias Tsitsimpis
        "--set-tests", action="callback", callback=parse_comma,
172 12ef696f Ilias Tsitsimpis
        type="string", default="all", dest="tests",
173 12ef696f Ilias Tsitsimpis
        help="Set comma separated tests for this run. Available tests: %s"
174 12ef696f Ilias Tsitsimpis
             % ", ".join(TSUITES_NAMES))
175 12ef696f Ilias Tsitsimpis
    parser.add_option(
176 12ef696f Ilias Tsitsimpis
        "--exclude-tests", action="callback", callback=parse_comma,
177 12ef696f Ilias Tsitsimpis
        type="string", default=None, dest="exclude_tests",
178 12ef696f Ilias Tsitsimpis
        help="Set comma separated tests to be excluded for this run.")
179 12ef696f Ilias Tsitsimpis
    parser.add_option(
180 12ef696f Ilias Tsitsimpis
        "--no-colors", action="store_false",
181 12ef696f Ilias Tsitsimpis
        default=True, dest="use_colors",
182 12ef696f Ilias Tsitsimpis
        help="Disable colorful output")
183 0c1833c8 Ilias Tsitsimpis
    parser.add_option(
184 0c1833c8 Ilias Tsitsimpis
        "--quiet", action="store_true",
185 0c1833c8 Ilias Tsitsimpis
        default=False, dest="quiet",
186 ee89df69 Ilias Tsitsimpis
        help="Turn off logging (both console and file logging)")
187 0c1833c8 Ilias Tsitsimpis
    parser.add_option(
188 0c1833c8 Ilias Tsitsimpis
        "--final-report-only", action="store_true",
189 0c1833c8 Ilias Tsitsimpis
        default=False, dest="final_report",
190 0c1833c8 Ilias Tsitsimpis
        help="Turn off log output and only print the contents of the log "
191 0c1833c8 Ilias Tsitsimpis
             "file at the end of the test. Useful when burnin is used in "
192 0c1833c8 Ilias Tsitsimpis
             "script files and it's output is to be sent using email")
193 24d1788b Ilias Tsitsimpis
    parser.add_option(
194 24d1788b Ilias Tsitsimpis
        "--temp-directory", action="store",
195 24d1788b Ilias Tsitsimpis
        default="/tmp/", dest="temp_directory",
196 24d1788b Ilias Tsitsimpis
        help="Directory to use for saving temporary files")
197 12ef696f Ilias Tsitsimpis
198 12ef696f Ilias Tsitsimpis
    (opts, args) = parser.parse_args(args)
199 12ef696f Ilias Tsitsimpis
200 12ef696f Ilias Tsitsimpis
    # ----------------------------------
201 12ef696f Ilias Tsitsimpis
    # Verify arguments
202 12ef696f Ilias Tsitsimpis
    # If `version' is given show version and exit
203 12ef696f Ilias Tsitsimpis
    if opts.show_version:
204 12ef696f Ilias Tsitsimpis
        show_version()
205 12ef696f Ilias Tsitsimpis
        sys.exit(0)
206 12ef696f Ilias Tsitsimpis
207 0c1833c8 Ilias Tsitsimpis
    # `delete_stale' implies `show_stale'
208 0c1833c8 Ilias Tsitsimpis
    if opts.delete_stale:
209 0c1833c8 Ilias Tsitsimpis
        opts.show_stale = True
210 0c1833c8 Ilias Tsitsimpis
211 ee89df69 Ilias Tsitsimpis
    # log_level:
212 ee89df69 Ilias Tsitsimpis
    #  0 -> log to console and file
213 ee89df69 Ilias Tsitsimpis
    #  1 -> log to file and output the results in console
214 ee89df69 Ilias Tsitsimpis
    #  2 -> don't log
215 ee89df69 Ilias Tsitsimpis
    opts.log_level = 0
216 0c1833c8 Ilias Tsitsimpis
    if opts.final_report:
217 ee89df69 Ilias Tsitsimpis
        opts.log_level = 1
218 ee89df69 Ilias Tsitsimpis
    if opts.quiet:
219 ee89df69 Ilias Tsitsimpis
        opts.log_level = 2
220 0c1833c8 Ilias Tsitsimpis
221 6c78720b Ilias Tsitsimpis
    # Check `--set-tests' and `--exclude-tests' options
222 6c78720b Ilias Tsitsimpis
    if opts.tests != "all" and \
223 6c78720b Ilias Tsitsimpis
            not (set(opts.tests)).issubset(set(TSUITES_NAMES)):
224 6c78720b Ilias Tsitsimpis
        raise optparse.OptionValueError("The selected set of tests is invalid")
225 6c78720b Ilias Tsitsimpis
    if opts.exclude_tests is not None and \
226 6c78720b Ilias Tsitsimpis
            not (set(opts.exclude_tests)).issubset(set(TSUITES_NAMES)):
227 6c78720b Ilias Tsitsimpis
        raise optparse.OptionValueError("The selected set of tests is invalid")
228 6c78720b Ilias Tsitsimpis
229 12ef696f Ilias Tsitsimpis
    # `token' is mandatory
230 12ef696f Ilias Tsitsimpis
    mandatory_argument(opts.token, "--token")
231 12ef696f Ilias Tsitsimpis
    # `auth_url' is mandatory
232 12ef696f Ilias Tsitsimpis
    mandatory_argument(opts.auth_url, "--auth-url")
233 12ef696f Ilias Tsitsimpis
234 12ef696f Ilias Tsitsimpis
    return (opts, args)
235 12ef696f Ilias Tsitsimpis
236 12ef696f Ilias Tsitsimpis
237 12ef696f Ilias Tsitsimpis
def show_version():
238 12ef696f Ilias Tsitsimpis
    """Show burnin's version"""
239 12ef696f Ilias Tsitsimpis
    sys.stdout.write("Burnin: version %s\n" % version.__version__)
240 12ef696f Ilias Tsitsimpis
241 12ef696f Ilias Tsitsimpis
242 12ef696f Ilias Tsitsimpis
def mandatory_argument(value, arg_name):
243 12ef696f Ilias Tsitsimpis
    """Check if a mandatory argument is given"""
244 12ef696f Ilias Tsitsimpis
    if (value is None) or (value == ""):
245 12ef696f Ilias Tsitsimpis
        sys.stderr.write("The " + arg_name + " argument is mandatory.\n")
246 12ef696f Ilias Tsitsimpis
        sys.exit("Invalid input")
247 12ef696f Ilias Tsitsimpis
248 12ef696f Ilias Tsitsimpis
249 12ef696f Ilias Tsitsimpis
# --------------------------------------------------------------------
250 12ef696f Ilias Tsitsimpis
# Burnin main function
251 12ef696f Ilias Tsitsimpis
def main():
252 12ef696f Ilias Tsitsimpis
    """Assemble test cases into a test suite, and run it
253 12ef696f Ilias Tsitsimpis

254 12ef696f Ilias Tsitsimpis
    IMPORTANT: Tests have dependencies and have to be run in the specified
255 12ef696f Ilias Tsitsimpis
    order inside a single test case. They communicate through attributes of the
256 12ef696f Ilias Tsitsimpis
    corresponding TestCase class (shared fixtures). Distinct subclasses of
257 12ef696f Ilias Tsitsimpis
    TestCase MAY SHARE NO DATA, since they are run in parallel, in distinct
258 12ef696f Ilias Tsitsimpis
    test runner processes.
259 12ef696f Ilias Tsitsimpis

260 12ef696f Ilias Tsitsimpis
    """
261 12ef696f Ilias Tsitsimpis
262 12ef696f Ilias Tsitsimpis
    # Parse arguments using `optparse'
263 12ef696f Ilias Tsitsimpis
    (opts, _) = parse_arguments(sys.argv[1:])
264 12ef696f Ilias Tsitsimpis
265 12ef696f Ilias Tsitsimpis
    # Initialize burnin
266 3eaf0ec5 Ilias Tsitsimpis
    (testsuites, failfast) = \
267 3eaf0ec5 Ilias Tsitsimpis
        common.initialize(opts, TSUITES_NAMES, STALE_TSUITES_NAMES)
268 12ef696f Ilias Tsitsimpis
    testsuites = string_to_class(testsuites)
269 12ef696f Ilias Tsitsimpis
270 12ef696f Ilias Tsitsimpis
    # Run burnin
271 12ef696f Ilias Tsitsimpis
    # The return value denotes the success status
272 ee89df69 Ilias Tsitsimpis
    return common.run_burnin(testsuites, failfast=failfast)
273 12ef696f Ilias Tsitsimpis
274 12ef696f Ilias Tsitsimpis
275 12ef696f Ilias Tsitsimpis
if __name__ == "__main__":
276 12ef696f Ilias Tsitsimpis
    sys.exit(main())