diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2018-10-02 11:49:19 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2018-10-04 10:04:21 +0100 |
commit | df0d5a8b704c828357d0dbb8c37ab2c4e7d36ae6 (patch) | |
tree | acf8f44151c7d9c859500617c66ea2fad43da1a7 | |
parent | b9ddcd0e9115ce232d8641cff569f4034bac4fd3 (diff) | |
download | buildstream-df0d5a8b704c828357d0dbb8c37ab2c4e7d36ae6.tar.gz |
_platform/linux.py: Refactor checks for sandboxing
To better report issues in the absence of a suitable bwrap, or the
FUSE devices, this refactors the checks for sandboxing in the Linux
platform to cover the various possibilities. The reasons are then
collated and passed to the dummy sandbox for later reporting to the
user if a local build is attempted.
Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-rw-r--r-- | buildstream/_platform/linux.py | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py index 97fbb47be..09db19f2d 100644 --- a/buildstream/_platform/linux.py +++ b/buildstream/_platform/linux.py @@ -37,25 +37,27 @@ class Linux(Platform): self._uid = os.geteuid() self._gid = os.getegid() + self._have_fuse = os.path.exists("/dev/fuse") + self._bwrap_exists = _site.check_bwrap_version(0, 0, 0) + self._have_good_bwrap = _site.check_bwrap_version(0, 1, 2) + + self._local_sandbox_available = self._have_fuse and self._have_good_bwrap + self._die_with_parent_available = _site.check_bwrap_version(0, 1, 8) - if self._local_sandbox_available(): + if self._local_sandbox_available: self._user_ns_available = self._check_user_ns_available() else: self._user_ns_available = False def create_sandbox(self, *args, **kwargs): - if not self._local_sandbox_available(): - return SandboxDummy(*args, **kwargs) + if not self._local_sandbox_available: + return self._create_dummy_sandbox(*args, **kwargs) else: - from ..sandbox._sandboxbwrap import SandboxBwrap - # Inform the bubblewrap sandbox as to whether it can use user namespaces or not - kwargs['user_ns_available'] = self._user_ns_available - kwargs['die_with_parent_available'] = self._die_with_parent_available - return SandboxBwrap(*args, **kwargs) + return self._create_bwrap_sandbox(*args, **kwargs) def check_sandbox_config(self, config): - if not self._local_sandbox_available(): + if not self._local_sandbox_available: # Accept all sandbox configs as it's irrelevant with the dummy sandbox (no Sandbox.run). return True @@ -70,11 +72,26 @@ class Linux(Platform): ################################################ # Private Methods # ################################################ - def _local_sandbox_available(self): - try: - return os.path.exists(utils.get_host_tool('bwrap')) and os.path.exists('/dev/fuse') - except utils.ProgramNotFoundError: - return False + + def _create_dummy_sandbox(self, *args, **kwargs): + reasons = [] + if not self._have_fuse: + reasons.append("FUSE is unavailable") + if not self._have_good_bwrap: + if self._bwrap_exists: + reasons.append("`bwrap` is too old (bst needs at least 0.1.2)") + else: + reasons.append("`bwrap` executable not found") + + kwargs['dummy_reason'] = " and ".join(reasons) + return SandboxDummy(*args, **kwargs) + + def _create_bwrap_sandbox(self, *args, **kwargs): + from ..sandbox._sandboxbwrap import SandboxBwrap + # Inform the bubblewrap sandbox as to whether it can use user namespaces or not + kwargs['user_ns_available'] = self._user_ns_available + kwargs['die_with_parent_available'] = self._die_with_parent_available + return SandboxBwrap(*args, **kwargs) def _check_user_ns_available(self): # Here, lets check if bwrap is able to create user namespaces, |