summaryrefslogtreecommitdiff
path: root/sandboxlib/__init__.py
diff options
context:
space:
mode:
authorAndrew Leeming <andrew.leeming@codethink.co.uk>2016-10-14 12:28:55 +0100
committerAndrew Leeming <andrew.leeming@codethink.co.uk>2016-10-17 16:56:21 +0100
commitb25338bfbd2f6d5ba2538443f4ac3044a9d91d2f (patch)
treed6ef5f3829f63a05dcda38c66ec3716bd49359b5 /sandboxlib/__init__.py
parentefad18c41aea63c25826c7f0e0faa7644c3a9211 (diff)
downloadsandboxlib-0.4.0.tar.gz
Bubblewrap is the default for executor_for_platform()0.4.0
Previously executor_for_platform() would select linux-user-chroot if availble. New behaviour is to look for bubblewrap first, then linux-user-chroot, else falling back to chroot. To support this, a generic 'get_program()' function was added to both bubblewrap.py and linux_user_chroot.py for interfacing.
Diffstat (limited to 'sandboxlib/__init__.py')
-rw-r--r--sandboxlib/__init__.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/sandboxlib/__init__.py b/sandboxlib/__init__.py
index cdb2fb3..e359b80 100644
--- a/sandboxlib/__init__.py
+++ b/sandboxlib/__init__.py
@@ -23,12 +23,14 @@ docstrings that describe the different parameters.
import logging
+import logging.config
import os
import platform
import pipes
import subprocess
import warnings
+logging.config.fileConfig(os.path.join(os.path.dirname(__file__), 'logger.conf'))
class ProgramNotFound(Exception):
pass
@@ -170,13 +172,19 @@ def executor_for_platform():
"value %s." % backend_name)
if backend is None and platform.uname()[0] == 'Linux':
- log.info("Linux detected, looking for 'linux-user-chroot'.")
- try:
- program = sandboxlib.linux_user_chroot.linux_user_chroot_program()
- log.info("Found %s, choosing 'linux_user_chroot' module.", program)
- backend = sandboxlib.linux_user_chroot
- except sandboxlib.ProgramNotFound as e:
- log.debug("Did not find 'linux-user-chroot': %s", e)
+ # Not all backends may exist, so try them one by one in order of preference
+ prefered_backends = ['bubblewrap', 'linux-user-chroot']
+ for backend_name in prefered_backends:
+
+ log.info("Linux detected, looking for '{}'.".format(backend_name))
+ try:
+ executor = get_executor(backend_name)
+ program = executor.get_program()
+ log.info("Found {}, choosing '{}' module.".format(program,backend_name))
+ backend = executor
+ break
+ except sandboxlib.ProgramNotFound as e:
+ log.warn("Did not find '{}': {}".format(backend_name, e))
if backend is None:
log.info("Choosing 'chroot' sandbox module.")
@@ -187,7 +195,7 @@ def executor_for_platform():
def validate_extra_mounts(extra_mounts):
'''Validate and fill in default values for 'extra_mounts' setting.'''
- if extra_mounts == None:
+ if extra_mounts is None:
return []
new_extra_mounts = []
@@ -246,7 +254,8 @@ def _run_command(argv, stdout, stderr, cwd=None, env=None):
dev_null = None
log = logging.getLogger('sandboxlib')
- log.debug('Running: {}'.format(argv))
+ log.debug('Running: {} ENV: {}'.format(argv,env))
+ log.debug(cwd)
try:
process = subprocess.Popen(