Skip to content

Commit

Permalink
Add new option admin_environment
Browse files Browse the repository at this point in the history
- This is environment which is intended to be passed only to the batch
  commands, not to the user servers.  However, it is unknown if any
  spawners support this.  Don't rely on it unless the spawner
  explicitely says it supports it.
  • Loading branch information
rkdarst committed Sep 6, 2018
1 parent 1238f67 commit 786f903
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ shell which will execute arbitrary user environment configuration
access to their own cluster user account. This is something which we
are working on.

The `admin_environment` option claims to pass environment only to the
batch spawners, and not the user servers. This relies on each spawner
handling environment correctly, and this is *not* checked so you
should *not* rely on this yet.

## Provide different configurations of BatchSpawner

Expand Down Expand Up @@ -162,6 +166,7 @@ Added (user)
* Add new option exec_prefix, which defaults to `sudo -E -u {username}`. This replaces explicit `sudo` in every batch command - changes in local commands may be needed.
* Add `req_prologue` and `req_epilogue` options to scripts which are inserted before/after the main jupyterhub-singleuser command, which allow for generic setup/cleanup without overriding the entire script. #96
* SlurmSpawner: add the `req_reservation` option. #
* Add the option `admin_environment` which get passed to the batch submission commands (like for authentication) but *not* to the `--export=keepvars` options. This *should* mean that it is not passed to the user, but not every spawner is checked, so this should *not* be relied on.

Added (developer)

Expand Down
2 changes: 2 additions & 0 deletions SPAWNERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ environment to be used, set `req_srun=''`. However, this is not
perfect: there is still a bash shell begun as the user which could run
arbitrary startup, define shell aliases for `srun`, etc.

`admin_environment` does work with SlurmSpawner.

Use of `srun` is required to gracefully terminate.


Expand Down
17 changes: 17 additions & 0 deletions batchspawner/batchspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ def parse_job_id(self, output):
def cmd_formatted_for_batch(self):
return ' '.join(self.cmd + self.get_args())

def get_admin_env(self):
"""Get the environment passed to the batch submit/cancel/etc commands.
This contains all of the output from self.get_env(), plus any
variables defined in self.admin_environment. In fact, only this
command is used to pass to batch commands, and the only use of
self.get_env() is producing the list of variables to be
--export='ed to. Everything in get_env *must* also be in here
or else it won't be used.
"""
env = self.get_env()
if self.admin_environment:
for key in self.admin_environment.split(','):
if key in os.environ and key not in env:
env[key] = os.environ[key]
return env

@gen.coroutine
def run_command(self, cmd, input=None, env=None):
proc = Subprocess(cmd, shell=True, env=env, stdin=Subprocess.STREAM, stdout=Subprocess.STREAM,stderr=Subprocess.STREAM)
Expand Down

0 comments on commit 786f903

Please sign in to comment.