From: Kefu Chai Date: Mon, 10 Nov 2025 04:11:08 +0000 (+0800) Subject: cephadm: fix zip_root_entries population in version command X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6f19802fb457b66e60f81a1e4a545944a5f87cee;p=ceph.git cephadm: fix zip_root_entries population in version command The 'cephadm version --verbose' command was returning an empty zip_root_entries list because it relied on the private '_files' attribute of zipimport.zipimporter, which is not reliably populated across Python versions. This commit fixes the issue by using the zipfile module to properly read the archive contents via the loader.archive path. This ensures that zip_root_entries is correctly populated with the root-level directories in the zipapp. This fix is necessary for the cephadm build tests to properly validate that all expected packages and modules are included in the built zipapp. Signed-off-by: Kefu Chai (cherry picked from commit 2c68c1496dbb7cd01bf783e31510940445040a34) --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index f75aaa86dac..8d08c700868 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -1688,6 +1688,7 @@ def command_version(ctx): # type: (CephadmContext) -> int import importlib import zipimport + import zipfile import types vmod: Optional[types.ModuleType] @@ -1744,10 +1745,17 @@ def command_version(ctx): out['bundled_packages'] = deps_info except OSError: pass - files = getattr(loader, '_files', {}) - out['zip_root_entries'] = sorted( - {p.split('/')[0] for p in files.keys()} - ) + # Use zipfile module to properly read the archive contents + # loader.archive contains the path to the zip file + try: + with zipfile.ZipFile(loader.archive, 'r') as zf: + files = zf.namelist() + out['zip_root_entries'] = sorted( + {p.split('/')[0] for p in files if p} + ) + except (OSError, zipfile.BadZipFile): + # Fallback to empty list if we can't read the zip + out['zip_root_entries'] = [] json.dump(out, sys.stdout, indent=2) print()