Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9342943
D5039.id18043.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D5039.id18043.diff
View Options
diff --git a/swh/loader/core/loader.py b/swh/loader/core/loader.py
--- a/swh/loader/core/loader.py
+++ b/swh/loader/core/loader.py
@@ -11,6 +11,7 @@
from typing import Any, Dict, Iterable, Optional
from swh.core.config import load_from_envvar
+from swh.loader.exception import NotFound
from swh.model.model import (
BaseContent,
Content,
@@ -189,6 +190,9 @@
"""Second step executed by the loader to prepare some state needed by
the loader.
+ Raises
+ NotFound exception if the origin to ingest is not found.
+
"""
pass
@@ -331,8 +335,14 @@
)
self.storage.origin_visit_status_add([visit_status])
self.post_load()
- except Exception:
- status = "partial" if self.loaded_snapshot_id else "failed"
+ except Exception as e:
+ if isinstance(e, NotFound):
+ status = "not_found"
+ task_status = "uneventful"
+ else:
+ status = "partial" if self.loaded_snapshot_id else "failed"
+ task_status = "failed"
+
self.log.exception(
"Loading failure, updating to `%s` status",
status,
@@ -348,7 +358,7 @@
)
self.storage.origin_visit_status_add([visit_status])
self.post_load(success=False)
- return {"status": "failed"}
+ return {"status": task_status}
finally:
self.flush()
self.cleanup()
diff --git a/swh/loader/core/tests/test_loader.py b/swh/loader/core/tests/test_loader.py
--- a/swh/loader/core/tests/test_loader.py
+++ b/swh/loader/core/tests/test_loader.py
@@ -8,6 +8,7 @@
import logging
from swh.loader.core.loader import DEFAULT_CONFIG, BaseLoader, DVCSLoader
+from swh.loader.exception import NotFound
from swh.loader.tests import assert_last_visit_matches
from swh.model.hashutil import hash_to_bytes
from swh.model.model import Origin, OriginVisit, Snapshot
@@ -135,6 +136,7 @@
def _check_load_failure(caplog, loader, exc_class, exc_text, status="partial"):
"""Check whether a failed load properly logged its exception, and that the
snapshot didn't get referenced in storage"""
+ assert isinstance(loader, DVCSLoader) # was implicit so far
for record in caplog.records:
if record.levelname != "ERROR":
continue
@@ -213,3 +215,26 @@
_check_load_failure(
caplog, loader, RuntimeError, "Failed to add snapshot!", status="failed"
)
+
+
+class DummyDVCSLoaderNotFound(DummyDVCSLoader, BaseLoader):
+ """A loader which raises a not_found exception during the prepare method call
+
+ """
+
+ def prepare(*args, **kwargs):
+ raise NotFound("Unknown origin!")
+
+ def load_status(self):
+ return {
+ "status": "uneventful",
+ }
+
+
+def test_loader_not_found(swh_config, caplog):
+ loader = DummyDVCSLoaderNotFound()
+ result = loader.load()
+
+ assert result == {"status": "uneventful"}
+
+ _check_load_failure(caplog, loader, NotFound, "Unknown origin!", status="not_found")
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 3, 1:07 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3220251
Attached To
D5039: core.loader: Allow vcs loaders to deal with not_found status
Event Timeline
Log In to Comment