blob: 067b994a1451742c5f2cb8c8564cd0dcff577318 [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
Marc Koderer16648e92013-10-05 10:49:13 +020026from tempest.openstack.common import log as logging
Marc Koderer211ca962013-12-05 12:20:21 +010027from tempest.stress import driver
Marc Koderer16648e92013-10-05 10:49:13 +020028
29LOG = logging.getLogger(__name__)
30
Marc Koderer32221b8e2013-08-23 13:57:50 +020031
Marc Kodererb0604412013-09-02 09:43:40 +020032def discover_stress_tests(path="./", filter_attr=None, call_inherited=False):
Marc Koderer32221b8e2013-08-23 13:57:50 +020033 """Discovers all tempest tests and create action out of them
34 """
Marc Koderer16648e92013-10-05 10:49:13 +020035 LOG.info("Start test discovery")
Marc Koderer32221b8e2013-08-23 13:57:50 +020036 tests = []
37 testloader = loader.TestLoader()
38 list = testloader.discover(path)
39 for func in (iterate_tests(list)):
Marc Koderer16648e92013-10-05 10:49:13 +020040 attrs = []
Marc Koderer32221b8e2013-08-23 13:57:50 +020041 try:
42 method_name = getattr(func, '_testMethodName')
43 full_name = "%s.%s.%s" % (func.__module__,
44 func.__class__.__name__,
45 method_name)
46 test_func = getattr(func, method_name)
47 # NOTE(mkoderer): this contains a list of all type attributes
48 attrs = getattr(test_func, "__testtools_attrs")
49 except Exception:
50 next
51 if 'stress' in attrs:
52 if filter_attr is not None and not filter_attr in attrs:
53 continue
54 class_setup_per = getattr(test_func, "st_class_setup_per")
55
56 action = {'action':
57 "tempest.stress.actions.unit_test.UnitTest",
58 'kwargs': {"test_method": full_name,
59 "class_setup_per": class_setup_per
60 }
61 }
Marc Kodererb0604412013-09-02 09:43:40 +020062 if (not call_inherited and
63 getattr(test_func, "st_allow_inheritance") is not True):
64 class_structure = inspect.getmro(test_func.im_class)
65 if test_func.__name__ not in class_structure[0].__dict__:
66 continue
Marc Koderer32221b8e2013-08-23 13:57:50 +020067 tests.append(action)
68 return tests
David Kranzb9d97502013-05-01 15:55:04 -040069
David Kranzb9d97502013-05-01 15:55:04 -040070
71def main(ns):
Marc Koderer888ddc42013-07-23 16:13:07 +020072 result = 0
Marc Koderer32221b8e2013-08-23 13:57:50 +020073 if not ns.all:
74 tests = json.load(open(ns.tests, 'r'))
75 else:
Marc Kodererb0604412013-09-02 09:43:40 +020076 tests = discover_stress_tests(filter_attr=ns.type,
77 call_inherited=ns.call_inherited)
Marc Koderer32221b8e2013-08-23 13:57:50 +020078
Matthew Treinish8e663fc2013-07-16 10:55:22 -040079 if ns.serial:
80 for test in tests:
Marc Koderer888ddc42013-07-23 16:13:07 +020081 step_result = driver.stress_openstack([test],
82 ns.duration,
Marc Koderer3414d732013-07-31 08:36:36 +020083 ns.number,
84 ns.stop)
85 # NOTE(mkoderer): we just save the last result code
Marc Koderer888ddc42013-07-23 16:13:07 +020086 if (step_result != 0):
87 result = step_result
Matthew Treinish8e663fc2013-07-16 10:55:22 -040088 else:
Marc Koderer3414d732013-07-31 08:36:36 +020089 driver.stress_openstack(tests, ns.duration, ns.number, ns.stop)
Marc Koderer888ddc42013-07-23 16:13:07 +020090 return result
David Kranzb9d97502013-05-01 15:55:04 -040091
92
Marc Kodererb0604412013-09-02 09:43:40 +020093parser = argparse.ArgumentParser(description='Run stress tests')
David Kranzb9d97502013-05-01 15:55:04 -040094parser.add_argument('-d', '--duration', default=300, type=int,
Marc Kodererb0604412013-09-02 09:43:40 +020095 help="Duration of test in secs")
Matthew Treinish8e663fc2013-07-16 10:55:22 -040096parser.add_argument('-s', '--serial', action='store_true',
Marc Kodererb0604412013-09-02 09:43:40 +020097 help="Trigger running tests serially")
Marc Koderer3414d732013-07-31 08:36:36 +020098parser.add_argument('-S', '--stop', action='store_true',
Marc Kodererb0604412013-09-02 09:43:40 +020099 default=False, help="Stop on first error")
Marc Koderer69d3bea2013-07-18 08:32:11 +0200100parser.add_argument('-n', '--number', type=int,
Marc Kodererb0604412013-09-02 09:43:40 +0200101 help="How often an action is executed for each process")
Marc Koderer32221b8e2013-08-23 13:57:50 +0200102group = parser.add_mutually_exclusive_group(required=True)
103group.add_argument('-a', '--all', action='store_true',
104 help="Execute all stress tests")
105parser.add_argument('-T', '--type',
106 help="Filters tests of a certain type (e.g. gate)")
Marc Kodererb0604412013-09-02 09:43:40 +0200107parser.add_argument('-i', '--call-inherited', action='store_true',
108 default=False,
109 help="Call also inherited function with stress attribute")
Marc Koderer32221b8e2013-08-23 13:57:50 +0200110group.add_argument('-t', "--tests", nargs='?',
Marc Kodererb0604412013-09-02 09:43:40 +0200111 help="Name of the file with test description")
Marc Koderer888ddc42013-07-23 16:13:07 +0200112
113if __name__ == "__main__":
Marc Koderer16648e92013-10-05 10:49:13 +0200114 try:
115 sys.exit(main(parser.parse_args()))
116 except Exception:
117 LOG.exception("Failure in the stress test framework")
118 sys.exit(1)