Skip to content

Commit

Permalink
Fix: Orchestrator failed with `assert result["result"] == HTTPOk.stat…
Browse files Browse the repository at this point in the history
…us_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.
  • Loading branch information
hoh committed Jun 5, 2024
1 parent b63d248 commit f242be6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/aleph/vm/orchestrator/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 129 in src/aleph/vm/orchestrator/status.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/orchestrator/status.py#L129

Added line #L129 was not covered by tests

return True
except ClientResponseError:
return False
Expand Down

0 comments on commit f242be6

Please sign in to comment.