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=OSCreds(
112 username='user', password='pass',
113 auth_url='http://foo.com:5000/v3', project_name='bar'),
114 side_effect=Exception)
115 def test_prepare_keystone_client_ko(self, *args):
116 with self.assertRaises(vnf.VnfPreparationException):
118 args[0].assert_called_once()
120 def test_vnf_clean_exc(self):
122 obj.clean.side_effect = Exception
123 self.test.created_object = [obj]
125 obj.clean.assert_called_with()
127 def test_vnf_clean(self):
129 self.test.created_object = [obj]
131 obj.clean.assert_called_with()
134 if __name__ == "__main__":
135 logging.disable(logging.CRITICAL)
136 unittest.main(verbosity=2)