From 2c68c1496dbb7cd01bf783e31510940445040a34 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 10 Nov 2025 12:11:08 +0800 Subject: [PATCH] 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 --- src/cephadm/cephadm.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index fe7dcd688aac7..4e255e551656b 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -1694,6 +1694,7 @@ def command_version(ctx): # type: (CephadmContext) -> int import importlib import zipimport + import zipfile import types vmod: Optional[types.ModuleType] @@ -1750,10 +1751,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() -- 2.39.5