]> git-server-git.apps.pok.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)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 17 Jul 2024 14:51:32 +0000 (16:51 +0200)
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>
(cherry picked from commit be1a8c2c43e97f91bd26554ba9dadc71c499865d)

Conflicts:
src/cephadm/cephadmlib/daemons/iscsi.py [ this file doesn't
  exist in quincy, get_version() lives in src/cephadm/cephadm ]

src/cephadm/cephadm

index 1b7947235c2b72d5970058957b00869f28122b22..6c64a8b6d7fb03c4fe81b407d39f3cfa52925602 100755 (executable)
@@ -875,14 +875,26 @@ 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()
+        return None
 
     def validate(self):
         # type: () -> None