Merge "Remove rnc unit test dir as empty"
[functest.git] / functest / tests / unit / vnf / ims / test_cloudify_ims.py
1 #!/usr/bin/env python
2
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
7
8 import logging
9 import unittest
10
11 import mock
12
13 from functest.core import vnf
14 from functest.opnfv_tests.vnf.ims import cloudify_ims
15
16 from snaps.openstack.os_credentials import OSCreds
17
18
19 class CloudifyImsTesting(unittest.TestCase):
20
21     def setUp(self):
22
23         self.tenant = 'cloudify_ims'
24         self.creds = {'username': 'user',
25                       'password': 'pwd'}
26         self.orchestrator = {'name': 'cloudify',
27                              'version': '4.0',
28                              'object': 'foo',
29                              'requirements': {'flavor': {'name': 'm1.medium',
30                                                          'ram_min': 4096},
31                                               'os_image': 'manager_4.0'}}
32
33         self.vnf = {'name': 'clearwater',
34                     'descriptor': {'version': '108',
35                                    'file_name': 'openstack-blueprint.yaml',
36                                    'name': 'clearwater-opnfv',
37                                    'url': 'https://foo',
38                                    'requirements': {'flavor':
39                                                     {'name': 'm1.medium',
40                                                      'ram_min': 2048}}}}
41
42         with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
43                         'os.makedirs'), \
44             mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
45                        'get_config', return_value={
46                            'tenant_images': 'foo',
47                            'orchestrator': self.orchestrator,
48                            'vnf': self.vnf,
49                            'vnf_test_suite': '',
50                            'version': 'whatever'}):
51
52             self.ims_vnf = cloudify_ims.CloudifyIms()
53
54         self.images = {'image1': 'url1',
55                        'image2': 'url2'}
56         self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
57                         'vnf': {},
58                         'test_vnf':  {}}
59
60     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
61                 return_value='test')
62     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
63                 return_value=True)
64     @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
65                 return_value=True)
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()
72
73     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
74                 return_value='test')
75     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
76                 return_value=True)
77     @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
78                 return_value=True)
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),
87                 mock.Mock())
88             args[0].assert_not_called()
89
90     def test_prepare_missing_param(self):
91         with self.assertRaises(vnf.VnfPreparationException):
92             self.ims_vnf.prepare()
93
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()
100
101     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
102                 return_value='test')
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()
109
110     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
111                 return_value='test')
112     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
113                 return_value=True)
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()
120
121     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
122                 return_value='test')
123     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
124                 return_value=True)
125     @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
126                 return_value=True)
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()
133
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()
139
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):
150     #
151
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):
158     #
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):
162     #
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):
167
168
169 if __name__ == "__main__":
170     logging.disable(logging.CRITICAL)
171     unittest.main(verbosity=2)