Skip to content

Commit 5804623

Browse files
Tilix4DiegoTavares
andauthored
[rqd] Feature: RQD use host env vars (#1324)
**Link the Issue(s) this Pull Request is related to.** [Mail list discussion](https://lists.aswf.io/g/opencue-user/topic/run_rqd_in_a_python/101775838?p=,,,20,0,0,0::recentpostdate/sticky,,,20,2,0,101775838,previd%3D1697464276523306623,nextid%3D1689790757197015748&previd=1697464276523306623&nextid=1689790757197015748) **Summarize your change.** Based on `RQD_USE_PATH_ENV_VAR` but generalized to any host env var. --------- Signed-off-by: Diego Tavares <[email protected]> Co-authored-by: Diego Tavares <[email protected]>
1 parent 9eb3ece commit 5804623

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

rqd/rqd/rqconstants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@
7272
# Copy specific environment variable from the RQD host to the frame env.
7373
RQD_HOST_ENV_VARS = []
7474

75+
# Use the environment variables from the RQD host. For variables that exist
76+
# In cases where a variable exists on both the host and the frame object (which are
77+
# copied during initialization), the value from the host will take precedence.
78+
# However, the handling of the PATH variable is unique: its value from the frame
79+
# is merged with the host's value, with the frame's value taking precedence in the
80+
# final result. If any var is defined at RQD_HOST_ENV_VARS, this attribute is considered False.
81+
RQD_USE_ALL_HOST_ENV_VARS = False
82+
7583
RQD_CUSTOM_HOME_PREFIX = None
7684
RQD_CUSTOM_MAIL_PREFIX = None
7785

@@ -219,6 +227,9 @@
219227
"RQD_USE_IPV6_AS_HOSTNAME")
220228
if config.has_option(__override_section, "RQD_USE_PATH_ENV_VAR"):
221229
RQD_USE_PATH_ENV_VAR = config.getboolean(__override_section, "RQD_USE_PATH_ENV_VAR")
230+
if config.has_option(__override_section, "RQD_USE_ALL_HOST_ENV_VARS"):
231+
RQD_USE_HOST_ENV_VARS = config.getboolean(__override_section,
232+
"RQD_USE_ALL_HOST_ENV_VARS")
222233
if config.has_option(__override_section, "RQD_BECOME_JOB_USER"):
223234
RQD_BECOME_JOB_USER = config.getboolean(__override_section, "RQD_BECOME_JOB_USER")
224235
if config.has_option(__override_section, "RQD_TAGS"):

rqd/rqd/rqcore.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def __init__(self, optNimbyoff=False):
7777
self.nimby = rqd.rqnimby.NimbyFactory.getNimby(self)
7878

7979
self.machine = rqd.rqmachine.Machine(self, self.cores)
80-
8180
self.network = rqd.rqnetwork.Network(self)
8281
self.__threadLock = threading.Lock()
8382
self.__cache = {}
@@ -767,10 +766,18 @@ def __createEnvVariables(self):
767766
for variable in ["SYSTEMROOT", "APPDATA", "TMP", "COMMONPROGRAMFILES", "SYSTEMDRIVE"]:
768767
if variable in os.environ:
769768
self.frameEnv[variable] = os.environ[variable]
770-
for variable in rqd.rqconstants.RQD_HOST_ENV_VARS:
771-
# Fallback to empty string, easy to spot what is missing in the log
772-
self.frameEnv[variable] = os.environ.get(variable, '')
773-
769+
if rqd.rqconstants.RQD_HOST_ENV_VARS:
770+
for variable in rqd.rqconstants.RQD_HOST_ENV_VARS:
771+
# Fallback to empty string, easy to spot what is missing in the log
772+
self.frameEnv[variable] = os.environ.get(variable, '')
773+
elif rqd.rqconstants.RQD_USE_ALL_HOST_ENV_VARS:
774+
# Add host environment variables
775+
for key, value in os.environ.items():
776+
# Merge frame PATH with host PATH
777+
if "PATH" == key and key in self.frameEnv:
778+
self.frameEnv[key] += os.pathsep + value
779+
else:
780+
self.frameEnv[key] = value
774781
for key, value in self.runFrame.environment.items():
775782
if key == 'PATH':
776783
self.frameEnv[key] += os.pathsep + value

0 commit comments

Comments
 (0)