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_clearwaterims"""
14 from snaps.openstack.os_credentials import OSCreds
16 from functest.core import vnf
17 from functest.opnfv_tests.vnf.ims import orchestra_clearwaterims
20 class OrchestraClearwaterImsTesting(unittest.TestCase):
21 """Test class for orchestra_clearwaterims"""
24 self.tenant = 'orchestra_clearwaterims'
25 self.creds = {'username': 'mocked_username',
26 'password': 'mocked_password'}
27 self.tenant_images = {
28 'image1': 'mocked_image_url_1',
29 'image2': 'mocked_image_url_2'
37 'name': 'mocked_flavor',
42 'os_image': 'mocked_image'
45 'url': 'mocked_bootstrap_url',
47 'url': 'mocked_config_url'}
51 'url': 'mocked_userdata_url'
55 'username': 'mocked_username',
56 'password': 'mocked_password'
62 'url': 'mocked_descriptor_url'
66 'name': 'mocked_flavor',
72 self.clearwaterims = {
89 with mock.patch('functest.opnfv_tests.vnf.ims.orchestra_clearwaterims.'
91 mock.patch('functest.opnfv_tests.vnf.ims.orchestra_clearwaterims.'
92 'get_config', return_value={
93 'orchestrator': self.mano,
94 'name': self.mano['name'],
95 'version': self.mano['version'],
96 'requirements': self.mano['requirements'],
97 'credentials': self.mano['credentials'],
98 'bootstrap': self.mano['bootstrap'],
99 'gvnfm': self.mano['gvnfm'],
100 'os_image': self.mano['requirements']['os_image'],
101 'flavor': self.mano['requirements']['flavor'],
102 'url': self.mano['bootstrap']['url'],
103 'config': self.mano['bootstrap']['config'],
104 'tenant_images': self.tenant_images,
106 'orchestra_clearwaterims': self.clearwaterims}):
107 self.ims_vnf = orchestra_clearwaterims.ClearwaterImsVnf()
109 self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
113 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
115 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
117 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
119 @mock.patch('functest.core.vnf.os_utils.get_credentials',
120 return_value={'auth_url': 'test/v1'})
122 'functest.utils.openstack_utils.get_tenant_id',
123 return_value={'mocked_tenant_id'})
125 'functest.utils.openstack_utils.get_floating_ips',
127 @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
128 @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create')
130 'snaps.openstack.create_security_group.OpenStackSecurityGroup.create')
131 @mock.patch('snaps.openstack.create_network.OpenStackNetwork.create')
132 @mock.patch('snaps.openstack.create_router.OpenStackRouter.create')
134 'functest.opnfv_tests.openstack.snaps.snaps_utils.get_ext_net_name')
136 'functest.opnfv_tests.openstack.snaps.'
137 'snaps_utils.neutron_utils.create_floating_ip')
138 def test_prepare_default(self, *args):
139 """Testing prepare function without any exceptions expected"""
140 self.assertIsNone(self.ims_vnf.prepare())
141 args[4].assert_called_once_with()
143 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
145 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
147 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
149 @mock.patch('functest.core.vnf.os_utils.get_credentials',
150 return_value={'auth_url': 'test/no_v'})
151 @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
152 def test_prepare_bad_auth_url(self, *args):
153 """Testing prepare function with bad auth url"""
154 with self.assertRaises(Exception):
155 self.ims_vnf.image_creator(
156 OSCreds(username='user', password='pass', auth_url='url',
157 project_name='project', identity_api_version=3),
159 args[0].assert_not_called()
161 def test_prepare_missing_param(self):
162 """Testing prepare function with missing param"""
163 with self.assertRaises(vnf.VnfPreparationException):
164 self.ims_vnf.prepare()
166 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
167 side_effect=Exception)
168 def test_prepare_keystone_exception(self, *args):
169 """Testing prepare function with keystone exception"""
170 with self.assertRaises(vnf.VnfPreparationException):
171 self.ims_vnf.prepare()
172 args[0].assert_called_once_with()
174 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
176 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
177 side_effect=Exception)
178 def test_prepare_tenant_exception(self, *args):
179 """Testing prepare function with tenant exception"""
180 with self.assertRaises(vnf.VnfPreparationException):
181 self.ims_vnf.prepare()
182 args[1].assert_called_once_with()
184 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
186 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
188 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
189 side_effect=Exception)
190 def test_prepare_user_exception(self, *args):
191 """Testing prepare function with user exception"""
192 with self.assertRaises(vnf.VnfPreparationException):
193 self.ims_vnf.prepare()
194 args[2].assert_called_once_with()
196 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
198 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
200 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
202 @mock.patch('functest.core.vnf.os_utils.get_credentials',
203 side_effect=Exception)
204 def test_prepare_credentials_exception(self, *args):
205 """Testing prepare function with credentials exception"""
206 with self.assertRaises(vnf.VnfPreparationException):
207 self.ims_vnf.prepare()
208 args[0].assert_called_once_with()
210 # # @mock.patch('functest.opnfv_tests.vnf.
211 # ims.orchestra_clearwaterims.get_userdata')
212 # def test_deploy_orchestrator(self, *args):
213 # floating_ip = FloatingIp
214 # floating_ip.ip = 'mocked_ip'
215 # details = {'fip':floating_ip,'flavor':{'name':'mocked_name'}}
216 # self.mano['details'] = details
217 # with mock.patch.dict(self.mano, {'details':
218 # {'fip':floating_ip,'flavor':{'name':'mocked_name'}}}):
219 # # with mock.patch.dict(self.mano, details):
220 # orchestra_clearwaterims.get_userdata(self.mano)
221 # self.assertIsNone(self.ims_vnf.deploy_orchestrator())
222 # args[4].assert_called_once_with()
225 if __name__ == "__main__":
226 logging.disable(logging.CRITICAL)
227 unittest.main(verbosity=2)