def get_delete_listener_flow(self): """Create a flow to delete a listener :returns: The flow for deleting a listener """ delete_listener_flow = linear_flow.Flow(constants.DELETE_LISTENER_FLOW) delete_listener_flow.add( lifecycle_tasks.ListenerToErrorOnRevertTask( requires=constants.LISTENER)) delete_listener_flow.add( amphora_driver_tasks.ListenerDelete(requires=constants.LISTENER)) delete_listener_flow.add( network_tasks.UpdateVIPForDelete(requires=constants.LOADBALANCER)) delete_listener_flow.add( database_tasks.DeleteListenerInDB(requires=constants.LISTENER)) delete_listener_flow.add( database_tasks.DecrementListenerQuota(requires=constants.LISTENER)) delete_listener_flow.add( database_tasks.MarkLBActiveInDB(requires=constants.LOADBALANCER)) return delete_listener_flow
def test_listener_delete(self, mock_driver, mock_generate_uuid, mock_log, mock_get_session, mock_listener_repo_get, mock_listener_repo_update, mock_amphora_repo_update): listener_delete_obj = amphora_driver_tasks.ListenerDelete() listener_delete_obj.execute(_listener_mock) mock_driver.delete.assert_called_once_with(_listener_mock) # Test the revert amp = listener_delete_obj.revert(_listener_mock) repo.ListenerRepository.update.assert_called_once_with( _session_mock, id=LISTENER_ID, provisioning_status=constants.ERROR) self.assertIsNone(amp) # Test the revert with exception repo.ListenerRepository.update.reset_mock() mock_listener_repo_update.side_effect = Exception('fail') amp = listener_delete_obj.revert(_listener_mock) repo.ListenerRepository.update.assert_called_once_with( _session_mock, id=LISTENER_ID, provisioning_status=constants.ERROR) self.assertIsNone(amp)