Fix small things for integration of ApexLake with Yardstick
[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_params(self):
48         return self.params
49
50     def get_features(self):
51         features = dict()
52         features['description'] = 'Please implement the method ' \
53                                   '"get_features" for your benchmark'
54         features['parameters'] = list()
55         features['allowed_values'] = dict()
56         features['default_values'] = dict()
57         return features
58
59     @abc.abstractmethod
60     def init(self):
61         """
62         Initializes the benchmark
63         :return:
64         """
65         raise NotImplementedError("Subclass must implement abstract method")
66
67     @abc.abstractmethod
68     def finalize(self):
69         """
70         Finalizes the benchmark
71         :return:
72         """
73         raise NotImplementedError("Subclass must implement abstract method")
74
75     @abc.abstractmethod
76     def run(self):
77         """
78         This method executes the specific benchmark on the VNF already
79         instantiated
80         :return: list of dictionaries (every dictionary contains the results
81         of a data point
82         """
83         raise NotImplementedError("Subclass must implement abstract method")