Merge "Move arp route tbl to script and update defailt vnf config files"
[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 from __future__ import absolute_import
23 import yardstick.common.utils as utils
24
25
26 class Scenario(object):
27
28     def setup(self):
29         """ default impl for scenario setup """
30         pass
31
32     def run(self, args):
33         """ catcher for not implemented run methods in subclasses """
34         raise RuntimeError("run method not implemented")
35
36     def teardown(self):
37         """ default impl for scenario teardown """
38         pass
39
40     @staticmethod
41     def get_types():
42         """return a list of known runner type (class) names"""
43         scenarios = []
44         for scenario in utils.itersubclasses(Scenario):
45             scenarios.append(scenario)
46         return scenarios
47
48     @staticmethod
49     def get_cls(scenario_type):
50         """return class of specified type"""
51         for scenario in utils.itersubclasses(Scenario):
52             if scenario_type == scenario.__scenario_type__:
53                 return scenario
54
55         raise RuntimeError("No such scenario type %s" % scenario_type)
56
57     @staticmethod
58     def get(scenario_type):
59         """Returns instance of a scenario runner for execution type.
60         """
61         for scenario in utils.itersubclasses(Scenario):
62             if scenario_type == scenario.__scenario_type__:
63                 return scenario.__module__ + "." + scenario.__name__
64
65         raise RuntimeError("No such scenario type %s" % scenario_type)
66
67     def _push_to_outputs(self, keys, values):
68         return dict(zip(keys, values))
69
70     def _change_obj_to_dict(self, obj):
71         dic = {}
72         for k, v in vars(obj).items():
73             try:
74                 vars(v)
75             except TypeError:
76                 dic[k] = v
77         return dic