From fae805e3fdac5b798f370eb87781de263e21e459 Mon Sep 17 00:00:00 2001 From: lxnay Date: Tue, 3 Mar 2009 12:20:43 +0000 Subject: [PATCH] Molecule: - implement sandbox support on ChrootHandler git-svn-id: http://svn.sabayonlinux.org/projects/molecule/trunk@3104 cd1c1023-2f26-0410-ae45-c471fc1f0318 --- molecule/handlers.py | 11 ++++++++++- molecule/utils.py | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/molecule/handlers.py b/molecule/handlers.py index 78aa787..bab3d0b 100644 --- a/molecule/handlers.py +++ b/molecule/handlers.py @@ -248,6 +248,15 @@ class ChrootHandler(GenericHandlerInterface): # now remove paths to remove (...) remove_paths = self.metadata.get('paths_to_remove',[]) + + # setup sandbox + sb_dirs = [self.dest_dir] + sb_env = { + 'SANDBOX_WRITE': ':'.join(sb_dirs), + } + myenv = os.environ.copy() + myenv.update(sb_env) + for mypath in remove_paths: mypath = self.dest_dir+mypath self.Output.updateProgress("[%s|%s] %s: %s" % ( @@ -255,7 +264,7 @@ class ChrootHandler(GenericHandlerInterface): _("removing dir"),mypath, ) ) - rc = molecule.utils.remove_path(mypath) + rc = molecule.utils.remove_path_sandbox(mypath, sb_env) if rc != 0: self.Output.updateProgress("[%s|%s] %s: %s: %s" % ( blue("ChrootHandler"),darkred(self.spec_name), diff --git a/molecule/utils.py b/molecule/utils.py index ce94917..728407a 100644 --- a/molecule/utils.py +++ b/molecule/utils.py @@ -19,6 +19,7 @@ from __future__ import with_statement import os +import sys import time import subprocess import shutil @@ -75,5 +76,12 @@ def empty_dir(dest_dir): def remove_path(path): return subprocess.call('rm -rf %s' % (path,), shell = True) +def remove_path_sandbox(path, sandbox_env): + p = subprocess.Popen(["sandbox", "rm", "-rf", path], + stdout = sys.stdout, stderr = sys.stderr, + env = sandbox_env + ) + return p.wait() + def get_random_number(): return abs(hash(os.urandom(2)))%99999