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 from __future__ import absolute_import
19 import experimental_framework.common as common
20 from experimental_framework.benchmarks \
21 import multi_tenancy_throughput_benchmark as bench
22 from six.moves import range
24 __author__ = 'gpetralx'
27 class MockDeploymentUnit(object):
29 def deploy_heat_template(self, temp_file, stack_name, heat_param):
32 def destroy_heat_template(self, stack_name):
36 def get_deployment_unit():
37 return MockDeploymentUnit()
40 class TestMultiTenancyThroughputBenchmark(unittest.TestCase):
45 common.BASE_DIR = os.getcwd()
46 self.benchmark = bench.MultiTenancyThroughputBenchmark(name, params)
51 def test_get_features_for_sanity(self):
52 output = self.benchmark.get_features()
53 self.assertIsInstance(output, dict)
54 self.assertIn('parameters', list(output.keys()))
55 self.assertIn('allowed_values', list(output.keys()))
56 self.assertIn('default_values', list(output.keys()))
57 self.assertIsInstance(output['parameters'], list)
58 self.assertIsInstance(output['allowed_values'], dict)
59 self.assertIsInstance(output['default_values'], dict)
61 @mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
62 side_effect=get_deployment_unit)
63 @mock.patch('experimental_framework.common.replace_in_file')
64 def test_init_for_success(self, replace_in_file, deployment_unit):
67 amount_of_ram = '250M'
69 self.benchmark.lua_file = 'lua_file'
70 self.benchmark.results_file = 'result_file'
71 self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
72 self.benchmark.params['number_of_cores'] = num_of_cores
73 self.benchmark.params['amount_of_ram'] = amount_of_ram
77 param_2 = 'local out_file = ""'
78 param_3 = 'local out_file = "result_file"'
79 replace_in_file.assert_called_once_with(param_1, param_2, param_3)
82 heat_param['cores'] = num_of_cores
83 heat_param['memory'] = amount_of_ram
84 heat_param['network'] = ''
85 heat_param['subnet'] = ''
86 neighbor_stack_names = list()
89 deploy_heat_template.assert_called_with(
90 self.benchmark.template_file,
91 'neighbour' + str(num_of_neighbours - 1), heat_param)
93 for i in range(0, num_of_neighbours):
94 neighbor_stack_names.append('neighbour' + str(i))
96 self.assertListEqual(neighbor_stack_names,
97 self.benchmark.neighbor_stack_names)
99 @mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
100 side_effect=get_deployment_unit)
101 @mock.patch('experimental_framework.common.replace_in_file')
102 def test_finalize_for_success(self, replace_in_file, deployment_unit):
103 num_of_neighbours = 5
104 self.benchmark.lua_file = 'lua_file'
105 self.benchmark.results_file = 'result_file'
106 self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
107 self.benchmark.neighbor_stack_names = list()
108 self.benchmark.neighbor_stack_names.append(str(num_of_neighbours - 1))
109 self.benchmark.finalize()
112 param_2 = 'local out_file = "result_file"'
113 param_3 = 'local out_file = ""'
114 replace_in_file.assert_called_once_with(param_1, param_2, param_3)
117 destroy_heat_template.\
118 assert_called_with(str(num_of_neighbours - 1))
119 self.assertListEqual(list(), self.benchmark.neighbor_stack_names)