]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: extract python() helper to execute python statement
authorKefu Chai <tchaikov@gmail.com>
Thu, 23 May 2024 23:16:14 +0000 (07:16 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sun, 26 May 2024 03:09:27 +0000 (11:09 +0800)
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 <tchaikov@gmail.com>
src/cephadm/cephadmlib/daemons/iscsi.py

index ade88a90af0ffe7f380877d52f272775158cb37c..da03fe36c03f3b3033af2cecf0a21555a9224aca 100644 (file)
@@ -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