From 4ecc0a2d6baed953e9d404143acc91f564b8bc99 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Sat, 4 Apr 2026 16:34:32 -0400 Subject: [PATCH] python-common/ceph/smb: add a shim file for configuring grpc imports 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 --- src/python-common/ceph/smb/ctl/_probe.py | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/python-common/ceph/smb/ctl/_probe.py diff --git a/src/python-common/ceph/smb/ctl/_probe.py b/src/python-common/ceph/smb/ctl/_probe.py new file mode 100644 index 00000000000..6a0b9f00f1e --- /dev/null +++ b/src/python-common/ceph/smb/ctl/_probe.py @@ -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' -- 2.47.3