3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 """Test module for orchestra_ims"""
15 from functest.core import vnf
16 from functest.opnfv_tests.vnf.ims import orchestra_ims
19 class OrchestraImsTesting(unittest.TestCase):
20 """Test class for orchestra_ims"""
23 self.tenant = 'orchestra_ims'
24 self.creds = {'username': 'mocked_username',
25 'password': 'mocked_password'}
26 self.tenant_images = {
27 'image1': 'mocked_image_url_1',
28 'image2': 'mocked_image_url_2'
36 'name': 'mocked_flavor',
41 'os_image': 'mocked_image'
44 'url': 'mocked_bootstrap_url',
46 'url': 'mocked_config_url'}
50 'url': 'mocked_userdata_url'
54 'username': 'mocked_username',
55 'password': 'mocked_password'
61 'url': 'mocked_descriptor_url'
65 'name': 'mocked_flavor',
88 with mock.patch('functest.opnfv_tests.vnf.ims.orchestra_ims.'
90 mock.patch('functest.opnfv_tests.vnf.ims.orchestra_ims.'
91 'get_config', return_value={
92 'orchestrator': self.orchestrator,
93 'name': self.orchestrator['name'],
94 'version': self.orchestrator['version'],
95 'requirements': self.orchestrator['requirements'],
96 'credentials': self.orchestrator['credentials'],
97 'bootstrap': self.orchestrator['bootstrap'],
98 'gvnfm': self.orchestrator['gvnfm'],
100 self.orchestrator['requirements']['os_image'],
102 self.orchestrator['requirements']['flavor'],
103 'url': self.orchestrator['bootstrap']['url'],
104 'config': self.orchestrator['bootstrap']['config'],
105 'tenant_images': self.tenant_images,
108 self.ims_vnf = orchestra_ims.ImsVnf()
110 self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
114 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
116 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
118 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
120 @mock.patch('functest.core.vnf.os_utils.get_credentials',
121 return_value={'auth_url': 'test/v1'})
123 'functest.utils.openstack_utils.get_tenant_id',
124 return_value={'mocked_tenant_id'})
126 'functest.utils.openstack_utils.get_floating_ips',
128 @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
129 @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create')
131 'snaps.openstack.create_security_group.OpenStackSecurityGroup.create')
132 @mock.patch('snaps.openstack.create_network.OpenStackNetwork.create')
133 @mock.patch('snaps.openstack.create_router.OpenStackRouter.create')
135 'functest.opnfv_tests.openstack.snaps.snaps_utils.get_ext_net_name')
137 'functest.opnfv_tests.openstack.snaps.snaps_utils.'
138 'neutron_utils.create_floating_ip')
139 def test_prepare_default(self, *args):
140 """Testing prepare function without any exceptions expected"""
141 self.assertIsNone(self.ims_vnf.prepare())
142 args[4].assert_called_once_with()
144 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
146 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
148 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
150 @mock.patch('functest.core.vnf.os_utils.get_credentials',
151 return_value={'auth_url': 'test/no_v'})
152 @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
153 def test_prepare_bad_auth_url(self, *args):
154 """Testing prepare function with bad auth url"""
155 with self.assertRaises(Exception):
156 self.ims_vnf.prepare()
157 args[0].assert_not_called()
159 def test_prepare_missing_param(self):
160 """Testing prepare function with missing param"""
161 with self.assertRaises(vnf.VnfPreparationException):
162 self.ims_vnf.prepare()
164 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
165 side_effect=Exception)
166 def test_prepare_keystone_exception(self, *args):
167 """Testing prepare function with keystone exception"""
168 with self.assertRaises(vnf.VnfPreparationException):
169 self.ims_vnf.prepare()
170 args[0].assert_called_once_with()
172 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
174 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
175 side_effect=Exception)
176 def test_prepare_tenant_exception(self, *args):
177 """Testing prepare function with tenant exception"""
178 with self.assertRaises(vnf.VnfPreparationException):
179 self.ims_vnf.prepare()
180 args[1].assert_called_once_with()
182 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
184 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
186 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
187 side_effect=Exception)
188 def test_prepare_user_exception(self, *args):
189 """Testing prepare function with user exception"""
190 with self.assertRaises(vnf.VnfPreparationException):
191 self.ims_vnf.prepare()
192 args[2].assert_called_once_with()
194 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
196 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
198 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
200 @mock.patch('functest.core.vnf.os_utils.get_credentials',
201 side_effect=Exception)
202 def test_prepare_credentials_exception(self, *args):
203 """Testing prepare function with credentials exception"""
204 with self.assertRaises(vnf.VnfPreparationException):
205 self.ims_vnf.prepare()
206 args[0].assert_called_once_with()
208 # # @mock.patch('functest.opnfv_tests.vnf.ims.orchestra_ims.get_userdata')
209 # def test_deploy_orchestrator(self, *args):
210 # floating_ip = FloatingIp
211 # floating_ip.ip = 'mocked_ip'
212 # details = {'fip':floating_ip,'flavor':{'name':'mocked_name'}}
213 # self.orchestrator['details'] = details
214 # with mock.patch.dict(self.orchestrator, {'details':
215 # {'fip':floating_ip,'flavor':{'name':'mocked_name'}}}):
216 # # with mock.patch.dict(self.orchestrator, details):
217 # orchestra_ims.get_userdata(self.orchestrator)
218 # self.assertIsNone(self.ims_vnf.deploy_orchestrator())
219 # args[4].assert_called_once_with()
222 if __name__ == "__main__":
223 logging.disable(logging.CRITICAL)
224 unittest.main(verbosity=2)