From f242be6d096775fc6d74e8c08faa74d3973dd3a5 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Wed, 5 Jun 2024 10:39:03 +0200 Subject: [PATCH] Fix: Orchestrator failed with `assert result["result"] == HTTPOk.status_code` Problem: The diagnostic VM returned HTTP 200 with {"result": False} when it could not connect to the internet. Since this is an OK return code, `raise_for_status` did not raise an error and an assertion error was raised. Solution: Test that the returned status code also corresponds to HTTP OK. --- src/aleph/vm/orchestrator/status.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/aleph/vm/orchestrator/status.py b/src/aleph/vm/orchestrator/status.py index b0d76554d..4c3d2c427 100644 --- a/src/aleph/vm/orchestrator/status.py +++ b/src/aleph/vm/orchestrator/status.py @@ -119,8 +119,15 @@ async def check_internet(session: ClientSession, vm_id: ItemHash) -> bool: """Check that the VM has internet connectivity. This requires DNS, IP, HTTP and TLS to work.""" try: result: dict = await get_json_from_vm(session, vm_id, "/internet") - assert result["result"] == HTTPOk.status_code + + # The HTTP Header "Server" must always be present in the result. assert "Server" in result["headers"] + + # The diagnostic VM returns HTTP 200 with {"result": False} when cannot connect to the internet. + # else it forwards the return code if its own test endpoint. + if result.get("result") != HTTPOk.status_code: + return False + return True except ClientResponseError: return False