diff --git a/swh/icinga_plugins/deposit.py b/swh/icinga_plugins/deposit.py
--- a/swh/icinga_plugins/deposit.py
+++ b/swh/icinga_plugins/deposit.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 The Software Heritage developers
+# Copyright (C) 2019-2020 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
@@ -6,6 +6,7 @@
import datetime
import sys
import time
+from typing import Any, Dict, Optional
from swh.deposit.client import PublicApiDepositClient
@@ -23,6 +24,7 @@
self._archive_path = obj["archive"]
self._metadata_path = obj["metadata"]
self._collection = obj["collection"]
+ self._slug: Optional[str] = None
self._client = PublicApiDepositClient(
{
@@ -32,16 +34,38 @@
)
def upload_deposit(self):
+ slug = "check-deposit-%s" % datetime.datetime.now().isoformat()
result = self._client.deposit_create(
archive=self._archive_path,
metadata=self._metadata_path,
collection=self._collection,
in_progress=False,
- slug="check-deposit-%s" % datetime.datetime.now().isoformat(),
+ slug=slug,
)
+ self._slug = slug
self._deposit_id = result["deposit_id"]
return result
+ def update_deposit_with_metadata(self) -> Dict[str, Any]:
+ """Trigger a metadata update on the deposit once it's completed.
+
+ """
+ deposit = self.get_deposit_status()
+ assert deposit["deposit_status"] == "done"
+ swhid = deposit["deposit_swh_id"]
+ assert deposit["deposit_id"] == self._deposit_id
+
+ # We can reuse the initial metadata file we already sent
+ # We only entertain this checks to ensure it's working
+ result = self._client.deposit_update(
+ self._collection,
+ self._deposit_id,
+ self._slug,
+ metadata=self._metadata_path,
+ swhid=swhid,
+ )
+ return result
+
def get_deposit_status(self):
return self._client.deposit_status(
collection=self._collection, deposit_id=self._deposit_id
@@ -117,12 +141,33 @@
)
return 2
- # Everything went fine, check total time wasn't too large and
- # print result
(status_code, status) = self.get_status(metrics["total_time"])
self.print_result(
status,
f'Deposit took {metrics["total_time"]:.2f}s and succeeded.',
**metrics,
)
+
+ result = self.update_deposit_with_metadata()
+ metrics["total_time"] = time.time() - start_time
+ metrics["update_time"] = (
+ metrics["total_time"]
+ - metrics["upload_time"]
+ - metrics["validation_time"]
+ - metrics["load_time"]
+ )
+ if "error" in result:
+ self.print_result(
+ "CRITICAL",
+ f'Deposit metadata update failed: {result["error"]} ',
+ **metrics,
+ )
+
+ (status_code, status) = self.get_status(metrics["total_time"])
+ self.print_result(
+ status,
+ f'Deposit Metadata update took {metrics["update_time"]:.2f}s and succeeded.',
+ **metrics,
+ )
+
return status_code
diff --git a/swh/icinga_plugins/tests/test_deposit.py b/swh/icinga_plugins/tests/test_deposit.py
--- a/swh/icinga_plugins/tests/test_deposit.py
+++ b/swh/icinga_plugins/tests/test_deposit.py
@@ -64,6 +64,7 @@
42
{status}
{status_detail}
+ {swhid}
"""
@@ -113,9 +114,38 @@
):
scenario = WebScenario()
+ # Initial deposit
scenario.add_step(
"post", BASE_URL + "/testcol/", ENTRY_TEMPLATE.format(status="done")
)
+ # Then metadata update
+ scenario.add_step(
+ "get",
+ f"{BASE_URL}/testcol/42/status/",
+ STATUS_TEMPLATE.format(
+ status="done",
+ status_detail="",
+ swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74",
+ ),
+ )
+ scenario.add_step(
+ "get",
+ f"{BASE_URL}/testcol/42/status/",
+ STATUS_TEMPLATE.format(
+ status="done",
+ status_detail="",
+ swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74",
+ ),
+ )
+ scenario.add_step(
+ "put",
+ f"{BASE_URL}/testcol/42/metadata/",
+ STATUS_TEMPLATE.format(
+ status="done",
+ status_detail="",
+ swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74",
+ ),
+ )
scenario.install_mock(requests_mock)