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