1 # Copyright 2013: Mirantis Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # yardstick comment: this is a modified copy of
17 # rally/rally/benchmark/scenarios/base.py
19 from stevedore import extension
21 import yardstick.common.utils as utils
24 def _iter_scenario_classes(scenario_type=None):
25 """Generator over all 'Scenario' subclasses
27 This function will iterate over all 'Scenario' subclasses defined in this
28 project and will load any class introduced by any installed plugin project,
29 defined in 'entry_points' section, under 'yardstick.scenarios' subsection.
31 extension.ExtensionManager(namespace='yardstick.scenarios',
33 for scenario in utils.itersubclasses(Scenario):
36 elif getattr(scenario, '__scenario_type__', None) == scenario_type:
40 class Scenario(object):
43 """ default impl for scenario setup """
47 """ catcher for not implemented run methods in subclasses """
48 raise RuntimeError("run method not implemented")
51 """ default impl for scenario teardown """
56 """return a list of known runner type (class) names"""
58 for scenario in _iter_scenario_classes():
59 scenarios.append(scenario)
63 def get_cls(scenario_type):
64 """return class of specified type"""
65 for scenario in _iter_scenario_classes(scenario_type):
68 raise RuntimeError("No such scenario type %s" % scenario_type)
71 def get(scenario_type):
72 """Returns instance of a scenario runner for execution type.
74 scenario = Scenario.get_cls(scenario_type)
75 return scenario.__module__ + "." + scenario.__name__
78 def get_scenario_type(cls):
79 """Return a string with the scenario type, if defined"""
80 return str(getattr(cls, '__scenario_type__', None))
83 def get_description(cls):
84 """Return a single line string with the class description
86 This function will retrieve the class docstring and return the first
87 line, or 'None' if it's empty.
89 return cls.__doc__.splitlines()[0] if cls.__doc__ else str(None)
91 def _push_to_outputs(self, keys, values):
92 return dict(zip(keys, values))
94 def _change_obj_to_dict(self, obj):
96 for k, v in vars(obj).items():