Skip to content

Commit

Permalink
add unit test for system usage
Browse files Browse the repository at this point in the history
  • Loading branch information
olethanh committed Apr 29, 2024
1 parent bc496dc commit 551cc3f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/aleph/vm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ class VmExecution:

@property
def is_running(self) -> bool:
return (
bool(self.times.starting_at and not self.times.stopping_at)
if not self.persistent
else self.systemd_manager.is_service_active(self.controller_service)
)
return bool(self.times.starting_at and not self.times.stopping_at)

@property
def is_stopping(self) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions src/aleph/vm/orchestrator/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def get_machine_properties() -> MachineProperties:
cpu_info = cpuinfo.get_cpu_info() # Slow
return MachineProperties(
cpu=CpuProperties(
architecture=cpu_info["raw_arch_string"],
vendor=cpu_info["vendor_id"],
architecture=cpu_info.get("raw_arch_string", cpu_info.get("arch_string_raw")),
vendor=cpu_info["vendor_id_raw"],
),
)

Expand Down
5 changes: 3 additions & 2 deletions src/aleph/vm/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ async def load_persistent_executions(self):
persistent=saved_execution.persistent,
)

if execution.is_running:
# TODO: Improve the way that we re-create running execution
if await self.systemd_manager.is_service_active(
execution.controller_service
): # TODO: Improve the way that we re-create running execution
await execution.prepare()
if self.network:
vm_type = VmType.from_message_content(execution.message)
Expand Down
13 changes: 13 additions & 0 deletions tests/supervisor/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,16 @@ async def test_allocation_fails_on_invalid_item_hash(aiohttp_client):
"type": "value_error.unknownhash",
},
]


@pytest.mark.asyncio
async def test_system_usage(aiohttp_client):
"""Test that the allocation endpoint fails when an invalid item_hash is provided."""
client = await aiohttp_client(app)
settings.ALLOCATION_TOKEN_HASH = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" # = "test"
response: web.Response = await client.get("/about/usage/system")
assert response.status == 200
# check if it is valid json
resp = await response.json()
assert "cpu" in resp
assert resp["cpu"]["count"] > 0

0 comments on commit 551cc3f

Please sign in to comment.