]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: move ContainerEngine to container_engine_base.py
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 16 Aug 2023 19:38:50 +0000 (15:38 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 30 Aug 2023 17:57:42 +0000 (13:57 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Pair-programmed-with: Adam King <adking@redhat.com>
Co-authored-by: Adam King <adking@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/container_engine_base.py [new file with mode: 0644]
src/cephadm/tests/test_container_engine.py

index 9a89bac6e7cf000d3c499abb702fe2c5a27c9f71..6294c08bba16db431cfcc1d0049ac708d329aebb 100755 (executable)
@@ -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 (file)
index 0000000..135b2f4
--- /dev/null
@@ -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})'
index 433f0127001bf02787567d8e8bb7799d70a724ae..9998f85d3bd72dcaaf164518c7e6a7d376aea1f1 100644 (file)
@@ -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)"