Skip to content

Commit

Permalink
Experimental chroot syscall step.
Browse files Browse the repository at this point in the history
  • Loading branch information
alenz33 committed Apr 2, 2015
1 parent 317224d commit ec06b5f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
25 changes: 24 additions & 1 deletion conduct/buildsteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

__all__ = ['BuildStep', 'SystemCall', 'Config', 'TmpDir', 'RmPath',
'Partitioning', 'DevMapper', 'CreateFileSystem', 'Mount',
'MakeDirs', 'Debootstrap']
'MakeDirs', 'Debootstrap', 'ChrootedSystemCall']


class BuildStepMeta(type):
Expand Down Expand Up @@ -287,6 +287,29 @@ def run(self):
finally:
os.chdir(cwd)

class ChrootedSystemCall(BuildStep):
'''
Build step to execute given shell command in a chroot environment.
'''
parameters = {
'command' : Parameter(type=str,
description='command to execute'),
'chrootdir' : Parameter(type=str,
description='Chroot directory',
default='.'),
}

outparameters = {
'commandoutput' : Parameter(type=none_or(str),
description='Command output (if captured)',
default=None)
}

def run(self):
self.commandoutput = chrootedSystemCall(self.chrootdir,
self.command,
log=self.log)




Expand Down
13 changes: 7 additions & 6 deletions conduct/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def mount(dev, mountpoint, flags='', log=None):
systemCall('mount %s %s %s' % (flags, dev, mountpoint),
log=log)

def umount(mountpoint, log=None):
systemCall('umount %s' % mountpoint,
def umount(mountpoint, flags='', log=None):
systemCall('umount %s %s' % (flags, mountpoint),
log=log)

def systemCall(cmd, sh=True, log=None):
Expand Down Expand Up @@ -232,10 +232,11 @@ def chrootedSystemCall(chrootDir, cmd, sh=True, mountPseudoFs=True, log=None):
if mountPseudoFs:
# handle devpts
if path.exists(devpts):
umount(devpts)
umount(dev)
umount(sys)
umount(proc)
umount(devpts, '-lf')
# lazy is ok for pseudo fs
umount(dev, '-lf')
umount(sys, '-lf')
umount(proc, '-lf')



Expand Down

0 comments on commit ec06b5f

Please sign in to comment.