From: John Mulligan Date: Wed, 16 Aug 2023 19:38:50 +0000 (-0400) Subject: cephadm: move ContainerEngine to container_engine_base.py X-Git-Tag: v19.0.0~561^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d54193d7391a18790c1ae8f0a53e7aa0108a1111;p=ceph.git cephadm: move ContainerEngine to container_engine_base.py Signed-off-by: John Mulligan Pair-programmed-with: Adam King Co-authored-by: Adam King --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 9a89bac6e7c..6294c08bba1 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -104,6 +104,7 @@ from cephadmlib.call_wrappers import ( call_timeout, concurrent_tasks, ) +from cephadmlib.container_engine_base import ContainerEngine FuncT = TypeVar('FuncT', bound=Callable) @@ -183,18 +184,6 @@ class DeploymentType(Enum): RECONFIG = 'Reconfig' -class ContainerEngine: - def __init__(self) -> None: - self.path = find_program(self.EXE) - - @property - def EXE(self) -> str: - raise NotImplementedError() - - def __str__(self) -> str: - return f'{self.EXE} ({self.path})' - - class Podman(ContainerEngine): EXE = 'podman' diff --git a/src/cephadm/cephadmlib/container_engine_base.py b/src/cephadm/cephadmlib/container_engine_base.py new file mode 100644 index 00000000000..135b2f4f321 --- /dev/null +++ b/src/cephadm/cephadmlib/container_engine_base.py @@ -0,0 +1,15 @@ +# container_engine_base.py - container engine base class + +from .exe_utils import find_program + + +class ContainerEngine: + def __init__(self) -> None: + self.path = find_program(self.EXE) + + @property + def EXE(self) -> str: + raise NotImplementedError() + + def __str__(self) -> str: + return f'{self.EXE} ({self.path})' diff --git a/src/cephadm/tests/test_container_engine.py b/src/cephadm/tests/test_container_engine.py index 433f0127001..9998f85d3bd 100644 --- a/src/cephadm/tests/test_container_engine.py +++ b/src/cephadm/tests/test_container_engine.py @@ -7,6 +7,9 @@ from tests.fixtures import with_cephadm_ctx, import_cephadm _cephadm = import_cephadm() +_find_program_loc = 'cephadmlib.container_engine_base.find_program' + + def test_container_engine(): with pytest.raises(NotImplementedError): _cephadm.ContainerEngine() @@ -14,14 +17,14 @@ def test_container_engine(): class PhonyContainerEngine(_cephadm.ContainerEngine): EXE = "true" - with mock.patch("cephadm.find_program") as find_program: + with mock.patch(_find_program_loc) as find_program: find_program.return_value = "/usr/bin/true" pce = PhonyContainerEngine() assert str(pce) == "true (/usr/bin/true)" def test_podman(): - with mock.patch("cephadm.find_program") as find_program: + with mock.patch(_find_program_loc) as find_program: find_program.return_value = "/usr/bin/podman" pm = _cephadm.Podman() find_program.assert_called() @@ -36,7 +39,7 @@ def test_podman(): def test_podman_badversion(): - with mock.patch("cephadm.find_program") as find_program: + with mock.patch(_find_program_loc) as find_program: find_program.return_value = "/usr/bin/podman" pm = _cephadm.Podman() find_program.assert_called() @@ -48,7 +51,7 @@ def test_podman_badversion(): def test_docker(): - with mock.patch("cephadm.find_program") as find_program: + with mock.patch(_find_program_loc) as find_program: find_program.return_value = "/usr/bin/docker" docker = _cephadm.Docker() assert str(docker) == "docker (/usr/bin/docker)"