Convert files to Unix format
[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
17 class CloudifyImsTesting(unittest.TestCase):
18
19     def setUp(self):
20
21         self.tenant = 'cloudify_ims'
22         self.creds = {'username': 'user',
23                       'password': 'pwd'}
24         self.orchestrator = {'name': 'cloudify',
25                              'version': '4.0',
26                              'object': 'foo',
27                              'requirements': {'flavor': {'name': 'm1.medium',
28                                                          'ram_min': 4096},
29                                               'os_image': 'manager_4.0'}}
30
31         self.vnf = {'name': 'clearwater',
32                     'descriptor': {'version': '108',
33                                    'file_name': 'openstack-blueprint.yaml',
34                                    'name': 'clearwater-opnfv',
35                                    'url': 'https://foo',
36                                    'requirements': {'flavor':
37                                                     {'name': 'm1.medium',
38                                                      'ram_min': 2048}}}}
39
40         with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
41                         'os.makedirs'), \
42             mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
43                        'get_config', return_value={
44                            'tenant_images': 'foo',
45                            'orchestrator': self.orchestrator,
46                            'vnf': self.vnf,
47                            'vnf_test_suite': '',
48                            'version': 'whatever'}):
49
50             self.ims_vnf = cloudify_ims.CloudifyIms()
51
52         self.images = {'image1': 'url1',
53                        'image2': 'url2'}
54         self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
55                         'vnf': {},
56                         'test_vnf':  {}}
57
58     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
59                 return_value='test')
60     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
61                 return_value=True)
62     @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
63                 return_value=True)
64     @mock.patch('functest.core.vnf.os_utils.get_credentials',
65                 return_value={'auth_url': 'test/v1'})
66     @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
67     def test_prepare_default(self, *args):
68         self.assertIsNone(self.ims_vnf.prepare())
69         args[4].assert_called_once_with()
70
71     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
72                 return_value='test')
73     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
74                 return_value=True)
75     @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
76                 return_value=True)
77     @mock.patch('functest.core.vnf.os_utils.get_credentials',
78                 return_value={'auth_url': 'test/no_v'})
79     @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
80     def test_prepare_bad_auth_url(self, *args):
81         with self.assertRaises(Exception):
82             self.ims_vnf.prepare()
83         args[0].assert_not_called()
84
85     def test_prepare_missing_param(self):
86         with self.assertRaises(vnf.VnfPreparationException):
87             self.ims_vnf.prepare()
88
89     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
90                 side_effect=Exception)
91     def test_prepare_keystone_exception(self, *args):
92         with self.assertRaises(vnf.VnfPreparationException):
93             self.ims_vnf.prepare()
94         args[0].assert_called_once_with()
95
96     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
97                 return_value='test')
98     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
99                 side_effect=Exception)
100     def test_prepare_tenant_exception(self, *args):
101         with self.assertRaises(vnf.VnfPreparationException):
102             self.ims_vnf.prepare()
103         args[1].assert_called_once_with()
104
105     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
106                 return_value='test')
107     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
108                 return_value=True)
109     @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
110                 side_effect=Exception)
111     def test_prepare_user_exception(self, *args):
112         with self.assertRaises(vnf.VnfPreparationException):
113             self.ims_vnf.prepare()
114         args[2].assert_called_once_with()
115
116     @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
117                 return_value='test')
118     @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
119                 return_value=True)
120     @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
121                 return_value=True)
122     @mock.patch('functest.core.vnf.os_utils.get_credentials',
123                 side_effect=Exception)
124     def test_prepare_credentials_exception(self, *args):
125         with self.assertRaises(vnf.VnfPreparationException):
126             self.ims_vnf.prepare()
127         args[0].assert_called_once_with()
128
129     # @mock.patch('snaps.openstack.create_keypairs.OpenStackKeypair',
130     #             side_effect=Exception)
131     # def test_deploy_orchestrator_keypair_exception(self, *args):
132     #    with self.assertRaises(vnf.OrchestratorDeploymentException):
133     #        self.ims_vnf.deploy_orchestrator()
134
135     #   def test_deploy_orchestrator_network_creation_fail(self):
136     #   def test_deploy_orchestrator_floatting_ip_creation_fail(self):
137     #   def test_deploy_orchestrator_flavor_fail(self):
138     #   def test_deploy_orchestrator_get_image_id_fail(self):
139     #   def test_deploy_orchestrator_create_instance_fail(self):
140     #   def test_deploy_orchestrator_secgroup_fail(self):
141     #   def test_deploy_orchestrator_add_floating_ip_fail(self):
142     #   def test_deploy_orchestrator_get_endpoint_fail(self):
143     #   def test_deploy_orchestrator_initiate CloudifyClient_fail(self):
144     #   def test_deploy_orchestrator_get_status_fail(self):
145     #
146
147     #   def test_deploy_vnf(self):
148     #   def test_deploy_vnf_publish_fail(self):
149     #   def test_deploy_vnf_get_flavor_fail(self):
150     #   def test_deploy_vnf_get_external_net_fail(self):
151     #   def test_deploy_vnf_deployment_create_fail(self):
152     #   def test_deploy_vnf_start_fail(self):
153     #
154     #   def test_test_vnf(self):
155     #   def test_test_vnf_deployment_get_fail(self):
156     #   def test_test_vnf_run_live_test_fail(self):
157     #
158     #   def test_clean(self):
159     #   def test_clean_execution_start_fail(self):
160     #   def test_clean_deployment_delete_fail(self):
161     #   def test_clean_blueprint_delete_fail(self):
162
163
164 if __name__ == "__main__":
165     logging.disable(logging.CRITICAL)
166     unittest.main(verbosity=2)