]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: use importlib.metadata for querying ceph_iscsi's version 58323/head
authorZac Dover <zac.dover@proton.me>
Thu, 27 Jun 2024 18:09:50 +0000 (04:09 +1000)
committerZac Dover <zac.dover@proton.me>
Mon, 1 Jul 2024 15:36:55 +0000 (01:36 +1000)
use importlib.metadata for querying ceph_iscsi's version and 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

This commit is functionally equivalent to a Reef-targeted backport of
https://github.com/ceph/ceph/pull/57685.

Signed-off-by: Zac Dover <zac.dover@proton.me>
src/cephadm/cephadm.py

index c718106400f192ed42064f2eded12e7d177e5966..237ccac69a0a134000e52873463b2c6d59ef13b4 100755 (executable)
@@ -1037,15 +1037,32 @@ class CephIscsi(object):
     @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()
+        out, _, code = python(
+            "import pkg_resources; print(pkg_resources.require('ceph_iscsi')[0].version)"
+        )
+
+        if code == 0:
+            return out.strip()
+        return None
 
     def validate(self):
         # type: () -> None