Merge "BugFix: update to paramiko 1.18.0 to fix TypeError"
[yardstick.git] / yardstick / vTC / apexlake / tests / instantiation_validation_noisy_bench_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 from __future__ import absolute_import
16 import unittest
17 import mock
18
19 from six.moves import range
20
21 import experimental_framework.common as common
22 import experimental_framework.deployment_unit as deploy
23 import experimental_framework.benchmarks.\
24     instantiation_validation_noisy_neighbors_benchmark as mut
25 from experimental_framework import APEX_LAKE_ROOT
26
27
28 class InstantiationValidationInitTest(unittest.TestCase):
29
30     def setUp(self):
31         name = 'instantiation_validation_noisy'
32         params = {'param': 'value'}
33         openstack_credentials = dict()
34         openstack_credentials['ip_controller'] = ''
35         openstack_credentials['project'] = ''
36         openstack_credentials['auth_uri'] = ''
37         openstack_credentials['user'] = ''
38         openstack_credentials['heat_url'] = ''
39         openstack_credentials['password'] = ''
40         common.DEPLOYMENT_UNIT = deploy.DeploymentUnit(openstack_credentials)
41         common.BASE_DIR = APEX_LAKE_ROOT
42         common.TEMPLATE_DIR = 'tests/data/generated_templates'
43         self.iv = mut.\
44             InstantiationValidationNoisyNeighborsBenchmark(name, params)
45
46     def tearDown(self):
47         common.BASE_DIR = None
48         common.TEMPLATE_DIR = None
49
50     @mock.patch('experimental_framework.benchmarks.'
51                 'instantiation_validation_benchmark.'
52                 'InstantiationValidationBenchmark')
53     @mock.patch('experimental_framework.common.get_template_dir')
54     def test___init___for_success(self, mock_get_template_dir,
55                                   mock_instant_validation):
56         mock_get_template_dir.return_value = '/directory/'
57         name = 'instantiation_validation_noisy'
58         params = {'param': 'value'}
59         obj = mut.InstantiationValidationNoisyNeighborsBenchmark(name, params)
60         self.assertEqual(obj.template_file, '/directory/stress_workload.yaml')
61         self.assertEqual(obj.stack_name, 'neighbour')
62         self.assertEqual(obj.neighbor_stack_names, list())
63
64     def test_get_features_for_success(self):
65         expected = dict()
66         expected['description'] = 'Instantiation Validation Benchmark with ' \
67                                   'noisy neghbors'
68         expected['parameters'] = list()
69         expected['allowed_values'] = dict()
70         expected['default_values'] = dict()
71         expected['parameters'].append('throughput')
72         expected['parameters'].append('vlan_sender')
73         expected['parameters'].append('vlan_receiver')
74         expected['parameters'].append('network')
75         expected['parameters'].append('subnet')
76         expected['parameters'].append(mut.NUM_OF_NEIGHBORS)
77         expected['parameters'].append(mut.AMOUNT_OF_RAM)
78         expected['parameters'].append(mut.NUMBER_OF_CORES)
79         expected['allowed_values']['throughput'] = [str(x) for x in range(100)]
80         expected['allowed_values']['vlan_sender'] = [str(x) for x in
81                                                      range(-1, 4096)]
82         expected['allowed_values']['vlan_receiver'] = [str(x) for x in
83                                                        range(-1, 4096)]
84         expected['allowed_values'][mut.NUM_OF_NEIGHBORS] = \
85             ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
86         expected['allowed_values'][mut.NUMBER_OF_CORES] = \
87             ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
88         expected['allowed_values'][mut.AMOUNT_OF_RAM] = \
89             ['256M', '1G', '2G', '3G', '4G', '5G', '6G', '7G', '8G', '9G',
90              '10G']
91         expected['default_values']['throughput'] = '1'
92         expected['default_values']['vlan_sender'] = '-1'
93         expected['default_values']['vlan_receiver'] = '-1'
94         expected['default_values']['network'] = ''
95         expected['default_values']['subnet'] = ''
96         expected['default_values'][mut.NUM_OF_NEIGHBORS] = '1'
97         expected['default_values'][mut.NUMBER_OF_CORES] = '1'
98         expected['default_values'][mut.AMOUNT_OF_RAM] = '256M'
99         output = self.iv.get_features()
100         self.assertEqual(expected['description'], output['description'])
101
102         for item in output['parameters']:
103             self.assertIn(item, expected['parameters'])
104         for key in output['allowed_values'].keys():
105             self.assertEqual(expected['allowed_values'][key],
106                              output['allowed_values'][key])
107         for key in output['default_values'].keys():
108             self.assertEqual(expected['default_values'][key],
109                              output['default_values'][key])
110
111     @mock.patch('experimental_framework.common.replace_in_file')
112     @mock.patch('experimental_framework.common.'
113                 'DEPLOYMENT_UNIT.deploy_heat_template')
114     def test_init_for_success(self, mock_deploy_heat, mock_replace):
115         self.iv.lua_file = 'file'
116         self.iv.results_file = 'res_file'
117         self.iv.params = {'number_of_cores': 1,
118                           'amount_of_ram': 1,
119                           'network': 1,
120                           'subnet': 1,
121                           'num_of_neighbours': 1}
122         self.iv.template_file = 'template.yaml'
123         self.iv.init()
124         mock_replace.assert_called_once_with('file',
125                                              'local out_file = ""',
126                                              'local out_file = "' +
127                                              'res_file' + '"')
128         mock_deploy_heat.assert_called_once_with('template.yaml',
129                                                  'neighbour0',
130                                                  {'cores': 1,
131                                                   'memory': 1,
132                                                   'network': 1,
133                                                   'subnet': 1})
134         self.assertEqual(self.iv.neighbor_stack_names, ['neighbour0'])
135
136     @mock.patch('experimental_framework.common.replace_in_file')
137     @mock.patch('experimental_framework.common.'
138                 'DEPLOYMENT_UNIT.destroy_heat_template')
139     def test_finalize_for_success(self, mock_heat_destroy, mock_replace):
140         self.iv.lua_file = 'file'
141         self.iv.results_file = 'res_file'
142         self.iv.neighbor_stack_names = ['neighbor0']
143         stack_name = 'neighbor0'
144         self.iv.finalize()
145         mock_heat_destroy.assert_called_once_with(stack_name)
146         mock_replace.assert_called_once_with('file',
147                                              'local out_file = "' +
148                                              'res_file' + '"',
149                                              'local out_file = ""')
150         self.assertEqual(self.iv.neighbor_stack_names, list())