fc5a7fddb74d24a2857abb180c7230f8b6310db8
[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 import unittest
16 import mock
17 import os
18 import experimental_framework.common as common
19 from experimental_framework.benchmarks \
20     import multi_tenancy_throughput_benchmark as bench
21
22 __author__ = 'gpetralx'
23
24
25 class MockDeploymentUnit(object):
26     def deploy_heat_template(self, temp_file, stack_name, heat_param):
27         pass
28
29     def destroy_heat_template(self, stack_name):
30         pass
31
32
33 def get_deployment_unit():
34     return MockDeploymentUnit()
35
36
37 class TestMultiTenancyThroughputBenchmark(unittest.TestCase):
38     def setUp(self):
39         name = 'benchmark'
40         params = dict()
41         common.BASE_DIR = os.getcwd()
42         self.benchmark = bench.MultiTenancyThroughputBenchmark(name, params)
43
44     def tearDown(self):
45         pass
46
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)
56
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):
61         num_of_neighbours = 5
62         num_of_cores = '3'
63         amount_of_ram = '250M'
64
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
70         self.benchmark.init()
71
72         param_1 = 'lua_file'
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)
76
77         heat_param = dict()
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()
83
84         deployment_unit.\
85             deploy_heat_template.assert_called_with(
86                 self.benchmark.template_file,
87                 'neighbour' + str(num_of_neighbours - 1), heat_param)
88
89         for i in range(0, num_of_neighbours):
90             neighbor_stack_names.append('neighbour' + str(i))
91
92         self.assertListEqual(neighbor_stack_names,
93                              self.benchmark.neighbor_stack_names)
94
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):
99         num_of_neighbours = 5
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()
106
107         param_1 = 'lua_file'
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)
111
112         deployment_unit.\
113             destroy_heat_template.\
114             assert_called_with(str(num_of_neighbours - 1))
115         self.assertListEqual(list(), self.benchmark.neighbor_stack_names)