Skip to content
Snippets Groups Projects
Verified Commit 71e3b447 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

svn.loader: Mark visit status as not_found when relevant

When failing to communicate with the svn server at initialization time, a visit status
ends up in "not_found" status.

Other failures to communicate ends up in a visit status marked as "failed".

Related to T3030
parent ddc18d08
No related branches found
Tags v0.6.0
1 merge request!50loader.svn: Mark visit status as not_found when relevant
# Copyright (C) 2015-2020 The Software Heritage developers
# Copyright (C) 2015-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
......@@ -16,9 +16,13 @@ from subprocess import Popen
import tempfile
from typing import Any, Dict, Iterator, List, Optional, Tuple
from subvertpy import SubversionException
from swh.core.config import merge_configs
from swh.loader.core.loader import BaseLoader
from swh.loader.core.utils import clean_dangling_folders
from swh.loader.exception import NotFound
from swh.loader.svn.svn import SvnRepo
from swh.model import from_disk, hashutil
from swh.model.model import (
Content,
......@@ -32,7 +36,7 @@ from swh.model.model import (
)
from swh.storage.algos.snapshot import snapshot_get_latest
from . import converters, svn
from . import converters
from .exception import SvnLoaderHistoryAltered, SvnLoaderUneventful
from .utils import (
OutputStream,
......@@ -398,9 +402,20 @@ Local repository not cleaned up for investigation: %s"""
dir=self.temp_directory,
)
self.svnrepo = svn.SvnRepo(
self.svn_url, self.origin_url, local_dirname, self.max_content_length
)
try:
self.svnrepo = SvnRepo(
self.svn_url, self.origin_url, local_dirname, self.max_content_length
)
except SubversionException as e:
error_msgs = [
"Unable to connect to a repository at URL",
"Unknown URL type",
]
for msg in error_msgs:
if msg in e.args[0]:
self._load_status = "uneventful"
raise NotFound(e)
raise
try:
revision_start, revision_end, revision_parents = self.start_from(
......
......@@ -5,6 +5,9 @@
import os
import pytest
from subvertpy import SubversionException
from swh.loader.svn.loader import SvnLoader, SvnLoaderFromRemoteDump
from swh.loader.tests import (
assert_last_visit_matches,
......@@ -36,6 +39,59 @@ GOURMET_UPDATES_SNAPSHOT = Snapshot(
)
def test_loader_svn_not_found_no_mock(swh_config, tmp_path):
"""Given an unknown repository, the loader visit ends up in status not_found"""
unknown_repo_url = "unknown-repository"
loader = SvnLoader(unknown_repo_url, destination_path=tmp_path)
assert loader.load() == {"status": "uneventful"}
assert_last_visit_matches(
loader.storage, unknown_repo_url, status="not_found", type="svn",
)
@pytest.mark.parametrize(
"exception_msg", ["Unable to connect to a repository at URL", "Unknown URL type",]
)
def test_loader_svn_not_found(swh_config, tmp_path, exception_msg, mocker):
"""Given unknown repository issues, the loader visit ends up in status not_found"""
mock = mocker.patch("swh.loader.svn.loader.SvnRepo")
mock.side_effect = SubversionException(exception_msg, 0)
unknown_repo_url = "unknown-repository"
loader = SvnLoader(unknown_repo_url, destination_path=tmp_path)
assert loader.load() == {"status": "uneventful"}
assert_last_visit_matches(
loader.storage, unknown_repo_url, status="not_found", type="svn",
)
@pytest.mark.parametrize(
"exception",
[
SubversionException("Irrelevant message, considered a failure", 10),
SubversionException("Present but fails to read, considered a failure", 20),
ValueError("considered a failure"),
],
)
def test_loader_svn_failures(swh_config, tmp_path, exception, mocker):
"""Given any errors raised, the loader visit ends up in status failed"""
mock = mocker.patch("swh.loader.svn.loader.SvnRepo")
mock.side_effect = exception
existing_repo_url = "existing-repo-url"
loader = SvnLoader(existing_repo_url, destination_path=tmp_path)
assert loader.load() == {"status": "failed"}
assert_last_visit_matches(
loader.storage, existing_repo_url, status="failed", type="svn",
)
def test_loader_svn_new_visit(swh_config, datadir, tmp_path):
"""Eventful visit should yield 1 snapshot"""
archive_name = "pkg-gourmet"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment