1 # Copyright (c) 2015 Intel Research and Development Ireland Ltd.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 __author__ = 'gpetralx'
20 from experimental_framework.benchmarks \
21 import multi_tenancy_throughput_benchmark as bench
24 class MockDeploymentUnit(object):
25 def deploy_heat_template(self, temp_file, stack_name, heat_param):
28 def destroy_heat_template(self, stack_name):
32 def get_deployment_unit():
33 return MockDeploymentUnit()
36 class TestMultiTenancyThroughputBenchmark(unittest.TestCase):
40 self.benchmark = bench.MultiTenancyThroughputBenchmark(name, params)
45 def test_get_features_for_sanity(self):
46 output = self.benchmark.get_features()
47 self.assertIsInstance(output, dict)
48 self.assertIn('parameters', output.keys())
49 self.assertIn('allowed_values', output.keys())
50 self.assertIn('default_values', output.keys())
51 self.assertIsInstance(output['parameters'], list)
52 self.assertIsInstance(output['allowed_values'], dict)
53 self.assertIsInstance(output['default_values'], dict)
55 @mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
56 side_effect=get_deployment_unit)
57 @mock.patch('experimental_framework.common.replace_in_file')
58 def test_init_for_success(self, replace_in_file, deployment_unit):
61 amount_of_ram = '250M'
63 self.benchmark.lua_file = 'lua_file'
64 self.benchmark.results_file = 'result_file'
65 self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
66 self.benchmark.params['number_of_cores'] = num_of_cores
67 self.benchmark.params['amount_of_ram'] = amount_of_ram
71 param_2 = 'local out_file = ""'
72 param_3 = 'local out_file = "result_file"'
73 replace_in_file.assert_called_once_with(param_1, param_2, param_3)
76 heat_param['cores'] = num_of_cores
77 heat_param['memory'] = amount_of_ram
78 neighbor_stack_names = list()
81 deploy_heat_template.assert_called_with(
82 self.benchmark.template_file,
83 'neighbour' + str(num_of_neighbours - 1), heat_param)
85 for i in range(0, num_of_neighbours):
86 neighbor_stack_names.append('neighbour' + str(i))
88 self.assertListEqual(neighbor_stack_names,
89 self.benchmark.neighbor_stack_names)
91 @mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
92 side_effect=get_deployment_unit)
93 @mock.patch('experimental_framework.common.replace_in_file')
94 def test_finalize_for_success(self, replace_in_file, deployment_unit):
96 self.benchmark.lua_file = 'lua_file'
97 self.benchmark.results_file = 'result_file'
98 self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
99 self.benchmark.neighbor_stack_names = list()
100 self.benchmark.neighbor_stack_names.append(str(num_of_neighbours - 1))
101 self.benchmark.finalize()
104 param_2 = 'local out_file = "result_file"'
105 param_3 = 'local out_file = ""'
106 replace_in_file.assert_called_once_with(param_1, param_2, param_3)
109 destroy_heat_template.\
110 assert_called_with(str(num_of_neighbours - 1))
111 self.assertListEqual(list(), self.benchmark.neighbor_stack_names)