1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = 'gpetralx'
import unittest
import mock
from experimental_framework.benchmarks \
import multi_tenancy_throughput_benchmark as bench
class MockDeploymentUnit(object):
def deploy_heat_template(self, temp_file, stack_name, heat_param):
pass
def destroy_heat_template(self, stack_name):
pass
def get_deployment_unit():
return MockDeploymentUnit()
class TestMultiTenancyThroughputBenchmark(unittest.TestCase):
def setUp(self):
name = 'benchmark'
params = dict()
self.benchmark = bench.MultiTenancyThroughputBenchmark(name, params)
def tearDown(self):
pass
def test_get_features_for_sanity(self):
output = self.benchmark.get_features()
self.assertIsInstance(output, dict)
self.assertIn('parameters', output.keys())
self.assertIn('allowed_values', output.keys())
self.assertIn('default_values', output.keys())
self.assertIsInstance(output['parameters'], list)
self.assertIsInstance(output['allowed_values'], dict)
self.assertIsInstance(output['default_values'], dict)
@mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
side_effect=get_deployment_unit)
@mock.patch('experimental_framework.common.replace_in_file')
def test_init_for_success(self, replace_in_file, deployment_unit):
num_of_neighbours = 5
num_of_cores = '3'
amount_of_ram = '250M'
self.benchmark.lua_file = 'lua_file'
self.benchmark.results_file = 'result_file'
self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
self.benchmark.params['number_of_cores'] = num_of_cores
self.benchmark.params['amount_of_ram'] = amount_of_ram
self.benchmark.init()
param_1 = 'lua_file'
param_2 = 'local out_file = ""'
param_3 = 'local out_file = "result_file"'
replace_in_file.assert_called_once_with(param_1, param_2, param_3)
heat_param = dict()
heat_param['cores'] = num_of_cores
heat_param['memory'] = amount_of_ram
neighbor_stack_names = list()
deployment_unit.\
deploy_heat_template.assert_called_with(
self.benchmark.template_file,
'neighbour' + str(num_of_neighbours - 1), heat_param)
for i in range(0, num_of_neighbours):
neighbor_stack_names.append('neighbour' + str(i))
self.assertListEqual(neighbor_stack_names,
self.benchmark.neighbor_stack_names)
@mock.patch('experimental_framework.common.DEPLOYMENT_UNIT',
side_effect=get_deployment_unit)
@mock.patch('experimental_framework.common.replace_in_file')
def test_finalize_for_success(self, replace_in_file, deployment_unit):
num_of_neighbours = 5
self.benchmark.lua_file = 'lua_file'
self.benchmark.results_file = 'result_file'
self.benchmark.params['num_of_neighbours'] = str(num_of_neighbours)
self.benchmark.neighbor_stack_names = list()
self.benchmark.neighbor_stack_names.append(str(num_of_neighbours - 1))
self.benchmark.finalize()
param_1 = 'lua_file'
param_2 = 'local out_file = "result_file"'
param_3 = 'local out_file = ""'
replace_in_file.assert_called_once_with(param_1, param_2, param_3)
deployment_unit.\
destroy_heat_template.\
assert_called_with(str(num_of_neighbours - 1))
self.assertListEqual(list(), self.benchmark.neighbor_stack_names)
|