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 @@ -174,13 +174,23 @@ return 2 # Get metadata list from swh-web - metadata_objects = requests.get( + response = requests.get( f"{self.api_url}/api/1/raw-extrinsic-metadata/swhid/{swhid}/", params={ "authority": f"deposit_client {self._provider_url}", "after": start_datetime.isoformat(), }, - ).json() + ) + if response.status_code != 200: + self.print_result( + "CRITICAL", + f"Getting the list of metadata returned code {response.status_code}: " + f"{response.content!r}", + **metrics, + ) + return 2 + + metadata_objects = response.json() expected_origin = f"{self._provider_url}/{self._slug}" # Filter out objects that were clearly not created by this deposit 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 @@ -673,6 +673,61 @@ assert result.exit_code == 2, f"Unexpected output: {result.output}" +def test_deposit_metadata_error( + requests_mock, mocker, sample_archive, sample_metadata, mocked_time +): + scenario = WebScenario() + + scenario.add_step( + "post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited") + ) + scenario.add_step( + "get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"), + ) + + # Deposit done, checker gets the SWHID + swhid = "swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74" + status_xml = status_template(status="done", status_detail="", swhid=swhid,) + scenario.add_step( + "get", f"{BASE_URL}/testcol/42/status/", status_xml, + ) + + # Then the checker checks the metadata appeared on the website + scenario.add_step( + "get", + f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" + f"?authority=deposit_client+http%3A%2F%2Ficinga-checker.example.org" + f"&after=2022-03-04T17%3A02%3A39%2B00%3A00", + "foo\nbar", + status_code=400, + ) + + scenario.install_mock(requests_mock) + + result = invoke( + [ + "check-deposit", + *COMMON_OPTIONS, + "single", + "--archive", + sample_archive, + "--metadata", + sample_metadata, + ], + catch_exceptions=True, + ) + + assert result.output == ( + "DEPOSIT CRITICAL - Getting the list of metadata returned code 400: " + "b'foo\\nbar'\n" + "| 'load_time' = 10.00s\n" + "| 'total_time' = 20.00s\n" + "| 'upload_time' = 0.00s\n" + "| 'validation_time' = 10.00s\n" + ) + assert result.exit_code == 2, f"Unexpected output: {result.output}" + + def test_deposit_metadata_corrupt( requests_mock, mocker, sample_archive, sample_metadata, mocked_time ):