Skip to content

Commit 584d144

Browse files
Don't add trace context for almalinux 8
it will need --whitelist-environment for su and thats not supported under almalinux8 Change-Id: Ia2cd8e1dcf1386ccd530926d0d87bdaea802247b
1 parent d69c642 commit 584d144

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/testlib/common/utils.py

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
logger = logging.getLogger(__name__)
3939
tracer = trace.get_tracer()
4040

41+
DISTROS_MISSING_WHITELIST_ENVIRONMENT_FOR_SU = ["almalinux-8"]
42+
4143

4244
def verbose_called_process_error(excp: subprocess.CalledProcessError) -> str:
4345
"""Return a verbose message containing debug information of a `CalledProcessError` exception."""
@@ -276,6 +278,10 @@ def execute(
276278
def _add_trace_context(
277279
kwargs: dict, preserve_env: list[str] | None, sudo: bool
278280
) -> tuple[list[str] | None, dict]:
281+
current_distro = os.environ.get("DISTRO")
282+
if current_distro in DISTROS_MISSING_WHITELIST_ENVIRONMENT_FOR_SU:
283+
logger.info(f"Don't add trace context for {current_distro}")
284+
return preserve_env, kwargs
279285
if trace_env := trace.context_for_environment():
280286
orig_env = kwargs["env"] if kwargs.get("env") else dict(os.environ)
281287
kwargs["env"] = {**orig_env, **trace_env}
@@ -329,6 +335,12 @@ def _cmd_as_user(username: str, preserve_env: list[str] | None = None) -> list[s
329335
"""Extend commandline by adopting rol oe desired user."""
330336
base_cmd = ["su", "-l", username]
331337
if preserve_env:
338+
current_distro = os.environ.get("DISTRO")
339+
if current_distro in DISTROS_MISSING_WHITELIST_ENVIRONMENT_FOR_SU:
340+
raise RuntimeError(
341+
f"Calling 'su' with '--whitelist-environment' is not supported under {current_distro}. "
342+
f"Fix the callsites."
343+
)
332344
base_cmd += ["--whitelist-environment", ",".join(preserve_env)]
333345
base_cmd += ["-c"]
334346
return base_cmd

0 commit comments

Comments
 (0)