summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <ssssam@gmail.com>2015-11-25 16:51:35 +0000
committerSam Thursfield <ssssam@gmail.com>2015-11-25 16:51:35 +0000
commitce30050daa10fa32801e8f798911b36aa82343a4 (patch)
treeb8f32bb848c5137f629207bb399be77f5a7679df
parentc38fcea43111826b8ea499813fb10459ed29dae8 (diff)
parent5c4b805dbdc83ef4269d0990dc4ed481ebb3d5ff (diff)
downloadsandboxlib-ce30050daa10fa32801e8f798911b36aa82343a4.tar.gz
Merge pull request #14 from fishface60/mount-more-flexibility
Mount more flexibility
-rw-r--r--sandboxlib/chroot.py17
-rw-r--r--sandboxlib/linux_user_chroot.py8
2 files changed, 22 insertions, 3 deletions
diff --git a/sandboxlib/chroot.py b/sandboxlib/chroot.py
index b5d2da5..9724368 100644
--- a/sandboxlib/chroot.py
+++ b/sandboxlib/chroot.py
@@ -101,8 +101,18 @@ def mount(source, path, mount_type, mount_options):
# little sad. It's possible to call the libc's mount() function
# directly from Python using the 'ctypes' library, and perhaps we
# should do that instead.
- argv = [
- 'mount', '-t', mount_type, '-o', mount_options, source, path]
+ def is_none(value):
+ return value in (None, 'none', '')
+
+ argv = ['mount']
+ if not is_none(mount_type):
+ argv.extend(('-t', mount_type))
+ if not is_none(mount_options):
+ argv.extend(('-o', mount_options))
+ if not is_none(source):
+ argv.append(source)
+ argv.append(path)
+
exit, out, err = sandboxlib._run_command(
argv, stdout=sandboxlib.CAPTURE, stderr=sandboxlib.CAPTURE)
@@ -137,7 +147,8 @@ def mount_all(rootfs_path, mount_info_list):
os.makedirs(path)
mount(source, path, mount_type, mount_options)
- mounted.append(path)
+ if not mount_options or 'remount' not in mount_options:
+ mounted.append(path)
yield
finally:
diff --git a/sandboxlib/linux_user_chroot.py b/sandboxlib/linux_user_chroot.py
index 943bde5..979d5d5 100644
--- a/sandboxlib/linux_user_chroot.py
+++ b/sandboxlib/linux_user_chroot.py
@@ -100,6 +100,14 @@ def args_for_mount(mount_source, mount_target, mount_type, mount_options,
mount_type)
else:
args = ['--mount-bind', mount_source, mount_target]
+ elif mount_options and all(opt in mount_options.split(",")
+ for opt in ("remount", "ro")):
+ if not is_none(mount_type):
+ raise AssertionError(
+ "Type cannot be specified for 'remount,ro' mounts. Got '%s'" %
+ mount_type)
+ else:
+ args = ['--mount-readonly', mount_target]
else:
raise AssertionError(
"Unsupported mount type '%s' for linux-user-chroot backend." %