diff --git a/docs/config_reference.rst b/docs/config_reference.rst index 68bd5ed1c..d9178649c 100644 --- a/docs/config_reference.rst +++ b/docs/config_reference.rst @@ -351,6 +351,7 @@ System Partition Configuration The Slurm-based backends unset all ``SBATCH_*`` environment variables before submitting a job. This is done to avoid environment variables bypassing ReFrame's configuration. For example, if the :attr:`~config.systems.partitions.access` options for a partition used ``-A foo`` and ``SBATCH_ACCOUNT=bar`` was set, then the environment variable would override the configuration, as ReFrame emits those (by default) in the submission script. + If this is not desired, environment variables can be explicitly whitelisted using the :attr:`~config.systems.partitions.sched_options.slurm_envvar_whitelist` option. Job submission in ReFrame is controlled exclusively by the system partition's :attr:`~config.systems.partitions.access` options, the test job's :attr:`~reframe.core.schedulers.Job.options` and the :option:`-J` command-line option. @@ -511,6 +512,18 @@ System Partition Configuration .. versionadded:: 4.8 +.. py:attribute:: systems.partitions.sched_options.slurm_envvar_whitelist + + :required: No + :default: ``[]`` + + List of Slurm environment variables that will not be unset when submitting a job. + + This option is relevant for the Slurm backends only. + + .. versionadded:: 4.10 + + .. py:attribute:: systems.partitions.sched_options.slurm_job_cancel_reasons :required: No diff --git a/reframe/core/schedulers/slurm.py b/reframe/core/schedulers/slurm.py index 1b23f89d1..df68f0953 100644 --- a/reframe/core/schedulers/slurm.py +++ b/reframe/core/schedulers/slurm.py @@ -142,6 +142,7 @@ def __init__(self): 'PLANNED', 'RESERVED' } + self._envvar_whitelist = set(self.get_option('slurm_envvar_whitelist')) # Define the base sacct and squeue commands to account for Slurm's # multiple cluster mode if enabled @@ -282,7 +283,8 @@ def sbatch(self, args): with rt.temp_environment(): for var in [name for name in os.environ.keys() - if name.startswith('SBATCH_')]: + if name.startswith('SBATCH_') and + name not in self._envvar_whitelist]: self.log(f'unsetting environment variable {var}', logging.DEBUG) del os.environ[var] diff --git a/reframe/schemas/config.json b/reframe/schemas/config.json index dbe9329f2..668cac0ee 100644 --- a/reframe/schemas/config.json +++ b/reframe/schemas/config.json @@ -119,6 +119,10 @@ "type": "array", "items": {"type": "string"} }, + "slurm_envvar_whitelist": { + "type": "array", + "items": {"type": "string"} + }, "slurm_job_cancel_reasons": { "type": "array", "items": {"type": "string"} @@ -720,6 +724,7 @@ "systems*/sched_options/slurm_multi_cluster_mode": [], "systems*/sched_options/ssh_hosts": [], "systems*/sched_options/resubmit_on_errors": [], + "systems*/sched_options/slurm_envvar_whitelist": [], "systems*/sched_options/slurm_job_cancel_reasons": ["ReqNodeNotAvail"], "systems*/sched_options/slurm_pending_job_reason_poll_freq": 10, "systems*/sched_options/unqualified_hostnames": false,