blob: 886d94bced2f54a54c830b91c98849b073b39f6a [file] [log] [blame]
David Kranzb9d97502013-05-01 15:55:04 -04001#!/usr/bin/env python
2
3# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
5# Copyright 2013 Quanta Research Cambridge, Inc.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18
19import argparse
Marc Kodererb0604412013-09-02 09:43:40 +020020import inspect
David Kranzb9d97502013-05-01 15:55:04 -040021import json
Marc Koderer888ddc42013-07-23 16:13:07 +020022import sys
Marc Koderer32221b8e2013-08-23 13:57:50 +020023from testtools.testsuite import iterate_tests
24from unittest import loader
25
26
Marc Kodererb0604412013-09-02 09:43:40 +020027def discover_stress_tests(path="./", filter_attr=None, call_inherited=False):
Marc Koderer32221b8e2013-08-23 13:57:50 +020028 """Discovers all tempest tests and create action out of them
29 """
Marc Koderer32221b8e2013-08-23 13:57:50 +020030 tests = []
31 testloader = loader.TestLoader()
32 list = testloader.discover(path)
33 for func in (iterate_tests(list)):
34 try:
35 method_name = getattr(func, '_testMethodName')
36 full_name = "%s.%s.%s" % (func.__module__,
37 func.__class__.__name__,
38 method_name)
39 test_func = getattr(func, method_name)
40 # NOTE(mkoderer): this contains a list of all type attributes
41 attrs = getattr(test_func, "__testtools_attrs")
42 except Exception:
43 next
44 if 'stress' in attrs:
45 if filter_attr is not None and not filter_attr in attrs:
46 continue
47 class_setup_per = getattr(test_func, "st_class_setup_per")
48
49 action = {'action':
50 "tempest.stress.actions.unit_test.UnitTest",
51 'kwargs': {"test_method": full_name,
52 "class_setup_per": class_setup_per
53 }
54 }
Marc Kodererb0604412013-09-02 09:43:40 +020055 if (not call_inherited and
56 getattr(test_func, "st_allow_inheritance") is not True):
57 class_structure = inspect.getmro(test_func.im_class)
58 if test_func.__name__ not in class_structure[0].__dict__:
59 continue
Marc Koderer32221b8e2013-08-23 13:57:50 +020060 tests.append(action)
61 return tests
David Kranzb9d97502013-05-01 15:55:04 -040062
David Kranzb9d97502013-05-01 15:55:04 -040063
64def main(ns):
Marc Koderer3414d732013-07-31 08:36:36 +020065 # NOTE(mkoderer): moved import to make "-h" possible without OpenStack
Marc Kodererfa399e72013-07-16 08:56:01 +020066 from tempest.stress import driver
Marc Koderer888ddc42013-07-23 16:13:07 +020067 result = 0
Marc Koderer32221b8e2013-08-23 13:57:50 +020068 if not ns.all:
69 tests = json.load(open(ns.tests, 'r'))
70 else:
Marc Kodererb0604412013-09-02 09:43:40 +020071 tests = discover_stress_tests(filter_attr=ns.type,
72 call_inherited=ns.call_inherited)
Marc Koderer32221b8e2013-08-23 13:57:50 +020073
Matthew Treinish8e663fc2013-07-16 10:55:22 -040074 if ns.serial:
75 for test in tests:
Marc Koderer888ddc42013-07-23 16:13:07 +020076 step_result = driver.stress_openstack([test],
77 ns.duration,
Marc Koderer3414d732013-07-31 08:36:36 +020078 ns.number,
79 ns.stop)
80 # NOTE(mkoderer): we just save the last result code
Marc Koderer888ddc42013-07-23 16:13:07 +020081 if (step_result != 0):
82 result = step_result
Matthew Treinish8e663fc2013-07-16 10:55:22 -040083 else:
Marc Koderer3414d732013-07-31 08:36:36 +020084 driver.stress_openstack(tests, ns.duration, ns.number, ns.stop)
Marc Koderer888ddc42013-07-23 16:13:07 +020085 return result
David Kranzb9d97502013-05-01 15:55:04 -040086
87
Marc Kodererb0604412013-09-02 09:43:40 +020088parser = argparse.ArgumentParser(description='Run stress tests')
David Kranzb9d97502013-05-01 15:55:04 -040089parser.add_argument('-d', '--duration', default=300, type=int,
Marc Kodererb0604412013-09-02 09:43:40 +020090 help="Duration of test in secs")
Matthew Treinish8e663fc2013-07-16 10:55:22 -040091parser.add_argument('-s', '--serial', action='store_true',
Marc Kodererb0604412013-09-02 09:43:40 +020092 help="Trigger running tests serially")
Marc Koderer3414d732013-07-31 08:36:36 +020093parser.add_argument('-S', '--stop', action='store_true',
Marc Kodererb0604412013-09-02 09:43:40 +020094 default=False, help="Stop on first error")
Marc Koderer69d3bea2013-07-18 08:32:11 +020095parser.add_argument('-n', '--number', type=int,
Marc Kodererb0604412013-09-02 09:43:40 +020096 help="How often an action is executed for each process")
Marc Koderer32221b8e2013-08-23 13:57:50 +020097group = parser.add_mutually_exclusive_group(required=True)
98group.add_argument('-a', '--all', action='store_true',
99 help="Execute all stress tests")
100parser.add_argument('-T', '--type',
101 help="Filters tests of a certain type (e.g. gate)")
Marc Kodererb0604412013-09-02 09:43:40 +0200102parser.add_argument('-i', '--call-inherited', action='store_true',
103 default=False,
104 help="Call also inherited function with stress attribute")
Marc Koderer32221b8e2013-08-23 13:57:50 +0200105group.add_argument('-t', "--tests", nargs='?',
Marc Kodererb0604412013-09-02 09:43:40 +0200106 help="Name of the file with test description")
Marc Koderer888ddc42013-07-23 16:13:07 +0200107
108if __name__ == "__main__":
109 sys.exit(main(parser.parse_args()))