Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/tests/test_deposit.py
Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | ): | ||||
status_xml = status_template(status="done", status_detail="", swhid=swhid,) | status_xml = status_template(status="done", status_detail="", swhid=swhid,) | ||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | ||||
# Then the checker checks the metadata appeared on the website | # Then the checker checks the metadata appeared on the website | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", | "get", | ||||
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | ||||
f"?authority=deposit_client%20http://icinga-checker.example.org", | f"?authority=deposit_client%20http://icinga-checker.example.org", | ||||
[{"swhid": swhid, "origin": origin}], | [ | ||||
{ | |||||
"swhid": swhid, | |||||
"origin": origin, | |||||
"discovery_date": "2999-03-03T10:48:47+00:00", | |||||
} | |||||
], | |||||
) | ) | ||||
# Then metadata update | # Then metadata update | ||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | ||||
# internal deposit client does call status, then update metadata then status api | # internal deposit client does call status, then update metadata then status api | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", f"{BASE_URL}/testcol/42/status/", status_xml, | "get", f"{BASE_URL}/testcol/42/status/", status_xml, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | ): | ||||
status_xml = status_template(status="done", status_detail="", swhid=swhid,) | status_xml = status_template(status="done", status_detail="", swhid=swhid,) | ||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | ||||
# Then the checker checks the metadata appeared on the website | # Then the checker checks the metadata appeared on the website | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", | "get", | ||||
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | ||||
f"?authority=deposit_client%20http://icinga-checker.example.org", | f"?authority=deposit_client%20http://icinga-checker.example.org", | ||||
[{"swhid": swhid, "origin": origin}], | [ | ||||
{ | |||||
"swhid": swhid, | |||||
"origin": origin, | |||||
"discovery_date": "2999-03-03T10:48:47+00:00", | |||||
} | |||||
], | |||||
) | ) | ||||
# Then metadata update | # Then metadata update | ||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | ||||
# internal deposit client does call status, then update metadata then status api | # internal deposit client does call status, then update metadata then status api | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", f"{BASE_URL}/testcol/42/status/", status_xml, | "get", f"{BASE_URL}/testcol/42/status/", status_xml, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | ): | ||||
status_xml = status_template(status="done", status_detail="", swhid=swhid,) | status_xml = status_template(status="done", status_detail="", swhid=swhid,) | ||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | ||||
# Then the checker checks the metadata appeared on the website | # Then the checker checks the metadata appeared on the website | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", | "get", | ||||
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | ||||
f"?authority=deposit_client%20http://icinga-checker.example.org", | f"?authority=deposit_client%20http://icinga-checker.example.org", | ||||
[{"swhid": swhid, "origin": origin}], | [ | ||||
{ | |||||
"swhid": swhid, | |||||
"origin": origin, | |||||
"discovery_date": "2999-03-03T10:48:47+00:00", | |||||
} | |||||
], | |||||
) | ) | ||||
# Then metadata update calls | # Then metadata update calls | ||||
failed_status_xml = status_template( | failed_status_xml = status_template( | ||||
status="failed", # lying here | status="failed", # lying here | ||||
status_detail="Failure to ingest", | status_detail="Failure to ingest", | ||||
swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74", | swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74", | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | ): | ||||
status_xml = status_template(status="done", status_detail="", swhid=swhid,) | status_xml = status_template(status="done", status_detail="", swhid=swhid,) | ||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | ||||
# Then the checker checks the metadata appeared on the website | # Then the checker checks the metadata appeared on the website | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", | "get", | ||||
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | ||||
f"?authority=deposit_client%20http://icinga-checker.example.org", | f"?authority=deposit_client%20http://icinga-checker.example.org", | ||||
[{"swhid": swhid, "origin": origin}], | [ | ||||
{ | |||||
"swhid": swhid, | |||||
"origin": origin, | |||||
"discovery_date": "2999-03-03T10:48:47+00:00", | |||||
} | |||||
], | |||||
) | ) | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"--warning", | "--warning", | ||||
"15", | "15", | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | scenario.add_step( | ||||
callback=lambda: time.sleep(60), | callback=lambda: time.sleep(60), | ||||
) | ) | ||||
# Then the checker checks the metadata appeared on the website | # Then the checker checks the metadata appeared on the website | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", | "get", | ||||
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | ||||
f"?authority=deposit_client%20http://icinga-checker.example.org", | f"?authority=deposit_client%20http://icinga-checker.example.org", | ||||
[{"swhid": swhid, "origin": origin}], | [ | ||||
{ | |||||
"swhid": swhid, | |||||
"origin": origin, | |||||
"discovery_date": "2999-03-03T10:48:47+00:00", | |||||
} | |||||
], | |||||
) | ) | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"--critical", | "--critical", | ||||
"50", | "50", | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | ): | ||||
# Deposit done, checker gets the SWHID | # Deposit done, checker gets the SWHID | ||||
swhid = "swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74" | swhid = "swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74" | ||||
status_xml = status_template(status="done", status_detail="", swhid=swhid,) | status_xml = status_template(status="done", status_detail="", swhid=swhid,) | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", f"{BASE_URL}/testcol/42/status/", status_xml, | "get", f"{BASE_URL}/testcol/42/status/", status_xml, | ||||
) | ) | ||||
# Then the checker checks the metadata appeared on the website | # Then the checker checks the metadata appeared on the website | ||||
metadata_list = [ | |||||
{ | |||||
# Filtered out, because wrong origin | |||||
"swhid": swhid, | |||||
"origin": "http://wrong-origin.example.org", | |||||
"discovery_date": "2999-03-03T10:48:47+00:00", | |||||
}, | |||||
{ | |||||
# Filtered out, because too old | |||||
"swhid": swhid, | |||||
"origin": origin, | |||||
"discovery_date": "2022-03-03T09:48:47+00:00", | |||||
}, | |||||
] | |||||
scenario.add_step( | scenario.add_step( | ||||
"get", | "get", | ||||
f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | f"{BASE_WEB_URL}/api/1/raw-extrinsic-metadata/swhid/{swhid}/" | ||||
f"?authority=deposit_client%20http://icinga-checker.example.org", | f"?authority=deposit_client%20http://icinga-checker.example.org", | ||||
[{"swhid": swhid, "origin": "http://wrong-origin.example.org"}], | metadata_list, | ||||
) | ) | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"check-deposit", | "check-deposit", | ||||
*COMMON_OPTIONS, | *COMMON_OPTIONS, | ||||
"single", | "single", | ||||
"--archive", | "--archive", | ||||
sample_archive, | sample_archive, | ||||
"--metadata", | "--metadata", | ||||
sample_metadata, | sample_metadata, | ||||
], | ], | ||||
catch_exceptions=True, | catch_exceptions=True, | ||||
) | ) | ||||
assert result.output == ( | assert result.output == ( | ||||
f"DEPOSIT CRITICAL - Deposited metadata on {swhid} with origin {origin}, " | f"DEPOSIT CRITICAL - No recent metadata on {swhid} with origin {origin} in: " | ||||
f"missing from the list of origins: ['http://wrong-origin.example.org']\n" | f"{metadata_list!r}\n" | ||||
"| 'load_time' = 10.00s\n" | "| 'load_time' = 10.00s\n" | ||||
"| 'total_time' = 20.00s\n" | "| 'total_time' = 20.00s\n" | ||||
"| 'upload_time' = 0.00s\n" | "| 'upload_time' = 0.00s\n" | ||||
"| 'validation_time' = 10.00s\n" | "| 'validation_time' = 10.00s\n" | ||||
) | ) | ||||
assert result.exit_code == 2, f"Unexpected output: {result.output}" | assert result.exit_code == 2, f"Unexpected output: {result.output}" | ||||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |