Skip to content

Commit 551cc3f

Browse files
committed
add unit test for system usage
1 parent bc496dc commit 551cc3f

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/aleph/vm/models.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ class VmExecution:
8585

8686
@property
8787
def is_running(self) -> bool:
88-
return (
89-
bool(self.times.starting_at and not self.times.stopping_at)
90-
if not self.persistent
91-
else self.systemd_manager.is_service_active(self.controller_service)
92-
)
88+
return bool(self.times.starting_at and not self.times.stopping_at)
9389

9490
@property
9591
def is_stopping(self) -> bool:

src/aleph/vm/orchestrator/resources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def get_machine_properties() -> MachineProperties:
8787
cpu_info = cpuinfo.get_cpu_info() # Slow
8888
return MachineProperties(
8989
cpu=CpuProperties(
90-
architecture=cpu_info["raw_arch_string"],
91-
vendor=cpu_info["vendor_id"],
90+
architecture=cpu_info.get("raw_arch_string", cpu_info.get("arch_string_raw")),
91+
vendor=cpu_info["vendor_id_raw"],
9292
),
9393
)
9494

src/aleph/vm/pool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ async def load_persistent_executions(self):
239239
persistent=saved_execution.persistent,
240240
)
241241

242-
if execution.is_running:
243-
# TODO: Improve the way that we re-create running execution
242+
if await self.systemd_manager.is_service_active(
243+
execution.controller_service
244+
): # TODO: Improve the way that we re-create running execution
244245
await execution.prepare()
245246
if self.network:
246247
vm_type = VmType.from_message_content(execution.message)

tests/supervisor/test_views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,16 @@ async def test_allocation_fails_on_invalid_item_hash(aiohttp_client):
2424
"type": "value_error.unknownhash",
2525
},
2626
]
27+
28+
29+
@pytest.mark.asyncio
30+
async def test_system_usage(aiohttp_client):
31+
"""Test that the allocation endpoint fails when an invalid item_hash is provided."""
32+
client = await aiohttp_client(app)
33+
settings.ALLOCATION_TOKEN_HASH = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" # = "test"
34+
response: web.Response = await client.get("/about/usage/system")
35+
assert response.status == 200
36+
# check if it is valid json
37+
resp = await response.json()
38+
assert "cpu" in resp
39+
assert resp["cpu"]["count"] > 0

0 commit comments

Comments
 (0)