Skip to content

Commit 4884654

Browse files
cephadm: add supports_split_cgroups property to Podman
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 <[email protected]>
1 parent 602564d commit 4884654

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/cephadm/cephadmlib/container_engines.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
from .call_wrappers import call_throws, CallVerbosity
88
from .context import CephadmContext
99
from .container_engine_base import ContainerEngine
10-
from .constants import DEFAULT_MODE, MIN_PODMAN_VERSION
10+
from .constants import (
11+
CGROUPS_SPLIT_PODMAN_VERSION,
12+
DEFAULT_MODE,
13+
MIN_PODMAN_VERSION,
14+
)
1115
from .exceptions import Error
1216

1317

@@ -36,6 +40,11 @@ def __str__(self) -> str:
3640
version = '.'.join(map(str, self.version))
3741
return f'{self.EXE} ({self.path}) version {version}'
3842

43+
@property
44+
def supports_split_cgroups(self) -> bool:
45+
"""Return true if this version of podman supports split cgroups."""
46+
return self.version >= CGROUPS_SPLIT_PODMAN_VERSION
47+
3948

4049
class Docker(ContainerEngine):
4150
EXE = 'docker'

src/cephadm/tests/fixtures.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def mock_podman():
3030
podman = mock.Mock(Podman)
3131
podman.path = '/usr/bin/podman'
3232
podman.version = (2, 1, 0)
33+
# This next little bit of black magic was adapated from the mock docs for
34+
# PropertyMock. We don't use a PropertyMock but the suggestion to call
35+
# type(...) from the doc allows us to "borrow" the real
36+
# supports_split_cgroups attribute:
37+
# https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock
38+
type(podman).supports_split_cgroups = Podman.supports_split_cgroups
3339
return podman
3440

3541

0 commit comments

Comments
 (0)