|
6 | 6 | import functools |
7 | 7 | import glob |
8 | 8 | import itertools |
| 9 | +import os |
9 | 10 | import re |
10 | 11 | import shlex |
11 | 12 | import time |
@@ -260,17 +261,35 @@ def emit_preamble(self, job): |
260 | 261 | # Filter out empty statements before returning |
261 | 262 | return list(filter(None, preamble)) |
262 | 263 |
|
| 264 | + def sbatch(self, args): |
| 265 | + '''Run sbatch using a clean environment |
| 266 | +
|
| 267 | + We unset all `SBATCH_*` environment variables before submitting; |
| 268 | + submission should be controlled entirely by ReFrame through the |
| 269 | + partition's `access` options, the test's `job.options` and the |
| 270 | + command-line `-J` option |
| 271 | + ''' |
| 272 | + |
| 273 | + with rt.temp_environment(): |
| 274 | + for var in [name for name in os.environ.keys() |
| 275 | + if name.startswith('SBATCH_')]: |
| 276 | + self.log(f'unsetting environment variable {var}', |
| 277 | + logging.DEBUG) |
| 278 | + del os.environ[var] |
| 279 | + |
| 280 | + cmd = ' '.join(['sbatch'] + args) |
| 281 | + return _run_strict(cmd, timeout=self._submit_timeout) |
| 282 | + |
263 | 283 | def submit(self, job): |
264 | | - cmd_parts = ['sbatch'] |
| 284 | + sbatch_args = [] |
265 | 285 | if self._sched_access_in_submit: |
266 | | - cmd_parts += job.sched_access |
| 286 | + sbatch_args += job.sched_access |
267 | 287 |
|
268 | | - cmd_parts += [job.script_filename] |
269 | | - cmd = ' '.join(cmd_parts) |
| 288 | + sbatch_args += [job.script_filename] |
270 | 289 | intervals = itertools.cycle([1, 2, 3]) |
271 | 290 | while True: |
272 | 291 | try: |
273 | | - completed = _run_strict(cmd, timeout=self._submit_timeout) |
| 292 | + completed = self.sbatch(sbatch_args) |
274 | 293 | break |
275 | 294 | except SpawnedProcessError as e: |
276 | 295 | error_match = re.search( |
|
0 commit comments