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.
18 import experimental_framework.common as common
19 from experimental_framework.benchmarks \
20 import multi_tenancy_throughput_benchmark as bench
22 __author__ = 'gpetralx'
25 class MockDeploymentUnit(object):
26 def deploy_heat_template(self, temp_file, stack_name, heat_param):
29 def destroy_heat_template(self, stack_name):
33 def get_deployment_unit():
34 return MockDeploymentUnit()
37 class TestMultiTenancyThroughputBenchmark(unittest.TestCase):
41 common.BASE_DIR = os.getcwd()
42 self.benchmark = bench.MultiTenancyThroughputBenchmark(name, params)
47 def test_get_features_for_sanity(self):
48 output = self.benchmark.get_features()
49 self.assertIsInstance(output, dict)
50 self.assertIn('parameters', output.keys())
51 self.assertIn('allowed_values', output.keys())
52 self.assertIn('default_values', output.keys())
53 self.assertIsInstance(output['parameters'], list)
54 self.assertIsInstance(output['allowed_values'], dict)
55 self.assertIsInstance(output['default_values'], dict)
57 @mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
58 side_effect=get_deployment_unit)
59 @mock.patch('experimental_framework.common.replace_in_file')
60 def test_init_for_success(self, replace_in_file, deployment_unit):
63 amount_of_ram = '250M'
65 self.benchmark.lua_file = 'lua_file'
66 self.benchmark.results_file = 'result_file'
67 self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
68 self.benchmark.params['number_of_cores'] = num_of_cores
69 self.benchmark.params['amount_of_ram'] = amount_of_ram
73 param_2 = 'local out_file = ""'
74 param_3 = 'local out_file = "result_file"'
75 replace_in_file.assert_called_once_with(param_1, param_2, param_3)
78 heat_param['cores'] = num_of_cores
79 heat_param['memory'] = amount_of_ram
80 heat_param['network'] = ''
81 heat_param['subnet'] = ''
82 neighbor_stack_names = list()
85 deploy_heat_template.assert_called_with(
86 self.benchmark.template_file,
87 'neighbour' + str(num_of_neighbours - 1), heat_param)
89 for i in range(0, num_of_neighbours):
90 neighbor_stack_names.append('neighbour' + str(i))
92 self.assertListEqual(neighbor_stack_names,
93 self.benchmark.neighbor_stack_names)
95 @mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
96 side_effect=get_deployment_unit)
97 @mock.patch('experimental_framework.common.replace_in_file')
98 def test_finalize_for_success(self, replace_in_file, deployment_unit):
100 self.benchmark.lua_file = 'lua_file'
101 self.benchmark.results_file = 'result_file'
102 self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
103 self.benchmark.neighbor_stack_names = list()
104 self.benchmark.neighbor_stack_names.append(str(num_of_neighbours - 1))
105 self.benchmark.finalize()
108 param_2 = 'local out_file = "result_file"'
109 param_3 = 'local out_file = ""'
110 replace_in_file.assert_called_once_with(param_1, param_2, param_3)
113 destroy_heat_template.\
114 assert_called_with(str(num_of_neighbours - 1))
115 self.assertListEqual(list(), self.benchmark.neighbor_stack_names)