From 7902aa52811a27c1dcb3bede182a11c7b7481f96 Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Tue, 22 Jul 2025 20:38:11 +0000 Subject: [PATCH] Add nvme as supported feature option --- supervisor/host/const.py | 1 + supervisor/host/manager.py | 3 +++ tests/host/test_supported_features.py | 32 ++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/supervisor/host/const.py b/supervisor/host/const.py index 8a97a41aa..8ab8444aa 100644 --- a/supervisor/host/const.py +++ b/supervisor/host/const.py @@ -67,6 +67,7 @@ class HostFeature(StrEnum): JOURNAL = "journal" MOUNT = "mount" NETWORK = "network" + NVME = "nvme" OS_AGENT = "os_agent" REBOOT = "reboot" RESOLVED = "resolved" diff --git a/supervisor/host/manager.py b/supervisor/host/manager.py index 6051eafae..dc3612222 100644 --- a/supervisor/host/manager.py +++ b/supervisor/host/manager.py @@ -125,6 +125,9 @@ class HostManager(CoreSysAttributes): if self.sys_dbus.udisks2.is_connected: features.append(HostFeature.DISK) + if self.nvme.devices: + features.append(HostFeature.NVME) + # Support added in OS10. Propagation mode changed on mount in 10.2 to support this if ( self.sys_dbus.systemd.is_connected diff --git a/tests/host/test_supported_features.py b/tests/host/test_supported_features.py index 5a4de141b..5ecc92db7 100644 --- a/tests/host/test_supported_features.py +++ b/tests/host/test_supported_features.py @@ -1,8 +1,17 @@ """Test supported features.""" + # pylint: disable=protected-access +from unittest.mock import patch + +import pytest + +from supervisor.coresys import CoreSys + +from tests.common import load_binary_fixture -def test_supported_features(coresys, dbus_is_connected): +@pytest.mark.usefixtures("dbus_is_connected") +def test_supported_features(coresys: CoreSys): """Test host features.""" assert "network" in coresys.host.features @@ -12,3 +21,24 @@ def test_supported_features(coresys, dbus_is_connected): coresys.host.supported_features.cache_clear() assert "network" not in coresys.host.features + + +async def test_supported_features_nvme(coresys: CoreSys): + """Test nvme supported feature.""" + with patch( + "supervisor.host.nvme.manager.asyncio.create_subprocess_shell" + ) as shell_mock: + shell_mock.return_value.returncode = 0 + shell_mock.return_value.communicate.return_value = (b'{"Devices":[]}', b"") + await coresys.host.nvme.load() + + assert "nvme" not in coresys.host.features + + shell_mock.return_value.communicate.return_value = ( + load_binary_fixture("nvme-list.json"), + b"", + ) + await coresys.host.nvme.update() + coresys.host.supported_features.cache_clear() + + assert "nvme" in coresys.host.features