Skip to content

Commit ab67e5a

Browse files
authored
Merge pull request ceph#57685 from tchaikov/replace-pkg_resources-with-importlib
cephadm: use importlib.metadata for querying ceph_iscsi's version Reviewed-by: Adam King <[email protected]> Reviewed-by: John Mulligan <[email protected]>
2 parents 4169c63 + cbd4bed commit ab67e5a

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/cephadm/cephadmlib/daemons/iscsi.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,31 @@ def customize_container_binds(
119119
@staticmethod
120120
def get_version(ctx, container_id):
121121
# type: (CephadmContext, str) -> Optional[str]
122-
version = None
123-
out, err, code = call(
124-
ctx,
125-
[
126-
ctx.container_engine.path,
127-
'exec',
128-
container_id,
129-
'/usr/bin/python3',
130-
'-c',
131-
"import pkg_resources; print(pkg_resources.require('ceph_iscsi')[0].version)",
132-
],
133-
verbosity=CallVerbosity.QUIET,
122+
def python(s: str) -> Tuple[str, str, int]:
123+
return call(
124+
ctx,
125+
[
126+
ctx.container_engine.path,
127+
'exec',
128+
container_id,
129+
'/usr/bin/python3',
130+
'-c',
131+
s,
132+
],
133+
verbosity=CallVerbosity.QUIET,
134+
)
135+
136+
out, _, code = python(
137+
"from importlib.metadata import version; print(version('ceph_iscsi'))"
138+
)
139+
if code == 0:
140+
return out.strip()
141+
out, _, code = python(
142+
"import pkg_resources; print(pkg_resources.require('ceph_iscsi')[0].version)"
134143
)
135144
if code == 0:
136-
version = out.strip()
137-
return version
145+
return out.strip()
146+
return None
138147

139148
def validate(self):
140149
# type: () -> None

0 commit comments

Comments
 (0)