Add support to the test case required by YARDSTICK-36
[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 from experimental_framework.benchmarks \
21     import multi_tenancy_throughput_benchmark as bench
22
23
24 class MockDeploymentUnit(object):
25     def deploy_heat_template(self, temp_file, stack_name, heat_param):
26         pass
27
28     def destroy_heat_template(self, stack_name):
29         pass
30
31
32 def get_deployment_unit():
33     return MockDeploymentUnit()
34
35
36 class TestMultiTenancyThroughputBenchmark(unittest.TestCase):
37     def setUp(self):
38         name = 'benchmark'
39         params = dict()
40         self.benchmark = bench.MultiTenancyThroughputBenchmark(name, params)
41
42     def tearDown(self):
43         pass
44
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)
54
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):
59         num_of_neighbours = 5
60         num_of_cores = '3'
61         amount_of_ram = '250M'
62
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
68         self.benchmark.init()
69
70         param_1 = 'lua_file'
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)
74
75         heat_param = dict()
76         heat_param['cores'] = num_of_cores
77         heat_param['memory'] = amount_of_ram
78         neighbor_stack_names = list()
79
80         deployment_unit.\
81             deploy_heat_template.assert_called_with(
82                 self.benchmark.template_file,
83                 'neighbour' + str(num_of_neighbours - 1), heat_param)
84
85         for i in range(0, num_of_neighbours):
86             neighbor_stack_names.append('neighbour' + str(i))
87
88         self.assertListEqual(neighbor_stack_names,
89                              self.benchmark.neighbor_stack_names)
90
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):
95         num_of_neighbours = 5
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()
102
103         param_1 = 'lua_file'
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)
107
108         deployment_unit.\
109             destroy_heat_template.\
110             assert_called_with(str(num_of_neighbours - 1))
111         self.assertListEqual(list(), self.benchmark.neighbor_stack_names)