38 lines
1.6 KiB
Python
38 lines
1.6 KiB
Python
"""Stage admission must recheck the host's higher-priority GPU ownership."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
from types import SimpleNamespace
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from llm_services import adapters
|
|
|
|
|
|
class AdmissionPolicyTests(unittest.TestCase):
|
|
def test_foreign_process_blocks_stage_even_when_vram_is_free(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
status = Path(directory) / 'status.json'
|
|
status.write_text(json.dumps({
|
|
'schema_version': 1, 'generated_at': time.time(), 'error': None,
|
|
'container_id': 'a' * 64,
|
|
'gpus': [{'index': 0, 'uuid': 'GPU-00000000-0000-0000-0000-000000000001',
|
|
'total_gib': 80, 'free_gib': 79, 'idle_since': None,
|
|
'external_pids': [12345], 'own_pids': []}]}))
|
|
memory = SimpleNamespace(free=79 * 2**30, total=80 * 2**30)
|
|
nvml = SimpleNamespace(nvmlInit=lambda: None, nvmlShutdown=lambda: None,
|
|
nvmlDeviceGetHandleByUUID=lambda uuid: uuid,
|
|
nvmlDeviceGetMemoryInfo=lambda handle: memory)
|
|
with patch.dict(os.environ, {'LLM_GPU_STATUS_PATH': str(status),
|
|
'LLM_GPU_UUID': 'GPU-00000000-0000-0000-0000-000000000001'}), \
|
|
patch.dict(sys.modules, {'pynvml': nvml}):
|
|
with self.assertRaisesRegex(RuntimeError, 'priority|external|yield|GPU policy'):
|
|
adapters.admit_gpu()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|