modify sc lab pod yaml as real configure
[yardstick.git] / yardstick / benchmark / scenarios / base.py
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 """ Scenario base class
11 """
12
13 import yardstick.common.utils as utils
14
15
16 class Scenario(object):
17
18     def setup(self):
19         ''' default impl for scenario setup '''
20         pass
21
22     def run(self, args):
23         ''' catcher for not implemented run methods in subclasses '''
24         raise RuntimeError("run method not implemented")
25
26     def teardown(self):
27         ''' default impl for scenario teardown '''
28         pass
29
30     @staticmethod
31     def get_types():
32         '''return a list of known runner type (class) names'''
33         scenarios = []
34         for scenario in utils.itersubclasses(Scenario):
35             scenarios.append(scenario)
36         return scenarios
37
38     @staticmethod
39     def get_cls(scenario_type):
40         '''return class of specified type'''
41         for scenario in utils.itersubclasses(Scenario):
42             if scenario_type == scenario.__scenario_type__:
43                 return scenario
44
45         raise RuntimeError("No such scenario type %s" % scenario_type)
46
47     @staticmethod
48     def get(scenario_type):
49         """Returns instance of a scenario runner for execution type.
50         """
51         for scenario in utils.itersubclasses(Scenario):
52             if scenario_type == scenario.__scenario_type__:
53                 return scenario.__module__ + "." + scenario.__name__
54
55         raise RuntimeError("No such scenario type %s" % scenario_type)