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.
19 import experimental_framework.benchmarks.\
20 instantiation_validation_noisy_neighbors_benchmark as mut
23 class InstantiationValidationInitTest(unittest.TestCase):
26 name = 'instantiation_validation_noisy'
27 params = {'param': 'value'}
29 InstantiationValidationNoisyNeighborsBenchmark(name, params)
34 @mock.patch('experimental_framework.benchmarks.'
35 'instantiation_validation_benchmark.'
36 'InstantiationValidationBenchmark')
37 @mock.patch('experimental_framework.common.get_template_dir')
38 def test___init___for_success(self, mock_get_template_dir,
39 mock_instant_validation):
40 mock_get_template_dir.return_value = '/directory/'
41 name = 'instantiation_validation_noisy'
42 params = {'param': 'value'}
43 obj = mut.InstantiationValidationNoisyNeighborsBenchmark(name, params)
44 self.assertEqual(obj.template_file, '/directory/stress_workload.yaml')
45 self.assertEqual(obj.stack_name, 'neighbour')
46 self.assertEqual(obj.neighbor_stack_names, list())
48 def test_get_features_for_success(self):
50 expected['description'] = 'Instantiation Validation Benchmark with ' \
52 expected['parameters'] = list()
53 expected['allowed_values'] = dict()
54 expected['default_values'] = dict()
55 expected['parameters'].append('throughput')
56 expected['parameters'].append('vlan_sender')
57 expected['parameters'].append('vlan_receiver')
58 expected['parameters'].append(mut.NUM_OF_NEIGHBORS)
59 expected['parameters'].append(mut.AMOUNT_OF_RAM)
60 expected['parameters'].append(mut.NUMBER_OF_CORES)
61 expected['allowed_values']['throughput'] = map(str, range(0, 100))
62 expected['allowed_values']['vlan_sender'] = map(str, range(-1, 4096))
63 expected['allowed_values']['vlan_receiver'] = map(str, range(-1, 4096))
64 expected['allowed_values'][mut.NUM_OF_NEIGHBORS] = \
65 ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
66 expected['allowed_values'][mut.NUMBER_OF_CORES] = \
67 ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
68 expected['allowed_values'][mut.AMOUNT_OF_RAM] = \
69 ['250M', '1G', '2G', '3G', '4G', '5G', '6G', '7G', '8G', '9G',
71 expected['default_values']['throughput'] = '1'
72 expected['default_values']['vlan_sender'] = '-1'
73 expected['default_values']['vlan_receiver'] = '-1'
74 expected['default_values'][mut.NUM_OF_NEIGHBORS] = '1'
75 expected['default_values'][mut.NUMBER_OF_CORES] = '1'
76 expected['default_values'][mut.AMOUNT_OF_RAM] = '250M'
77 output = self.iv.get_features()
78 self.assertEqual(expected['description'], output['description'])
80 for item in output['parameters']:
81 self.assertIn(item, expected['parameters'])
82 for key in output['allowed_values'].keys():
83 self.assertEqual(expected['allowed_values'][key],
84 output['allowed_values'][key])
85 for key in output['default_values'].keys():
86 self.assertEqual(expected['default_values'][key],
87 output['default_values'][key])
89 @mock.patch('experimental_framework.common.replace_in_file')
90 @mock.patch('experimental_framework.common.'
91 'DEPLOYMENT_UNIT.deploy_heat_template')
92 def test_init_for_success(self, mock_deploy_heat, mock_replace):
93 self.iv.lua_file = 'file'
94 self.iv.results_file = 'res_file'
95 self.iv.params = {'number_of_cores': 1,
97 'num_of_neighbours': 1}
98 self.iv.template_file = 'template.yaml'
100 mock_replace.assert_called_once_wih('file',
101 'local out_file = ""',
102 'local out_file = "' +
104 mock_deploy_heat.assert_called_once_with('template.yaml',
106 {'cores': 1, 'memory': 1})
107 self.assertEqual(self.iv.neighbor_stack_names, ['neighbour0'])
109 @mock.patch('experimental_framework.common.replace_in_file')
110 @mock.patch('experimental_framework.common.'
111 'DEPLOYMENT_UNIT.destroy_heat_template')
112 def test_finalize_for_success(self, mock_heat_destroy, mock_replace):
113 self.iv.neighbor_stack_names = ['neighbor0']
114 stack_name = 'neighbor0'
116 mock_heat_destroy.assert_called_once_with(stack_name)
117 mock_replace.assert_called_once_wih('file',
118 'local out_file = ""',
119 'local out_file = "' +
121 self.assertEqual(self.iv.neighbor_stack_names, list())