summaryrefslogtreecommitdiff
path: root/morphlib/builder2.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-10-30 15:50:27 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-10-30 15:50:27 +0000
commit242e16e592da6ef0bb3b8f36ba5ce3eb01c0c1ba (patch)
tree254098f8d4597e206cf674172caffd6c7f510424 /morphlib/builder2.py
parentf786b2f6f4b4db8c3410c4e8991c36df8d752a27 (diff)
parent53ce07c7062fc5bad7fa4c470b1824393474277d (diff)
downloadmorph-242e16e592da6ef0bb3b8f36ba5ce3eb01c0c1ba.tar.gz
Merge branch 'baserock/richardmaw-os/unify-namespace-logic'
This removes the last case of global mounting that could cause issues for being able to run multiple builds in parallel. There's still concurrent access to caches and git servers that could cause issues, but with this, it's possible to run morph in the test-suite in parallel. Reviewed-by: Daniel Silverstone Reviewed-by: Sam Thursfield
Diffstat (limited to 'morphlib/builder2.py')
-rw-r--r--morphlib/builder2.py60
1 files changed, 5 insertions, 55 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 8615ed59..f71f21db 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -28,7 +28,6 @@ import time
import traceback
import subprocess
import tempfile
-import textwrap
import gzip
import cliapp
@@ -647,53 +646,6 @@ class SystemBuilder(BuilderBase): # pragma: no cover
os.chmod(os_release_file, 0644)
- def _chroot_runcmd(self, rootdir, to_mount, env, *args):
- # We need to do mounts in a different namespace. Unfortunately
- # this means we have to in-line the mount commands in the
- # command-line.
- command = textwrap.dedent(r'''
- mount --make-rprivate /
- rootdir="$1"
- shift
- ''')
- cmdargs = [rootdir]
-
- # We need to mount all the specified mounts in the namespace,
- # we don't need to unmount them before exiting, as they'll be
- # unmounted when the namespace is no longer used.
- command += textwrap.dedent(r'''
- while true; do
- case "$1" in
- --)
- shift
- break
- ;;
- *)
- mount_point="$1"
- mount_type="$2"
- mount_source="$3"
- shift 3
- path="$rootdir/$mount_point"
- mount -t "$mount_type" "$mount_source" "$path"
- ;;
- esac
- done
- ''')
- for mount_opts in to_mount:
- cmdargs.extend(mount_opts)
- cmdargs.append('--')
-
- command += textwrap.dedent(r'''
- exec chroot "$rootdir" "$@"
- ''')
- cmdargs.extend(args)
-
- # The single - is just a shell convention to fill $0 when using -c,
- # since ordinarily $0 contains the program name.
- cmdline = ['unshare', '--mount', '--', 'sh', '-ec', command, '-']
- cmdline.extend(cmdargs)
- self.app.runcmd(cmdline, env=env)
-
def run_system_integration_commands(self, rootdir): # pragma: no cover
''' Run the system integration commands '''
@@ -708,18 +660,16 @@ class SystemBuilder(BuilderBase): # pragma: no cover
self.app.status(msg='Running the system integration commands')
to_mount = (
- ('proc', 'proc', 'none'),
('dev/shm', 'tmpfs', 'none'),
('tmp', 'tmpfs', 'none'),
)
try:
- for mount_point, mount_type, source in to_mount:
- path = os.path.join(rootdir, mount_point)
- if not os.path.exists(path):
- os.makedirs(path)
for bin in sorted(os.listdir(sys_integration_dir)):
- self._chroot_runcmd(rootdir, to_mount, env,
- os.path.join(SYSTEM_INTEGRATION_PATH, bin))
+ self.app.runcmd(
+ morphlib.util.containerised_cmdline(
+ [os.path.join(SYSTEM_INTEGRATION_PATH, bin)],
+ root=rootdir, mounts=to_mount, mount_proc=True),
+ env=env)
except BaseException, e:
self.app.status(
msg='Error while running system integration commands',