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.
18 import experimental_framework.common as common
19 import experimental_framework.deployment_unit as deploy
20 import experimental_framework.benchmarks.\
21 instantiation_validation_noisy_neighbors_benchmark as mut
24 class InstantiationValidationInitTest(unittest.TestCase):
27 name = 'instantiation_validation_noisy'
28 params = {'param': 'value'}
29 openstack_credentials = dict()
30 openstack_credentials['ip_controller'] = ''
31 openstack_credentials['project'] = ''
32 openstack_credentials['auth_uri'] = ''
33 openstack_credentials['user'] = ''
34 openstack_credentials['heat_url'] = ''
35 openstack_credentials['password'] = ''
36 common.DEPLOYMENT_UNIT = deploy.DeploymentUnit(openstack_credentials)
37 common.BASE_DIR = os.getcwd()
38 common.TEMPLATE_DIR = 'tests/data/generated_templates'
40 InstantiationValidationNoisyNeighborsBenchmark(name, params)
43 common.BASE_DIR = None
44 common.TEMPLATE_DIR = None
46 @mock.patch('experimental_framework.benchmarks.'
47 'instantiation_validation_benchmark.'
48 'InstantiationValidationBenchmark')
49 @mock.patch('experimental_framework.common.get_template_dir')
50 def test___init___for_success(self, mock_get_template_dir,
51 mock_instant_validation):
52 mock_get_template_dir.return_value = '/directory/'
53 name = 'instantiation_validation_noisy'
54 params = {'param': 'value'}
55 obj = mut.InstantiationValidationNoisyNeighborsBenchmark(name, params)
56 self.assertEqual(obj.template_file, '/directory/stress_workload.yaml')
57 self.assertEqual(obj.stack_name, 'neighbour')
58 self.assertEqual(obj.neighbor_stack_names, list())
60 def test_get_features_for_success(self):
62 expected['description'] = 'Instantiation Validation Benchmark with ' \
64 expected['parameters'] = list()
65 expected['allowed_values'] = dict()
66 expected['default_values'] = dict()
67 expected['parameters'].append('throughput')
68 expected['parameters'].append('vlan_sender')
69 expected['parameters'].append('vlan_receiver')
70 expected['parameters'].append(mut.NUM_OF_NEIGHBORS)
71 expected['parameters'].append(mut.AMOUNT_OF_RAM)
72 expected['parameters'].append(mut.NUMBER_OF_CORES)
73 expected['allowed_values']['throughput'] = map(str, range(0, 100))
74 expected['allowed_values']['vlan_sender'] = map(str, range(-1, 4096))
75 expected['allowed_values']['vlan_receiver'] = map(str, range(-1, 4096))
76 expected['allowed_values'][mut.NUM_OF_NEIGHBORS] = \
77 ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
78 expected['allowed_values'][mut.NUMBER_OF_CORES] = \
79 ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
80 expected['allowed_values'][mut.AMOUNT_OF_RAM] = \
81 ['250M', '1G', '2G', '3G', '4G', '5G', '6G', '7G', '8G', '9G',
83 expected['default_values']['throughput'] = '1'
84 expected['default_values']['vlan_sender'] = '-1'
85 expected['default_values']['vlan_receiver'] = '-1'
86 expected['default_values'][mut.NUM_OF_NEIGHBORS] = '1'
87 expected['default_values'][mut.NUMBER_OF_CORES] = '1'
88 expected['default_values'][mut.AMOUNT_OF_RAM] = '250M'
89 output = self.iv.get_features()
90 self.assertEqual(expected['description'], output['description'])
92 for item in output['parameters']:
93 self.assertIn(item, expected['parameters'])
94 for key in output['allowed_values'].keys():
95 self.assertEqual(expected['allowed_values'][key],
96 output['allowed_values'][key])
97 for key in output['default_values'].keys():
98 self.assertEqual(expected['default_values'][key],
99 output['default_values'][key])
101 @mock.patch('experimental_framework.common.replace_in_file')
102 @mock.patch('experimental_framework.common.'
103 'DEPLOYMENT_UNIT.deploy_heat_template')
104 def test_init_for_success(self, mock_deploy_heat, mock_replace):
105 self.iv.lua_file = 'file'
106 self.iv.results_file = 'res_file'
107 self.iv.params = {'number_of_cores': 1,
109 'num_of_neighbours': 1}
110 self.iv.template_file = 'template.yaml'
112 mock_replace.assert_called_once_wih('file',
113 'local out_file = ""',
114 'local out_file = "' +
116 mock_deploy_heat.assert_called_once_with('template.yaml',
118 {'cores': 1, 'memory': 1})
119 self.assertEqual(self.iv.neighbor_stack_names, ['neighbour0'])
121 @mock.patch('experimental_framework.common.replace_in_file')
122 @mock.patch('experimental_framework.common.'
123 'DEPLOYMENT_UNIT.destroy_heat_template')
124 def test_finalize_for_success(self, mock_heat_destroy, mock_replace):
125 self.iv.neighbor_stack_names = ['neighbor0']
126 stack_name = 'neighbor0'
128 mock_heat_destroy.assert_called_once_with(stack_name)
129 mock_replace.assert_called_once_wih('file',
130 'local out_file = ""',
131 'local out_file = "' +
133 self.assertEqual(self.iv.neighbor_stack_names, list())