def delete(repo_id): """ Delete a repository and inform other affected collections. :param repo_id: id of the repository to delete. :type repo_id: str :raise pulp_exceptions.PulpExecutionException: if any part of the process fails; the exception will contain information on which sections failed :return: A TaskResult object with the details of any errors or spawned tasks :rtype: pulp.server.async.tasks.TaskResult """ # With so much going on during a delete, it's possible that a few things could go wrong while # others are successful. We track lesser errors that shouldn't abort the entire process until # the end and then raise an exception describing the incompleteness of the delete. The exception # arguments are captured as the second element in the tuple, but the user will have to look at # the server logs for more information. error_tuples = [] # tuple of failed step and exception arguments # Inform the importer repo_importer = model.Importer.objects(repo_id=repo_id).first() if repo_importer is not None: try: importer_controller.remove_importer(repo_id) except Exception, e: _logger.exception('Error received removing importer [%s] from repo [%s]' % ( repo_importer.importer_type_id, repo_id)) error_tuples.append(e)
def test_as_expected(self, m_plug_call, m_plugin_api, m_factory, mock_models): """ Test removing an importer. """ mock_repo = mock_models.Repository.objects.get_repo_or_missing_resource.return_value mock_importer = mock_models.Importer.objects.get_or_404.return_value m_imp_inst = mock.MagicMock() m_plugin_config = mock.MagicMock() m_plugin_api.get_importer_by_id.return_value = (m_imp_inst, m_plugin_config) importer.remove_importer('foo') m_sync = m_factory.repo_sync_schedule_manager.return_value m_sync.delete_by_importer_id.assert_called_once_with('foo', mock_importer.importer_type_id) m_plug_call.assert_called_once_with(m_plugin_config, mock_importer.config) m_imp_inst.importer_removed.assert_called_once_with( mock_repo.to_transfer_repo.return_value, m_plug_call.return_value) mock_importer.delete.assert_called_once_with()