]> 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)
committerMichael Fritch <mfritch@suse.com>
Wed, 25 Aug 2021 13:21:43 +0000 (07:21 -0600)
when docker/podman are not present

Fixes: https://tracker.ceph.com/issues/51818
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 08965051c44111014547e28b6a0c8f0983e7b0c7..8fdd5f5de4cd9292a3c1963a160a83d04a5c9934 100755 (executable)
@@ -2000,8 +2000,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
@@ -2011,6 +2010,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):
@@ -5796,14 +5796,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 59559233d71492b05c4b8bc36ec9b6d05fcf2109..b67e1430c6d8f8cf2fdbaf0a67c8c38c3d897a43 100644 (file)
@@ -1480,4 +1480,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)