Merge "complement sceanrio for joid, apex, noha"
[yardstick.git] / yardstick / benchmark / scenarios / base.py
1 # Copyright 2013: Mirantis Inc.
2 # All Rights Reserved.
3 #
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
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
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
14 #    under the License.
15
16 # yardstick comment: this is a modified copy of
17 # rally/rally/benchmark/scenarios/base.py
18
19 """ Scenario base class
20 """
21
22 import yardstick.common.utils as utils
23
24
25 class Scenario(object):
26
27     def setup(self):
28         ''' default impl for scenario setup '''
29         pass
30
31     def run(self, args):
32         ''' catcher for not implemented run methods in subclasses '''
33         raise RuntimeError("run method not implemented")
34
35     def teardown(self):
36         ''' default impl for scenario teardown '''
37         pass
38
39     @staticmethod
40     def get_types():
41         '''return a list of known runner type (class) names'''
42         scenarios = []
43         for scenario in utils.itersubclasses(Scenario):
44             scenarios.append(scenario)
45         return scenarios
46
47     @staticmethod
48     def get_cls(scenario_type):
49         '''return class of specified type'''
50         for scenario in utils.itersubclasses(Scenario):
51             if scenario_type == scenario.__scenario_type__:
52                 return scenario
53
54         raise RuntimeError("No such scenario type %s" % scenario_type)
55
56     @staticmethod
57     def get(scenario_type):
58         """Returns instance of a scenario runner for execution type.
59         """
60         for scenario in utils.itersubclasses(Scenario):
61             if scenario_type == scenario.__scenario_type__:
62                 return scenario.__module__ + "." + scenario.__name__
63
64         raise RuntimeError("No such scenario type %s" % scenario_type)