]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common/ceph/smb: add a shim file for configuring grpc imports
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 4 Apr 2026 20:34:32 +0000 (16:34 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 27 May 2026 18:26:53 +0000 (14:26 -0400)
Add a private shim file that can be used by ceph.smb.ctl to choose
the grpc implementation in order to work around issues present in some
grpc versions. These are unfortunately the versions packaged for EL
distros.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/python-common/ceph/smb/ctl/_probe.py [new file with mode: 0644]

diff --git a/src/python-common/ceph/smb/ctl/_probe.py b/src/python-common/ceph/smb/ctl/_probe.py
new file mode 100644 (file)
index 0000000..6a0b9f0
--- /dev/null
@@ -0,0 +1,26 @@
+"""Utility to probe protobuf version and control behavior."""
+
+from typing import Tuple
+
+
+def protobuf_ver_tuple() -> Tuple[int, ...]:
+    import google.protobuf
+
+    ver = tuple(int(p) for p in google.protobuf.__version__.split('.'))
+    return ver
+
+
+def protobuf_choose_impl() -> None:
+    """Work around the crummy old version of protobuf that is available on
+    rhel10. Force the python implementation unless 3.20 or newer because
+    we can monkeypatch the python version but not the c ext version.
+    """
+    import os
+
+    key = 'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'
+    if key in os.environ:
+        return
+    ver = protobuf_ver_tuple()
+    if ver[:2] >= (3, 20):
+        return
+    os.environ[key] = 'python'