summaryrefslogtreecommitdiff
path: root/worker_manager
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-01-27 17:25:54 +0200
committerLars Wirzenius <liw@liw.fi>2018-01-27 18:08:16 +0200
commit59cb84c15b7410c1ab8999ed2a36841490102332 (patch)
tree8503781962b1289600c4158839bb034a0a15cf3d /worker_manager
parentb03c2db5a5b8492ebeb63ed5254b182f8603cccb (diff)
downloadick2-59cb84c15b7410c1ab8999ed2a36841490102332.tar.gz
Change: bind mount /proc, /sys into chroot actions
Diffstat (limited to 'worker_manager')
-rwxr-xr-xworker_manager32
1 files changed, 31 insertions, 1 deletions
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)