]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add supports_split_cgroups property to Podman
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 29 Sep 2023 15:39:05 +0000 (11:39 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 18 Oct 2023 19:52:46 +0000 (15:52 -0400)
Add a new method, supports_split_cgroups, to the Podman type. This
function returns a boolean indicating the the podman instance in
use supports split cgroups. This function will be later used to replace
various instances of `podman.version >= CGROUPS_SPLIT_PODMAN_VERSION`.
This encapsulates the check and allows it to be more easily modified
in the future.
It is also shorter, which is nicer to read and to type.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadmlib/container_engines.py
src/cephadm/tests/fixtures.py

index 396161906431fb2ce9e29306e06d22fddf7511a5..dc7834de36acd9fa49b54e304ba3d259ea0825aa 100644 (file)
@@ -7,7 +7,11 @@ from typing import Tuple, List, Optional
 from .call_wrappers import call_throws, CallVerbosity
 from .context import CephadmContext
 from .container_engine_base import ContainerEngine
-from .constants import DEFAULT_MODE, MIN_PODMAN_VERSION
+from .constants import (
+    CGROUPS_SPLIT_PODMAN_VERSION,
+    DEFAULT_MODE,
+    MIN_PODMAN_VERSION,
+)
 from .exceptions import Error
 
 
@@ -36,6 +40,11 @@ class Podman(ContainerEngine):
         version = '.'.join(map(str, self.version))
         return f'{self.EXE} ({self.path}) version {version}'
 
+    @property
+    def supports_split_cgroups(self) -> bool:
+        """Return true if this version of podman supports split cgroups."""
+        return self.version >= CGROUPS_SPLIT_PODMAN_VERSION
+
 
 class Docker(ContainerEngine):
     EXE = 'docker'
index 788913ae6b8ed02fd4deb298e0a81224711b39a4..940703733db7ab9f1cf85de5d54153f57c5866ee 100644 (file)
@@ -30,6 +30,12 @@ def mock_podman():
     podman = mock.Mock(Podman)
     podman.path = '/usr/bin/podman'
     podman.version = (2, 1, 0)
+    # This next little bit of black magic was adapated from the mock docs for
+    # PropertyMock. We don't use a PropertyMock but the suggestion to call
+    # type(...) from the doc allows us to "borrow" the real
+    # supports_split_cgroups attribute:
+    # https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock
+    type(podman).supports_split_cgroups = Podman.supports_split_cgroups
     return podman