Fix small things for integration of ApexLake with Yardstick
[yardstick.git] / yardstick / vTC / apexlake / experimental_framework / benchmarks / instantiation_validation_noisy_neighbors_benchmark.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 instantiation_validation_benchmark as base
17 from experimental_framework import common
18
19
20 NUM_OF_NEIGHBORS = 'num_of_neighbours'
21 AMOUNT_OF_RAM = 'amount_of_ram'
22 NUMBER_OF_CORES = 'number_of_cores'
23
24
25 class InstantiationValidationNoisyNeighborsBenchmark(
26         base.InstantiationValidationBenchmark):
27
28     def __init__(self, name, params):
29         base.InstantiationValidationBenchmark.__init__(self, name, params)
30         self.template_file = common.get_template_dir() + \
31             'stress_workload.yaml'
32         self.stack_name = 'neighbour'
33         self.neighbor_stack_names = list()
34
35     def get_features(self):
36         features = super(InstantiationValidationNoisyNeighborsBenchmark,
37                          self).get_features()
38         features['description'] = 'Instantiation Validation Benchmark ' \
39                                   'with noisy neghbors'
40         features['parameters'].append(NUM_OF_NEIGHBORS)
41         features['parameters'].append(AMOUNT_OF_RAM)
42         features['parameters'].append(NUMBER_OF_CORES)
43         features['allowed_values'][NUM_OF_NEIGHBORS] = \
44             ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
45         features['allowed_values'][NUMBER_OF_CORES] = \
46             ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
47         features['allowed_values'][AMOUNT_OF_RAM] = \
48             ['256M', '1G', '2G', '3G', '4G', '5G', '6G', '7G', '8G', '9G',
49              '10G']
50         features['default_values'][NUM_OF_NEIGHBORS] = '1'
51         features['default_values'][NUMBER_OF_CORES] = '1'
52         features['default_values'][AMOUNT_OF_RAM] = '256M'
53         return features
54
55     def init(self):
56         super(InstantiationValidationNoisyNeighborsBenchmark, self).init()
57         common.replace_in_file(self.lua_file, 'local out_file = ""',
58                                'local out_file = "' +
59                                self.results_file + '"')
60         heat_param = dict()
61         heat_param['cores'] = self.params['number_of_cores']
62         heat_param['memory'] = self.params['amount_of_ram']
63         for i in range(0, int(self.params['num_of_neighbours'])):
64             stack_name = self.stack_name + str(i)
65             common.DEPLOYMENT_UNIT.deploy_heat_template(self.template_file,
66                                                         stack_name,
67                                                         heat_param)
68             self.neighbor_stack_names.append(stack_name)
69
70     def finalize(self):
71         common.replace_in_file(self.lua_file, 'local out_file = "' +
72                                self.results_file + '"',
73                                'local out_file = ""')
74         # destroy neighbor stacks
75         for stack_name in self.neighbor_stack_names:
76             common.DEPLOYMENT_UNIT.destroy_heat_template(stack_name)
77         self.neighbor_stack_names = list()