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
13 from functest.opnfv_tests.vnf.ims import orchestrator_cloudify
16 class ImsVnfTesting(unittest.TestCase):
18 logging.disable(logging.CRITICAL)
21 self.orchestrator = orchestrator_cloudify.Orchestrator('test_dir')
22 self.bp = {'file_name': 'test_file',
23 'destination_folder': 'test_folder',
25 'branch': 'test_branch'}
27 def test_download_manager_blueprint_download_blueprint_failed(self):
28 self.orchestrator.manager_blueprint = False
29 with mock.patch.object(self.orchestrator, '_download_blueprints',
30 return_value=False), \
31 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
33 self.orchestrator.download_manager_blueprint('test_url',
35 mock_exit.assert_any_call(-1)
37 def test_download_manager_blueprint_download_blueprint_passed(self):
38 self.orchestrator.manager_blueprint = False
39 with mock.patch.object(self.orchestrator, '_download_blueprints',
41 self.orchestrator.download_manager_blueprint('test_url',
43 self.assertEqual(self.orchestrator.manager_blueprint,
46 def test_deploy_manager_failed(self):
47 self.orchestrator.manager_blueprint = True
48 with mock.patch('__builtin__.open', mock.mock_open()), \
49 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
51 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
52 'execute_command', return_value='error'):
53 self.assertEqual(self.orchestrator.deploy_manager(),
55 self.assertEqual(self.orchestrator.manager_up,
58 def test_deploy_manager_passed(self):
59 self.orchestrator.manager_blueprint = True
60 with mock.patch('__builtin__.open', mock.mock_open()), \
61 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
63 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
64 'execute_command', return_value=''):
65 self.orchestrator.deploy_manager()
66 self.assertEqual(self.orchestrator.manager_up,
69 def test_undeploy_manager_passed(self):
70 with mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
71 'execute_command', return_value=''):
72 self.orchestrator.deploy_manager()
73 self.assertEqual(self.orchestrator.manager_up,
76 def test_dwnld_upload_and_depl_blueprint_dwnld_blueprint_failed(self):
77 with mock.patch.object(self.orchestrator, '_download_blueprints',
78 return_value=False), \
79 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
80 'exit', side_effect=Exception) as mock_exit, \
81 self.assertRaises(Exception):
82 self.orchestrator.download_upload_and_deploy_blueprint(self.bp,
86 mock_exit.assert_any_call(-1)
88 def test_dwnld_upload_and_depl_blueprint_failed(self):
89 with mock.patch.object(self.orchestrator, '_download_blueprints',
91 mock.patch('__builtin__.open', mock.mock_open()), \
92 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
93 'execute_command', return_value='error'):
94 r = self.orchestrator.download_upload_and_deploy_blueprint(self.bp,
98 self.assertEqual(r, 'error')
100 def test__download_blueprints_failed(self):
101 with mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
103 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
104 'Repo.clone_from', side_effect=Exception):
105 self.assertEqual(self.orchestrator._download_blueprints('bp_url',
110 def test__download_blueprints_passed(self):
111 with mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
113 mock.patch('functest.opnfv_tests.vnf.ims.orchestrator_cloudify.'
115 self.assertEqual(self.orchestrator._download_blueprints('bp_url',
121 if __name__ == "__main__":
122 unittest.main(verbosity=2)