3 # Copyright (c) 2017 Okinawa Open Laboratory and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
15 from functest.core import vnf
16 from functest.opnfv_tests.vnf.router import cloudify_vrouter
18 from snaps.openstack.os_credentials import OSCreds
21 class CloudifyVrouterTesting(unittest.TestCase):
25 self.tenant = 'cloudify_vrouter'
26 self.creds = {'username': 'user',
28 self.orchestrator = {'name': 'cloudify',
31 'requirements': {'flavor': {'name': 'm1.medium',
33 'os_image': 'manager_4.0'}}
35 self.vnf = {'name': 'vrouter',
36 'descriptor': {'version': '100',
37 'file_name': 'function-test-' +
38 'openstack-blueprint.yaml',
39 'name': 'vrouter-opnfv',
41 'requirements': {'flavor':
45 with mock.patch('functest.opnfv_tests.vnf.router.cloudify_vrouter.'
47 mock.patch('functest.opnfv_tests.vnf.router.cloudify_vrouter.'
48 'get_config', return_value={
49 'tenant_images': 'foo',
50 'orchestrator': self.orchestrator,
53 'version': 'whatever'}):
55 self.router_vnf = cloudify_vrouter.CloudifyVrouter()
57 self.images = {'image1': 'url1',
59 self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
63 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
65 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
67 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
69 @mock.patch('functest.core.vnf.os_utils.get_credentials',
70 return_value={'auth_url': 'test/v1'})
71 @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
72 def test_prepare_default(self, *args):
73 self.assertIsNone(self.router_vnf.prepare())
74 args[4].assert_called_once_with()
76 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
78 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
80 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
82 @mock.patch('functest.core.vnf.os_utils.get_credentials',
83 return_value={'auth_url': 'test/no_v'})
84 @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
85 def test_prepare_bad_auth_url(self, *args):
86 with self.assertRaises(Exception):
87 self.router_vnf.image_creator(
88 OSCreds(username='user', password='pass', auth_url='url',
89 project_name='project', identity_api_version=3),
91 args[0].assert_not_called()
93 def test_prepare_missing_param(self):
94 with self.assertRaises(vnf.VnfPreparationException):
95 self.router_vnf.prepare()
97 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
98 side_effect=Exception)
99 def test_prepare_keystone_exception(self, *args):
100 with self.assertRaises(vnf.VnfPreparationException):
101 self.router_vnf.prepare()
102 args[0].assert_called_once_with()
104 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
106 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
107 side_effect=Exception)
108 def test_prepare_tenant_exception(self, *args):
109 with self.assertRaises(vnf.VnfPreparationException):
110 self.router_vnf.prepare()
111 args[1].assert_called_once_with()
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',
118 side_effect=Exception)
119 def test_prepare_user_exception(self, *args):
120 with self.assertRaises(vnf.VnfPreparationException):
121 self.router_vnf.prepare()
122 args[2].assert_called_once_with()
124 @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
126 @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
128 @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
130 @mock.patch('functest.core.vnf.os_utils.get_credentials',
131 side_effect=Exception)
132 def test_prepare_credentials_exception(self, *args):
133 with self.assertRaises(vnf.VnfPreparationException):
134 self.router_vnf.prepare()
135 args[0].assert_called_once_with()
138 if __name__ == "__main__":
139 logging.disable(logging.CRITICAL)
140 unittest.main(verbosity=2)