7569627148bfa6fd26fedc6424f6b0e7cab21d38
[yardstick.git] / yardstick / vTC / apexlake / experimental_framework / benchmarks / benchmark_base_class.py
1 # Copyright (c) 2015 Intel Research and Development Ireland Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 import abc
17
18
19 class BenchmarkBaseClass(object):
20     '''
21     This class represents a Benchmark that we want to run on the platform.
22     One of them will be the calculation of the throughput changing the
23     configuration parameters
24     '''
25
26     def __init__(self, name, params):
27         if not params:
28             params = dict()
29         if not isinstance(params, dict):
30             raise ValueError("Parameters need to be provided in a dict")
31
32         for param in self.get_features()['parameters']:
33             if param not in params.keys():
34                 params[param] = self.get_features()['default_values'][param]
35
36         for param in self.get_features()['parameters']:
37             if params[param] not in \
38                     (self.get_features())['allowed_values'][param]:
39                 raise ValueError('Value of parameter "' + param +
40                                  '" is not allowed')
41         self.name = name
42         self.params = params
43
44     def get_name(self):
45         return self.name
46
47     def get_features(self):
48         features = dict()
49         features['description'] = 'Please implement the method ' \
50                                   '"get_features" for your benchmark'
51         features['parameters'] = list()
52         features['allowed_values'] = dict()
53         features['default_values'] = dict()
54         return features
55
56     @abc.abstractmethod
57     def init(self):
58         """
59         Initializes the benchmark
60         :return:
61         """
62         raise NotImplementedError("Subclass must implement abstract method")
63
64     @abc.abstractmethod
65     def finalize(self):
66         """
67         Finalizes the benchmark
68         :return:
69         """
70         raise NotImplementedError("Subclass must implement abstract method")
71
72     @abc.abstractmethod
73     def run(self):
74         """
75         This method executes the specific benchmark on the VNF already
76         instantiated
77         :return: list of dictionaries (every dictionary contains the results
78         of a data point
79         """
80         raise NotImplementedError("Subclass must implement abstract method")