]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: avoid unhandled `AttributeError`
authorMichael Fritch <mfritch@suse.com>
Thu, 19 Aug 2021 20:06:32 +0000 (14:06 -0600)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 2 Nov 2021 09:01:16 +0000 (10:01 +0100)
when docker/podman are not present

Fixes: https://tracker.ceph.com/issues/51818
Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit 4d5694a9f0977a22c2a6dac680d594ab3feb070b)

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 87a1b13ed9d45fb8f3391d5606df562688a8e55b..570133aeba5b1b5d60a55986c95cf03419e805b4 100755 (executable)
@@ -1999,8 +1999,7 @@ def find_container_engine(ctx: CephadmContext) -> Optional[ContainerEngine]:
     return None
 
 
-def check_container_engine(ctx):
-    # type: (CephadmContext) -> None
+def check_container_engine(ctx: CephadmContext) -> ContainerEngine:
     engine = ctx.container_engine
     if not isinstance(engine, CONTAINER_PREFERENCE):
         # See https://github.com/python/mypy/issues/8993
@@ -2010,6 +2009,7 @@ def check_container_engine(ctx):
         engine.get_version(ctx)
         if engine.version < MIN_PODMAN_VERSION:
             raise Error('podman version %d.%d.%d or later is required' % MIN_PODMAN_VERSION)
+    return engine
 
 
 def get_unit_name(fsid, daemon_type, daemon_id=None):
@@ -5770,14 +5770,12 @@ def check_time_sync(ctx, enabler=None):
 
 
 def command_check_host(ctx: CephadmContext) -> None:
-    container_path = ctx.container_engine.path
-
     errors = []
     commands = ['systemctl', 'lvcreate']
 
     try:
-        check_container_engine(ctx)
-        logger.info('podman|docker (%s) is present' % container_path)
+        engine = check_container_engine(ctx)
+        logger.info('podman|docker (%s) is present' % engine.path)
     except Error as e:
         errors.append(str(e))
 
index 40afdd42212ea1eb73c093a93850cd9b0e1e9712..d70ec82a3fe31b319436fdf2e202cf76fe16a281 100644 (file)
@@ -1460,4 +1460,21 @@ if ! grep -qs /var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/iscsi.daemon_id
             assert c.old_cname == 'ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9-iscsi.something'
 
 
+class TestCheckHost:
 
+    @mock.patch('cephadm.find_executable', return_value='foo')
+    def test_container_engine(self, find_executable):
+        cmd = ['check-host']
+
+        ctx = cd.CephadmContext()
+        ctx.container_engine = None
+
+        err = r'No container engine binary found'
+        with pytest.raises(cd.Error, match=err):
+            cd.command_check_host(ctx)
+
+        ctx.container_engine = mock_podman()
+        cd.command_check_host(ctx)
+
+        ctx.container_engine = mock_docker()
+        cd.command_check_host(ctx)