3 # Copyright (c) 2016 Orange 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
10 # pylint: disable=missing-docstring
17 from functest.core import vnf
18 from functest.core import testcase
19 from functest.utils import constants
21 from snaps.openstack.os_credentials import OSCreds
24 class VnfBaseTesting(unittest.TestCase):
25 """The class testing VNF."""
26 # pylint: disable=missing-docstring,too-many-public-methods
28 tenant_name = 'test_tenant_name'
29 tenant_description = 'description'
32 constants.CONST.__setattr__("vnf_foo_tenant_name", self.tenant_name)
33 constants.CONST.__setattr__(
34 "vnf_foo_tenant_description", self.tenant_description)
35 self.test = vnf.VnfOnBoarding(project='functest', case_name='foo')
37 def test_run_deploy_vnf_exc(self):
38 with mock.patch.object(self.test, 'prepare'),\
39 mock.patch.object(self.test, 'deploy_orchestrator',
41 mock.patch.object(self.test, 'deploy_vnf',
42 side_effect=Exception):
43 self.assertEqual(self.test.run(),
44 testcase.TestCase.EX_TESTCASE_FAILED)
46 def test_run_test_vnf_exc(self):
47 with mock.patch.object(self.test, 'prepare'),\
48 mock.patch.object(self.test, 'deploy_orchestrator',
50 mock.patch.object(self.test, 'deploy_vnf'), \
51 mock.patch.object(self.test, 'test_vnf',
52 side_effect=Exception):
53 self.assertEqual(self.test.run(),
54 testcase.TestCase.EX_TESTCASE_FAILED)
56 def test_run_deploy_orch_ko(self):
57 with mock.patch.object(self.test, 'prepare'),\
58 mock.patch.object(self.test, 'deploy_orchestrator',
59 return_value=False), \
60 mock.patch.object(self.test, 'deploy_vnf',
62 mock.patch.object(self.test, 'test_vnf',
64 self.assertEqual(self.test.run(),
65 testcase.TestCase.EX_TESTCASE_FAILED)
67 def test_run_vnf_deploy_ko(self):
68 with mock.patch.object(self.test, 'prepare'),\
69 mock.patch.object(self.test, 'deploy_orchestrator',
71 mock.patch.object(self.test, 'deploy_vnf',
72 return_value=False), \
73 mock.patch.object(self.test, 'test_vnf',
75 self.assertEqual(self.test.run(),
76 testcase.TestCase.EX_TESTCASE_FAILED)
78 def test_run_vnf_test_ko(self):
79 with mock.patch.object(self.test, 'prepare'),\
80 mock.patch.object(self.test, 'deploy_orchestrator',
82 mock.patch.object(self.test, 'deploy_vnf',
84 mock.patch.object(self.test, 'test_vnf',
86 self.assertEqual(self.test.run(),
87 testcase.TestCase.EX_TESTCASE_FAILED)
89 def test_run_default(self):
90 with mock.patch.object(self.test, 'prepare'),\
91 mock.patch.object(self.test, 'deploy_orchestrator',
93 mock.patch.object(self.test, 'deploy_vnf',
95 mock.patch.object(self.test, 'test_vnf',
97 self.assertEqual(self.test.run(), testcase.TestCase.EX_OK)
99 def test_deploy_vnf_unimplemented(self):
100 with self.assertRaises(vnf.VnfDeploymentException):
101 self.test.deploy_vnf()
103 def test_test_vnf_unimplemented(self):
104 with self.assertRaises(vnf.VnfTestException):
107 def test_deploy_orch_unimplemented(self):
108 self.assertTrue(self.test.deploy_orchestrator())
110 # @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials',
111 # return_value='test')
112 # @mock.patch('snaps.openstack.create_project.OpenStackProject',
114 # @mock.patch('snaps.openstack.create_user.OpenStackUser',
116 # def test_prepare(self, *args):
117 # self.assertEqual(self.test.prepare(),
118 # testcase.TestCase.EX_OK)
119 # args[0].assert_called_once_with()
120 # args[1].assert_called_once_with('test', self.tenant_name)
121 # args[2].assert_called_once_with(
122 # 'test', self.tenant_name, self.tenant_description)
123 # args[3].assert_called_once_with()
125 @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials',
126 return_value=OSCreds(
127 username='user', password='pass',
128 auth_url='http://foo.com:5000/v3', project_name='bar'),
129 side_effect=Exception)
130 def test_prepare_keystone_client_ko(self, *args):
131 with self.assertRaises(vnf.VnfPreparationException):
133 args[0].assert_called_once()
135 # @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials',
136 # return_value=OS_CREDS)
137 # @mock.patch('snaps.openstack.create_project.OpenStackProject')
138 # @mock.patch('snaps.openstack.create_project.OpenStackProject.create',
139 # side_effect=Exception)
140 # def test_prepare_tenant_creation_ko(self, *args):
141 # with self.assertRaises(vnf.VnfPreparationException):
142 # self.test.prepare()
143 # args[2].assert_called_once()
144 # args[1].assert_called_once_with(OS_CREDS,
146 # name=self.tenant_name,
147 # description=self.tenant_description,
149 # args[0].assert_called_once()
151 # @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials')
152 # @mock.patch('snaps.openstack.create_project.OpenStackProject',
154 # @mock.patch('snaps.openstack.create_user.OpenStackUser',
155 # side_effect=Exception)
156 # def test_prepare_user_creation_ko(self, *args):
157 # with self.assertRaises(vnf.VnfPreparationException):
158 # self.test.prepare()
159 # args[0].assert_called_once_with(mock.ANY, self.tenant_name)
160 # args[1].assert_called_once_with(
161 # mock.ANY, self.tenant_name, self.tenant_description)
162 # args[2].assert_called_once_with()
165 if __name__ == "__main__":
166 logging.disable(logging.CRITICAL)
167 unittest.main(verbosity=2)