From: Kefu Chai Date: Thu, 23 May 2024 23:16:14 +0000 (+0800) Subject: cephadm: extract python() helper to execute python statement X-Git-Tag: v20.0.0~1765^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=be1a8c2c43e97f91bd26554ba9dadc71c499865d;p=ceph.git cephadm: extract python() helper to execute python statement to prepare for a change to use importlib, then fallback to pkg_resources. as the former is only available in Python 3.8, while the latter is deprecated. Refs https://tracker.ceph.com/issues/66201 Signed-off-by: Kefu Chai --- diff --git a/src/cephadm/cephadmlib/daemons/iscsi.py b/src/cephadm/cephadmlib/daemons/iscsi.py index ade88a90af0ff..da03fe36c03f3 100644 --- a/src/cephadm/cephadmlib/daemons/iscsi.py +++ b/src/cephadm/cephadmlib/daemons/iscsi.py @@ -119,22 +119,26 @@ class CephIscsi(ContainerDaemonForm): @staticmethod def get_version(ctx, container_id): # type: (CephadmContext, str) -> Optional[str] - version = None - out, err, code = call( - ctx, - [ - ctx.container_engine.path, - 'exec', - container_id, - '/usr/bin/python3', - '-c', - "import pkg_resources; print(pkg_resources.require('ceph_iscsi')[0].version)", - ], - verbosity=CallVerbosity.QUIET, + def python(s: str) -> Tuple[str, str, int]: + return call( + ctx, + [ + ctx.container_engine.path, + 'exec', + container_id, + '/usr/bin/python3', + '-c', + s, + ], + verbosity=CallVerbosity.QUIET, + ) + + out, _, code = python( + "from importlib.metadata import version; print(version('ceph_iscsi'))" ) if code == 0: - version = out.strip() - return version + return out.strip() + return None def validate(self): # type: () -> None