diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-01-27 17:25:54 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-01-27 18:08:16 +0200 |
commit | 59cb84c15b7410c1ab8999ed2a36841490102332 (patch) | |
tree | 8503781962b1289600c4158839bb034a0a15cf3d | |
parent | b03c2db5a5b8492ebeb63ed5254b182f8603cccb (diff) | |
download | ick2-59cb84c15b7410c1ab8999ed2a36841490102332.tar.gz |
Change: bind mount /proc, /sys into chroot actions
-rw-r--r-- | NEWS | 3 | ||||
-rwxr-xr-x | worker_manager | 32 |
2 files changed, 34 insertions, 1 deletions
@@ -32,6 +32,9 @@ Version 0.23+git, not yet released parameter. The old behaviour of having the suite name as an argument to the `debootstrap` field in the action still works. +* When an action is run in a chroot, the `/proc` and `/sys` + filesystems get bind mounted temporarily into the chroot. + Version 0.23, released 2018-01-22 ---------------------------------- diff --git a/worker_manager b/worker_manager index 81015c2..e2cbc32 100755 --- a/worker_manager +++ b/worker_manager @@ -374,6 +374,30 @@ class Runner: self._post(stream, buf) +class Mounter: + + def __init__(self, mounts, runner): + self._mounts = mounts + self._runner = runner + + def __enter__(self): + self.mount() + return self + + def __exit__(self, *args): + self.unmount() + + def mount(self): + for dirname, mp in self._mounts: + if not os.path.exists(mp): + os.mkdir(mp) + self._runner.runcmd(['sudo', 'mount', '--bind', dirname, mp]) + + def unmount(self): + for dirname, mp in reversed(self._mounts): + self._runner.runcmd(['sudo', 'umount', mp]) + + class WorkerBase: def __init__(self, api, workspace, systree, post): @@ -386,9 +410,14 @@ class WorkerBase: params = work.get('parameters', {}) params_text = self.params64(params) argv = self.get_argv(work, params_text) + mounts = [] if self.where(work) == 'chroot': logging.debug('CHROOT REQUESTED') argv = ['sudo', 'chroot', self._workspace] + argv + mounts = [ + ('/proc', os.path.join(self._workspace, 'proc')), + ('/sys', os.path.join(self._workspace, 'sys')), + ] elif self.where(work) == 'container': logging.debug('CONTAINER REQUESTED') bind = '{}:/workspace'.format(self._workspace) @@ -402,7 +431,8 @@ class WorkerBase: else: logging.debug('HOST REQUESTED') runner = Runner(self._post) - return runner.runcmd(argv, cwd=self._workspace) + with Mounter(mounts, runner): + return runner.runcmd(argv, cwd=self._workspace) def params64(self, params): as_json = json.dumps(params) |