From 08aa8ad930c1488285263145f01c7e8a9dca59dc Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 8 Oct 2021 19:29:14 +0100 Subject: templates: Inherit environment for the most part We inherit all the environment except we override a few variables in order to provide some level of consistency. Signed-off-by: Daniel Silverstone --- share/bash/template/template.sh.tera | 14 +------------- share/python/template/scenarios.py | 6 ++---- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/share/bash/template/template.sh.tera b/share/bash/template/template.sh.tera index da748be..12d72ea 100644 --- a/share/bash/template/template.sh.tera +++ b/share/bash/template/template.sh.tera @@ -163,20 +163,8 @@ scenario_{{ loop.index }}() { {% endfor %} ############################################################################# -# Make the environment minimal. - -# Write to stdout the names of all environment variables, one per -# line. Handle also cases where the value of an environment variable -# contains newlines. -envnames() -{ - env -0 | sed -z 's/^\([^=]\+\)=.*$/\1/' | tr '\0' '\n' -} +# Update the environment -# Unset all environment variables. At the beginning of each scenario, -# some additional ones will be set to the per-scenario directory. -unset $(envnames) -export PATH=/bin:/usr/bin export SHELL=/bin/sh # Include any configured environment variables diff --git a/share/python/template/scenarios.py b/share/python/template/scenarios.py index 96dcc69..b215133 100644 --- a/share/python/template/scenarios.py +++ b/share/python/template/scenarios.py @@ -83,15 +83,13 @@ class Scenario: def _set_environment_variables_to(self, scendir, extra_env): log_value = globals()["log_value"] - minimal = { - "PATH": "/bin:/usr/bin", + overrides = { "SHELL": "/bin/sh", "HOME": scendir, "TMPDIR": scendir, } - os.environ.clear() - os.environ.update(minimal) + os.environ.update(overrides) os.environ.update(extra_env) if not self._logged_env: self._logged_env = True -- cgit v1.2.1