-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark GPU as critical if it has devices which are in an iommu group wh…
…ich (#13976) has a critical device
- Loading branch information
Showing
8 changed files
with
274 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
src/middlewared/middlewared/pytest/unit/plugins/test_gpu_critical.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import textwrap | ||
|
||
import pytest | ||
from unittest.mock import patch, MagicMock | ||
|
||
from middlewared.utils.gpu import get_gpus | ||
|
||
|
||
DEVICE_DATA = { | ||
'0000:17:00.0': { | ||
'PCI_ID': '1AF4:1050', | ||
'ID_VENDOR_FROM_DATABASE': 'NVIDIA Corporation', | ||
'ID_PCI_SUBCLASS_FROM_DATABASE': 'VGA compatible controller', | ||
'PCI_SLOT_NAME': '0000:17:00.0', | ||
}, | ||
'0000:17:00.1': { | ||
'PCI_ID': '1AF4:1050', | ||
'ID_VENDOR_FROM_DATABASE': 'NVIDIA Corporation', | ||
'ID_PCI_SUBCLASS_FROM_DATABASE': 'Audio device', | ||
'PCI_SLOT_NAME': '0000:17:00.1', | ||
}, | ||
'0000:00:1f.4': { | ||
'PCI_ID': '1AF4:1050', | ||
'ID_VENDOR_FROM_DATABASE': 'Intel Corporation', | ||
'ID_PCI_SUBCLASS_FROM_DATABASE': 'SMBus', | ||
'PCI_SLOT_NAME': '0000:00:1f.4', | ||
}, | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'ls_pci,gpu_pci_id,child_ids,iommu_group,uses_system_critical_devices,critical_reason', | ||
[ | ||
( | ||
textwrap.dedent(''' | ||
0000:17:00.0 VGA compatible controller: NVIDIA Corporation TU117GL [T400 4GB] (rev a1) | ||
0000:17:00.1 Audio device: NVIDIA Corporation Device 10fa (rev a1) | ||
'''), | ||
'0000:17:00.0', | ||
['0000:17:00.1'], | ||
{ | ||
'0000:17:00.1': { | ||
'number': 9, | ||
'addresses': [], | ||
'critical': False | ||
}, | ||
'0000:17:00.0': { | ||
'number': 9, | ||
'addresses': [], | ||
'critical': False | ||
}, | ||
}, | ||
False, | ||
None | ||
), | ||
( | ||
textwrap.dedent(''' | ||
0000:17:00.0 VGA compatible controller: NVIDIA Corporation TU117GL [T400 4GB] (rev a1) | ||
0000:17:00.1 Audio device: NVIDIA Corporation Device 10fa (rev a1) | ||
0000:00:1f.4 SMBus: Intel Corporation C620 Series Chipset Family SMBus (rev 09) | ||
'''), | ||
'0000:17:00.0', | ||
['0000:17:00.1', '0000:00:1f.4'], | ||
{ | ||
'0000:17:00.1': { | ||
'number': 9, | ||
'addresses': [], | ||
'critical': False | ||
}, | ||
'0000:17:00.0': { | ||
'number': 9, | ||
'addresses': [], | ||
'critical': False | ||
}, | ||
'0000:00:1f.4': { | ||
'number': 31, | ||
'addresses': [], | ||
'critical': True | ||
}, | ||
}, | ||
True, | ||
'Critical devices found: 0000:00:1f.4\nCritical devices found in same IOMMU group: 0000:00:1f.4' | ||
), | ||
( | ||
textwrap.dedent(''' | ||
0000:17:00.0 VGA compatible controller: NVIDIA Corporation TU117GL [T400 4GB] (rev a1) | ||
0000:17:00.1 Audio device: NVIDIA Corporation Device 10fa (rev a1) | ||
0000:00:1f.4 SMBus: Intel Corporation C620 Series Chipset Family SMBus (rev 09) | ||
'''), | ||
'0000:17:00.0', | ||
['0000:17:00.1'], | ||
{ | ||
'0000:17:00.1': { | ||
'number': 10, | ||
'addresses': [], | ||
'critical': False | ||
}, | ||
'0000:17:00.0': { | ||
'number': 9, | ||
'addresses': [], | ||
'critical': False | ||
}, | ||
'0000:00:1f.4': { | ||
'number': 9, | ||
'addresses': [], | ||
'critical': True | ||
}, | ||
}, | ||
True, | ||
'Critical devices found in same IOMMU group: 0000:17:00.0' | ||
), | ||
( | ||
textwrap.dedent(''' | ||
0000:17:00.0 VGA compatible controller: NVIDIA Corporation TU117GL [T400 4GB] (rev a1) | ||
0000:17:00.1 Audio device: NVIDIA Corporation Device 10fa (rev a1) | ||
0000:00:1f.4 SMBus: Intel Corporation C620 Series Chipset Family SMBus (rev 09) | ||
'''), | ||
'0000:17:00.0', | ||
['0000:17:00.1'], | ||
{ | ||
'0000:17:00.1': { | ||
'number': 9, | ||
'addresses': [], | ||
'critical': False | ||
}, | ||
'0000:17:00.0': { | ||
'number': 10, | ||
'addresses': [], | ||
'critical': False | ||
}, | ||
'0000:00:1f.4': { | ||
'number': 9, | ||
'addresses': [], | ||
'critical': True | ||
}, | ||
}, | ||
True, | ||
'Critical devices found in same IOMMU group: 0000:17:00.1' | ||
) | ||
] | ||
) | ||
def test_critical_gpu( | ||
ls_pci, gpu_pci_id, child_ids, iommu_group, uses_system_critical_devices, critical_reason | ||
): | ||
with patch('middlewared.utils.gpu.pyudev.Devices.from_name', MagicMock()) as from_name_mock: | ||
udev_mock = MagicMock() | ||
udev_mock.get = lambda key, default: DEVICE_DATA[gpu_pci_id].get(key, default) | ||
udev_mock.parent.children = [DEVICE_DATA[child_id] for child_id in child_ids] | ||
from_name_mock.return_value = udev_mock | ||
with patch('middlewared.utils.gpu.subprocess.Popen', MagicMock()) as popen_mock: | ||
comm_mock = MagicMock() | ||
comm_mock.returncode = 0 | ||
comm_mock.communicate.return_value = ls_pci.strip().encode(), b'' | ||
popen_mock.return_value = comm_mock | ||
|
||
with patch('middlewared.utils.gpu.get_iommu_groups_info', lambda *args, **kwargs: iommu_group): | ||
gpus = get_gpus()[0] | ||
assert gpus['uses_system_critical_devices'] == uses_system_critical_devices | ||
assert gpus['critical_reason'] == critical_reason |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.