1
1
import asyncio
2
+ import os
2
3
import tempfile
3
4
from copy import deepcopy
4
5
from pathlib import Path
11
12
from pytest_mock import MockerFixture
12
13
13
14
from aleph .vm .conf import settings
14
- from aleph .vm .orchestrator .machine import get_hardware_info
15
15
from aleph .vm .orchestrator .supervisor import setup_webapp
16
16
from aleph .vm .pool import VmPool
17
17
from aleph .vm .sevclient import SevClient
@@ -45,6 +45,7 @@ async def test_allocation_fails_on_invalid_item_hash(aiohttp_client):
45
45
@pytest .mark .asyncio
46
46
async def test_system_usage (aiohttp_client , mocker , mock_app_with_pool ):
47
47
"""Test that the usage system endpoints responds. No auth needed"""
48
+ mocker .patch ("aleph.vm.orchestrator.resources.get_hardware_info" , return_value = MOCK_SYSTEM_INFO )
48
49
49
50
client = await aiohttp_client (await mock_app_with_pool )
50
51
response : web .Response = await client .get ("/about/usage/system" )
@@ -55,7 +56,7 @@ async def test_system_usage(aiohttp_client, mocker, mock_app_with_pool):
55
56
assert resp ["cpu" ]["count" ] > 0
56
57
57
58
58
- FAKE_SYSTEM_INFO = {
59
+ MOCK_SYSTEM_INFO = {
59
60
"cpu" : {
60
61
"id" : "cpu" ,
61
62
"class" : "processor" ,
@@ -74,6 +75,7 @@ async def test_system_usage(aiohttp_client, mocker, mock_app_with_pool):
74
75
"width" : 64 ,
75
76
"configuration" : {"cores" : "8" , "enabledcores" : "8" , "microcode" : "167776681" , "threads" : "1" },
76
77
"capabilities" : {
78
+ "x86-64" : "64bits extensions (x86-64)" ,
77
79
"fpu" : "mathematical co-processor" ,
78
80
"fpu_exception" : "FPU exceptions reporting" ,
79
81
"wp" : True ,
@@ -209,7 +211,7 @@ async def test_system_usage(aiohttp_client, mocker, mock_app_with_pool):
209
211
async def test_system_usage_mock (aiohttp_client , mocker , mock_app_with_pool ):
210
212
"""Test that the usage system endpoints response value. No auth needed"""
211
213
212
- mocker .patch ("aleph.vm.orchestrator.machine .get_hardware_info" , FAKE_SYSTEM_INFO )
214
+ mocker .patch ("aleph.vm.orchestrator.resources .get_hardware_info" , return_value = MOCK_SYSTEM_INFO )
213
215
mocker .patch (
214
216
"psutil.getloadavg" ,
215
217
lambda : [1 , 2 , 3 ],
@@ -233,7 +235,10 @@ async def test_system_usage_mock(aiohttp_client, mocker, mock_app_with_pool):
233
235
@pytest .mark .asyncio
234
236
async def test_system_capability_mock (aiohttp_client , mocker ):
235
237
"""Test that the capability system endpoints response value. No auth needed"""
236
- mocker .patch ("aleph.vm.orchestrator.machine.get_hardware_info" , FAKE_SYSTEM_INFO )
238
+ mocker .patch ("aleph.vm.orchestrator.resources.get_hardware_info" , return_value = MOCK_SYSTEM_INFO )
239
+ mocker .patch ("aleph.vm.orchestrator.resources.check_amd_sev_supported" , return_value = True )
240
+ mocker .patch ("aleph.vm.orchestrator.resources.check_amd_sev_es_supported" , return_value = True )
241
+ mocker .patch ("aleph.vm.orchestrator.resources.check_amd_sev_snp_supported" , return_value = False )
237
242
mocker .patch (
238
243
"psutil.getloadavg" ,
239
244
lambda : [1 , 2 , 3 ],
@@ -252,14 +257,34 @@ async def test_system_capability_mock(aiohttp_client, mocker):
252
257
"cpu" : {
253
258
"architecture" : "x86_64" ,
254
259
"vendor" : "AuthenticAMD" ,
260
+ "features" : ["sev" , "sev_es" ],
255
261
"model" : "AMD EPYC 7763 64-Core Processor" ,
256
- "frequency" : " 2000000000" ,
257
- "count" : " 200" ,
262
+ "frequency" : 2000000000 ,
263
+ "count" : 200 ,
258
264
},
259
- "memory" : {"size" : " 17179869184" , "units" : "bytes" , "type" : "" , "clock" : None , "clock_units" : "" },
265
+ "memory" : {"size" : 17179869184 , "units" : "bytes" , "type" : "" , "clock" : None , "clock_units" : None },
260
266
}
261
267
262
268
269
+ @pytest .mark .asyncio
270
+ async def test_system_capability_real (aiohttp_client , mocker ):
271
+ """Test that the capability system endpoints response value
272
+ with real system value, no mock so we don't know the definive value but want ot see that it works"""
273
+ if os .environ .get ("GITHUB_JOB" ):
274
+ pytest .xfail ("Test fail inside GITHUB CI because of invalid lshw return inside worker" )
275
+
276
+ app = setup_webapp ()
277
+ client = await aiohttp_client (app )
278
+ response : web .Response = await client .get ("/about/capability" )
279
+ assert response .status == 200
280
+ # check if it is valid json
281
+ resp = await response .json ()
282
+ assert resp .get ("cpu" ), resp
283
+ assert resp ["cpu" ].get ("architecture" )
284
+ assert resp .get ("memory" )
285
+ assert resp ["memory" ].get ("size" )
286
+
287
+
263
288
@pytest .mark .asyncio
264
289
async def test_allocation_invalid_auth_token (aiohttp_client ):
265
290
"""Test that the allocation endpoint fails when an invalid auth token is provided."""
@@ -456,6 +481,7 @@ def mock_is_kernel_enabled_gpu(pci_host: str) -> bool:
456
481
async def test_system_usage_gpu_ressources (aiohttp_client , mocker , mock_app_with_pool ):
457
482
"""Test gpu are properly listed"""
458
483
client = await aiohttp_client (await mock_app_with_pool )
484
+ mocker .patch ("aleph.vm.orchestrator.resources.get_hardware_info" , return_value = MOCK_SYSTEM_INFO )
459
485
460
486
response : web .Response = await client .get ("/about/usage/system" )
461
487
assert response .status == 200
0 commit comments