From 20fbfe6b4225f3f63c2d030a67ceca3a62ad96ba Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 5 Jun 2026 15:52:16 -0600 Subject: [PATCH] Fix regression in Host.os_type And go ahead and make it a property. Signed-off-by: Zack Cerza --- ceph_devstack/host.py | 1 + ceph_devstack/requirements.py | 10 +++++----- tests/test_requirements_core.py | 7 +++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ceph_devstack/host.py b/ceph_devstack/host.py index 85c88114..5c2f8836 100644 --- a/ceph_devstack/host.py +++ b/ceph_devstack/host.py @@ -73,6 +73,7 @@ def kernel_version(self) -> Version: self._kernel_version = parse_version(raw_version.split("-")[0]) return self._kernel_version + @property def os_type(self) -> str: if not hasattr(self, "_os_type"): proc = self.run(["uname"]) diff --git a/ceph_devstack/requirements.py b/ceph_devstack/requirements.py index 32d49b42..b91946a5 100644 --- a/ceph_devstack/requirements.py +++ b/ceph_devstack/requirements.py @@ -56,7 +56,7 @@ class PodmanPlatform(LocalFixableRequirement): @property def fix_cmd(self): - host_os = self.host.os_type() + host_os = self.host.os_type if host_os == "darwin": return ["brew", "install", "podman"] return ["sudo", host.package_manager(), "install", "-y", "podman"] @@ -164,7 +164,7 @@ async def check(self): class PodmanRuntime(Requirement): @property def fix_cmd(self): - if self.host.os_type() != "darwin": + if self.host.os_type != "darwin": return ["sudo", self.host.package_manager(), "install", "-y", "crun"] return [] @@ -214,7 +214,7 @@ class PodmanDNSPlugin(FixableRequirement): @property def dns_plugin_path(self): - os_type = self.host.os_type() + os_type = self.host.os_type if os_type in ["ubuntu", "debian"]: return "/usr/lib/cni/dnsname" return "/usr/libexec/cni/dnsname" @@ -225,7 +225,7 @@ def check_cmd(self): @property def fix_cmd(self): - os_type = self.host.os_type() + os_type = self.host.os_type if os_type == "centos": return ["sudo", "dnf", "install", "-y", self.dns_plugin_path] elif os_type in ["ubuntu", "debian"]: @@ -261,7 +261,7 @@ class AppArmorProfile(FixableRequirement): async def check_requirements(): if not await PodmanPlatform().evaluate(): return False - if local_host.os_type() == "darwin": + if local_host.os_type == "darwin": if not await PodmanMachinePresent().evaluate(): return False if not await PodmanMachineRunning().evaluate(): diff --git a/tests/test_requirements_core.py b/tests/test_requirements_core.py index 3a43261b..8448caab 100644 --- a/tests/test_requirements_core.py +++ b/tests/test_requirements_core.py @@ -1,7 +1,7 @@ import asyncio import pytest from packaging.version import parse as parse_version -from unittest.mock import AsyncMock, MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch, PropertyMock from ceph_devstack import config, requirements @@ -303,7 +303,10 @@ def dns_plugin_path(self, os_type): return "/usr/lib/cni/dnsname" def test_podman_dns_plugin_config(self, cls, os_type, dns_plugin_path): - with patch.object(cls.host, "os_type", return_value=os_type): + with patch( + "ceph_devstack.host.Host.os_type", new_callable=PropertyMock + ) as MockHost: + MockHost.return_value = os_type req = cls() assert req.check_cmd == ["test", "-x", dns_plugin_path]