]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: fix zip_root_entries population in version command
authorKefu Chai <k.chai@proxmox.com>
Mon, 10 Nov 2025 04:11:08 +0000 (12:11 +0800)
committerKefu Chai <k.chai@proxmox.com>
Fri, 14 Nov 2025 13:20:59 +0000 (21:20 +0800)
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 <k.chai@proxmox.com>
(cherry picked from commit 2c68c1496dbb7cd01bf783e31510940445040a34)

src/cephadm/cephadm.py

index f75aaa86dac6835a64ff70fa863089c2f2a68d22..8d08c700868e3355642395549a1c2a5a9c606f48 100755 (executable)
@@ -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()