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'
21 import experimental_framework.common as common
22 from experimental_framework.benchmarks \
23 import multi_tenancy_throughput_benchmark as bench
26 class MockDeploymentUnit(object):
27 def deploy_heat_template(self, temp_file, stack_name, heat_param):
30 def destroy_heat_template(self, stack_name):
34 def get_deployment_unit():
35 return MockDeploymentUnit()
38 class TestMultiTenancyThroughputBenchmark(unittest.TestCase):
42 common.BASE_DIR = os.getcwd()
43 self.benchmark = bench.MultiTenancyThroughputBenchmark(name, params)
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)
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):
64 amount_of_ram = '250M'
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
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)
79 heat_param['cores'] = num_of_cores
80 heat_param['memory'] = amount_of_ram
81 neighbor_stack_names = list()
84 deploy_heat_template.assert_called_with(
85 self.benchmark.template_file,
86 'neighbour' + str(num_of_neighbours - 1), heat_param)
88 for i in range(0, num_of_neighbours):
89 neighbor_stack_names.append('neighbour' + str(i))
91 self.assertListEqual(neighbor_stack_names,
92 self.benchmark.neighbor_stack_names)
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):
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()
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)
112 destroy_heat_template.\
113 assert_called_with(str(num_of_neighbours - 1))
114 self.assertListEqual(list(), self.benchmark.neighbor_stack_names)