From bdad6faa1fafe7cd20ea96aa70a52178d62add63 Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Mon, 27 Aug 2018 18:11:11 +0200 Subject: Decouple tacker from tests Support n-sfc too and abstract a bit the MANO layer so that other MANO components can be inserted into the test Change-Id: I3fb59fbf40b4207bf1721092cd8ff0559e1d9d90 Signed-off-by: Manuel Buil --- sfc/unit_tests/unit/lib/test_cleanup.py | 84 +++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 31 deletions(-) (limited to 'sfc/unit_tests/unit/lib/test_cleanup.py') diff --git a/sfc/unit_tests/unit/lib/test_cleanup.py b/sfc/unit_tests/unit/lib/test_cleanup.py index 5ec4261e..b83e229f 100644 --- a/sfc/unit_tests/unit/lib/test_cleanup.py +++ b/sfc/unit_tests/unit/lib/test_cleanup.py @@ -262,8 +262,10 @@ class SfcCleanupTesting(unittest.TestCase): mock_log.assert_has_calls(log_calls) mock_del_vim.assert_has_calls(del_calls) + @patch('sfc.lib.cleanup.logger.info') @patch('sfc.lib.cleanup.logger.error') - def test_delete_openstack_objects_exception(self, mock_log): + def test_delete_openstack_objects_exception(self, mock_log_err, + mock_log_info): """ Check the proper functionality of the delete_openstack_objects @@ -283,11 +285,13 @@ class SfcCleanupTesting(unittest.TestCase): mock_creator_objs_list = [mock_creator_obj_one, mock_creator_obj_two] log_calls = [call('Unexpected error cleaning - %s', exception_two), - call('Unexpected error cleaning - %s', exception_one)] + call('Unexpected error cleaning - %s', exception_one), + call('Deleting the openstack objects...')] cleanup.delete_openstack_objects(mock_creator_objs_list) - mock_log.assert_has_calls(log_calls) + mock_log_err.assert_has_calls(log_calls[:2]) + mock_log_info.assert_has_calls(log_calls[2:]) @patch('sfc.lib.openstack_utils.OpenStackSFC', autospec=True) def test_delete_untracked_security_groups(self, @@ -314,53 +318,71 @@ class SfcCleanupTesting(unittest.TestCase): mock_del_odl_res.assert_has_calls(odl_res_calls) mock_del_odl_ietf.assert_called_once_with(self.odl_ip, self.odl_port) + @patch('sfc.lib.openstack_utils.OpenStackSFC', autospec=True) + def test_cleanup_nsfc_objects(self, mock_os_sfc): + mock_os_sfc_ins = mock_os_sfc.return_value + cleanup.cleanup_nsfc_objects() + mock_os_sfc_ins.delete_chain.assert_called_once() + mock_os_sfc_ins.delete_port_groups.assert_called_once() + @patch('time.sleep') - @patch('sfc.lib.cleanup.delete_openstack_objects') - @patch('sfc.lib.cleanup.cleanup_odl') - def test_cleanup(self, - mock_cleanup_odl, - mock_del_os_obj, - mock_time): + def test_cleanup_tacker_objects(self, mock_time): mock_dict = {'delete_vnffgs': DEFAULT, 'delete_vnffgds': DEFAULT, 'delete_vnfs': DEFAULT, 'delete_vnfds': DEFAULT, - 'delete_vims': DEFAULT, - 'delete_untracked_security_groups': DEFAULT} + 'delete_vims': DEFAULT} with patch.multiple('sfc.lib.cleanup', **mock_dict) as mock_values: - - cleanup.cleanup(['creator_one', 'creator_two'], - self.odl_ip, - self.odl_port) + cleanup.cleanup_tacker_objects() for key in mock_values: mock_values[key].assert_called_once() + + mock_time.assert_called_once_with(20) + + @patch('sfc.lib.cleanup.cleanup_tacker_objects') + def test_cleanup_mano_objects_tacker(self, mock_cleanup_tacker): + cleanup.cleanup_mano_objects('tacker') + mock_cleanup_tacker.assert_called_once() + + @patch('sfc.lib.cleanup.cleanup_nsfc_objects') + def test_cleanup_mano_objects_nsfc(self, mock_cleanup_nsfc): + cleanup.cleanup_mano_objects('no-mano') + mock_cleanup_nsfc.assert_called_once() + + @patch('sfc.lib.cleanup.delete_untracked_security_groups') + @patch('sfc.lib.cleanup.cleanup_mano_objects') + @patch('sfc.lib.cleanup.delete_openstack_objects') + @patch('sfc.lib.cleanup.cleanup_odl') + def test_cleanup(self, + mock_cleanup_odl, + mock_del_os_obj, + mock_cleanup_mano, + mock_untr_sec_grps): + + cleanup.cleanup(['creator_one', 'creator_two'], + 'mano', + self.odl_ip, + self.odl_port) + mock_cleanup_odl.assert_called_once_with(self.odl_ip, self.odl_port) mock_del_os_obj.assert_called_once_with(['creator_one', 'creator_two']) - mock_time.assert_called_once_with(20) + mock_cleanup_mano.assert_called_once_with('mano') + mock_untr_sec_grps.assert_called_once() - @patch('time.sleep') + @patch('sfc.lib.cleanup.cleanup_mano_objects') @patch('sfc.lib.cleanup.cleanup_odl') def test_cleanup_from_bash(self, mock_cleanup_odl, - mock_time): - - mock_dict = {'delete_vnffgs': DEFAULT, - 'delete_vnffgds': DEFAULT, - 'delete_vnfs': DEFAULT, - 'delete_vnfds': DEFAULT, - 'delete_vims': DEFAULT} - with patch.multiple('sfc.lib.cleanup', - **mock_dict) as mock_values: + mock_cleanup_mano): - cleanup.cleanup_from_bash(self.odl_ip, - self.odl_port) + cleanup.cleanup_from_bash(self.odl_ip, + self.odl_port, + 'mano') - for key in mock_values: - mock_values[key].assert_called_once() mock_cleanup_odl.assert_called_once_with(self.odl_ip, self.odl_port) - mock_time.assert_called_once_with(20) + mock_cleanup_mano.assert_called_once_with(mano='mano') -- cgit 1.2.3-korg