Fix small things for integration of ApexLake with Yardstick
[yardstick.git] / yardstick / vTC / apexlake / tests / multi_tenancy_throughput_benchmark_test.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 __author__ = 'gpetralx'
16
17
18 import unittest
19 import mock
20 import os
21 import experimental_framework.common as common
22 from experimental_framework.benchmarks \
23     import multi_tenancy_throughput_benchmark as bench
24
25
26 class MockDeploymentUnit(object):
27     def deploy_heat_template(self, temp_file, stack_name, heat_param):
28         pass
29
30     def destroy_heat_template(self, stack_name):
31         pass
32
33
34 def get_deployment_unit():
35     return MockDeploymentUnit()
36
37
38 class TestMultiTenancyThroughputBenchmark(unittest.TestCase):
39     def setUp(self):
40         name = 'benchmark'
41         params = dict()
42         common.BASE_DIR = os.getcwd()
43         self.benchmark = bench.MultiTenancyThroughputBenchmark(name, params)
44
45     def tearDown(self):
46         pass
47
48     def test_get_features_for_sanity(self):
49         output = self.benchmark.get_features()
50         self.assertIsInstance(output, dict)
51         self.assertIn('parameters', output.keys())
52         self.assertIn('allowed_values', output.keys())
53         self.assertIn('default_values', output.keys())
54         self.assertIsInstance(output['parameters'], list)
55         self.assertIsInstance(output['allowed_values'], dict)
56         self.assertIsInstance(output['default_values'], dict)
57
58     @mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
59                 side_effect=get_deployment_unit)
60     @mock.patch('experimental_framework.common.replace_in_file')
61     def test_init_for_success(self, replace_in_file, deployment_unit):
62         num_of_neighbours = 5
63         num_of_cores = '3'
64         amount_of_ram = '250M'
65
66         self.benchmark.lua_file = 'lua_file'
67         self.benchmark.results_file = 'result_file'
68         self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
69         self.benchmark.params['number_of_cores'] = num_of_cores
70         self.benchmark.params['amount_of_ram'] = amount_of_ram
71         self.benchmark.init()
72
73         param_1 = 'lua_file'
74         param_2 = 'local out_file = ""'
75         param_3 = 'local out_file = "result_file"'
76         replace_in_file.assert_called_once_with(param_1, param_2, param_3)
77
78         heat_param = dict()
79         heat_param['cores'] = num_of_cores
80         heat_param['memory'] = amount_of_ram
81         neighbor_stack_names = list()
82
83         deployment_unit.\
84             deploy_heat_template.assert_called_with(
85                 self.benchmark.template_file,
86                 'neighbour' + str(num_of_neighbours - 1), heat_param)
87
88         for i in range(0, num_of_neighbours):
89             neighbor_stack_names.append('neighbour' + str(i))
90
91         self.assertListEqual(neighbor_stack_names,
92                              self.benchmark.neighbor_stack_names)
93
94     @mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
95                 side_effect=get_deployment_unit)
96     @mock.patch('experimental_framework.common.replace_in_file')
97     def test_finalize_for_success(self, replace_in_file, deployment_unit):
98         num_of_neighbours = 5
99         self.benchmark.lua_file = 'lua_file'
100         self.benchmark.results_file = 'result_file'
101         self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
102         self.benchmark.neighbor_stack_names = list()
103         self.benchmark.neighbor_stack_names.append(str(num_of_neighbours - 1))
104         self.benchmark.finalize()
105
106         param_1 = 'lua_file'
107         param_2 = 'local out_file = "result_file"'
108         param_3 = 'local out_file = ""'
109         replace_in_file.assert_called_once_with(param_1, param_2, param_3)
110
111         deployment_unit.\
112             destroy_heat_template.\
113             assert_called_with(str(num_of_neighbours - 1))
114         self.assertListEqual(list(), self.benchmark.neighbor_stack_names)