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
13 from functest.core import vnf
14 from functest.opnfv_tests.vnf.ims import cloudify_ims
16 from snaps.openstack.os_credentials import OSCreds
19 class CloudifyImsTesting(unittest.TestCase):
23 self.tenant = 'cloudify_ims'
24 self.creds = {'username': 'user',
26 self.orchestrator = {'name': 'cloudify',
29 'requirements': {'flavor': {'name': 'm1.medium',
31 'os_image': 'manager_4.0'}}
33 self.vnf = {'name': 'clearwater',
34 'descriptor': {'version': '108',
35 'file_name': 'openstack-blueprint.yaml',
36 'name': 'clearwater-opnfv',
38 'requirements': {'flavor':
42 with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
44 mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
45 'get_config', return_value={
46 'tenant_images': 'foo',
47 'orchestrator': self.orchestrator,
50 'version': 'whatever'}):
52 self.ims_vnf = cloudify_ims.CloudifyIms()
54 self.images = {'image1': 'url1',
56 self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
60 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
62 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
64 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
66 @mock.patch('functest.core.vnf.os_utils.get_credentials',
67 return_value={'auth_url': 'test/v1'})
68 @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
69 def test_prepare_default(self, *args):
70 self.assertIsNone(self.ims_vnf.prepare())
71 args[4].assert_called_once_with()
73 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
75 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
77 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
79 @mock.patch('functest.core.vnf.os_utils.get_credentials',
80 return_value={'auth_url': 'test/no_v'})
81 @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
82 def test_prepare_bad_auth_url(self, *args):
83 with self.assertRaises(Exception):
84 self.ims_vnf.image_creator(
85 OSCreds(username='user', password='pass', auth_url='url',
86 project_name='project', identity_api_version=3),
88 args[0].assert_not_called()
90 def test_prepare_missing_param(self):
91 with self.assertRaises(vnf.VnfPreparationException):
92 self.ims_vnf.prepare()
94 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
95 side_effect=Exception)
96 def test_prepare_keystone_exception(self, *args):
97 with self.assertRaises(vnf.VnfPreparationException):
98 self.ims_vnf.prepare()
99 args[0].assert_called_once_with()
101 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
103 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
104 side_effect=Exception)
105 def test_prepare_tenant_exception(self, *args):
106 with self.assertRaises(vnf.VnfPreparationException):
107 self.ims_vnf.prepare()
108 args[1].assert_called_once_with()
110 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
112 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
114 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
115 side_effect=Exception)
116 def test_prepare_user_exception(self, *args):
117 with self.assertRaises(vnf.VnfPreparationException):
118 self.ims_vnf.prepare()
119 args[2].assert_called_once_with()
121 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
123 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
125 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
127 @mock.patch('functest.core.vnf.os_utils.get_credentials',
128 side_effect=Exception)
129 def test_prepare_credentials_exception(self, *args):
130 with self.assertRaises(vnf.VnfPreparationException):
131 self.ims_vnf.prepare()
132 args[0].assert_called_once_with()
134 # @mock.patch('snaps.openstack.create_keypairs.OpenStackKeypair',
135 # side_effect=Exception)
136 # def test_deploy_orchestrator_keypair_exception(self, *args):
137 # with self.assertRaises(vnf.OrchestratorDeploymentException):
138 # self.ims_vnf.deploy_orchestrator()
140 # def test_deploy_orchestrator_network_creation_fail(self):
141 # def test_deploy_orchestrator_floatting_ip_creation_fail(self):
142 # def test_deploy_orchestrator_flavor_fail(self):
143 # def test_deploy_orchestrator_get_image_id_fail(self):
144 # def test_deploy_orchestrator_create_instance_fail(self):
145 # def test_deploy_orchestrator_secgroup_fail(self):
146 # def test_deploy_orchestrator_add_floating_ip_fail(self):
147 # def test_deploy_orchestrator_get_endpoint_fail(self):
148 # def test_deploy_orchestrator_initiate CloudifyClient_fail(self):
149 # def test_deploy_orchestrator_get_status_fail(self):
152 # def test_deploy_vnf(self):
153 # def test_deploy_vnf_publish_fail(self):
154 # def test_deploy_vnf_get_flavor_fail(self):
155 # def test_deploy_vnf_get_external_net_fail(self):
156 # def test_deploy_vnf_deployment_create_fail(self):
157 # def test_deploy_vnf_start_fail(self):
159 # def test_test_vnf(self):
160 # def test_test_vnf_deployment_get_fail(self):
161 # def test_test_vnf_run_live_test_fail(self):
163 # def test_clean(self):
164 # def test_clean_execution_start_fail(self):
165 # def test_clean_deployment_delete_fail(self):
166 # def test_clean_blueprint_delete_fail(self):
169 if __name__ == "__main__":
170 logging.disable(logging.CRITICAL)
171 unittest.main(verbosity=2)