From: Michael Fritch Date: Thu, 19 Aug 2021 20:06:32 +0000 (-0600) Subject: cephadm: avoid unhandled `AttributeError` X-Git-Tag: v17.1.0~924^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4d5694a9f0977a22c2a6dac680d594ab3feb070b;p=ceph.git cephadm: avoid unhandled `AttributeError` when docker/podman are not present Fixes: https://tracker.ceph.com/issues/51818 Signed-off-by: Michael Fritch --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 08965051c441..8fdd5f5de4cd 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -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)) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 59559233d714..b67e1430c6d8 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -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)