aboutsummaryrefslogtreecommitdiff
path: root/slave
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek.chauhan@gmail.com>2008-07-05 16:09:28 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2008-07-05 16:09:28 +0530
commit057e93420919a79c232297ffb5bb0e45d11215e3 (patch)
tree20b740818dbc901f4294bfaa4f8a03048757dfd6 /slave
parentWorkChroot rsync is now 'rsync-nc' (no-clobber) (diff)
downloadautotua-057e93420919a79c232297ffb5bb0e45d11215e3.tar.gz
autotua-057e93420919a79c232297ffb5bb0e45d11215e3.tar.bz2
autotua-057e93420919a79c232297ffb5bb0e45d11215e3.zip
autotua.chroot.WorkChroot():
- Revamp _clean_mounts() * Reads /proc/mounts to find all mounts inside chrootdir - Move out bind mount code in _setup_mounts() to _bind() - Bind mount ${workdir}/jobtage and autotua/bin into ${chrootdir}/tmp/autotua - Tidy up in setup() before preparing chroot - Move ${chrootdir}/tmp/autotua to ${chrootdir}/tmp/aututua-${timestamp} - Replace useless osp.joins with direct path separators autotua.Job(): - Tidy before cleaning in clean()
Diffstat (limited to 'slave')
-rw-r--r--slave/autotua/__init__.py3
-rw-r--r--slave/autotua/chroot/__init__.py58
2 files changed, 37 insertions, 24 deletions
diff --git a/slave/autotua/__init__.py b/slave/autotua/__init__.py
index 3ab594e..019733a 100644
--- a/slave/autotua/__init__.py
+++ b/slave/autotua/__init__.py
@@ -128,8 +128,9 @@ class Job:
def tidy(self):
print 'Tidying up..'
self.chroot.tidy()
- print 'The workdir has not been removed (default)'
def clean(self):
+ # Tidy up before cleaning
+ self.tidy()
shutil.rmtree(self.jobdir)
os.removedirs(osp.join(const.WORKDIR, self.maint))
diff --git a/slave/autotua/chroot/__init__.py b/slave/autotua/chroot/__init__.py
index 07f41b2..fefc290 100644
--- a/slave/autotua/chroot/__init__.py
+++ b/slave/autotua/chroot/__init__.py
@@ -9,6 +9,7 @@
import os, sys, shutil, subprocess, re
import os.path as osp
from .. import const, sync
+from time import strftime
class PristineChroot(object):
"""
@@ -28,7 +29,7 @@ class PristineChroot(object):
os.makedirs(self.dir)
# Replace with a jobuild.sh unpack later.
subprocess.check_call('tar xf "%s" -C "%s"' % self.tar_args, shell=True)
- os.mkdir(osp.join(self.dir, 'usr', 'portage'))
+ os.mkdir(self.dir+'/usr/portage')
def check(self, fix=False):
"""Verify that the pristine is intact"""
@@ -85,33 +86,39 @@ class WorkChroot(object):
@type job: L{autotua.Job}
"""
self.pristine = PristineChroot(stage_file)
- self.dir = osp.join(jobdir, 'chroot')
+ self.jobdir = jobdir
+ self.chrootdir = osp.join(self.jobdir, 'chroot')
# Hmmmm. Maybe all this should be in a module of it's own.
- def _clean_mounts(self, chrootdir=None):
- if not chrootdir:
- chrootdir = self.dir
- for dir in ['dev', 'proc', 'sys', osp.join('usr','portage')]:
- if osp.ismount(osp.join(chrootdir, dir)):
- result = subprocess.check_call('umount "%s"' % osp.join(chrootdir, dir), shell=True)
- if not result == 0:
- return None
- return True
+ def _clean_mounts(self):
+ # /proc/mounts is more reliable than mtab (which is what `mount` uses)
+ mounts = open('/proc/mounts', 'r').read()
+ regex = re.compile(r'%s/[^ ]+' % self.chrootdir.replace(' ', r'\\040'))
+ for mount in regex.findall(mounts):
+ subprocess.check_call('umount "%s"' % mount.replace(r'\040', ' '), shell=True)
- def _setup_mounts(self, chrootdir=None):
- if not chrootdir:
- chrootdir = self.dir
- for dir in ['dev', 'sys']:
- result = subprocess.check_call('mount -o bind "%s" "%s"' % (osp.join('/', dir), osp.join(chrootdir, dir)), shell=True)
- result = subprocess.check_call('mount -t proc proc "%s"' % osp.join(chrootdir, 'proc'), shell=True)
+ def _bind(self, src, dest):
+ """
+ Bind mount src onto dest inside self.chrootdir
+ """
+ if not dest.startswith('/'):
+ dest = '/'+dest
+ dest = self.chrootdir+dest
+ subprocess.check_call('mount -o bind "%s" "%s"' % (src, dest), shell=True)
+
+ def _setup_mounts(self):
+ for dir in ['/dev', '/sys', '/proc']:
+ self._bind(dir, dir)
if const.PORTAGE_DIR:
if not osp.isdir(const.PORTAGE_DIR):
print "\"%s\" is not a directory, cannot mount" % const.PORTAGE_DIR
- result = subprocess.check_call('mount -o bind "%s" "%s"' % (const.PORTAGE_DIR, osp.join(chrootdir, 'usr', 'portage')), shell=True)
+ self._bind(const.PORTAGE_DIR, '/usr/portage')
if const.DISTFILES_DIR:
if not osp.isdir(const.DISTFILES_DIR):
print "\"%s\" is not a directory, cannot mount" % const.DISTFILES_DIR
- result = subprocess.check_call('mount -o bind "%s" "%s"' % (const.DISTFILES_DIR, osp.join(chrootdir, 'usr', 'portage', 'distfiles')), shell=True)
+ self._bind(const.DISTFILES_DIR, '/usr/portage/distfiles')
+ self._bind(const.AUTOTUA_DIR+'/bin', '/tmp/autotua/bin')
+ self._bind(self.jobdir+'/jobtage', '/tmp/autotua/jobtage')
def setup(self):
"""
@@ -121,10 +128,12 @@ class WorkChroot(object):
"""
if not self.pristine.setup():
return False
- self._clean_mounts()
- # self.chroot.dir/ => rsync *contents* to self.dir
- syncer = sync.Syncer(uri=self.pristine.dir+"/", destdir=self.dir, scheme='rsync-nc')
- syncer.sync()
+ # Tidy up incase we screwed up last time
+ self.tidy()
+ # self.pristine.dir/ => rsync *contents* to self.chrootdir
+ sync.Syncer(uri=self.pristine.dir+"/", destdir=self.chrootdir, scheme='rsync-nc').sync()
+ os.makedirs('%s/tmp/autotua/bin' % self.chrootdir)
+ os.makedirs('%s/tmp/autotua/jobtage' % self.chrootdir)
self._setup_mounts()
print "Work Chroot ready."
@@ -133,3 +142,6 @@ class WorkChroot(object):
Cleanup when done.
"""
self._clean_mounts()
+ if osp.isdir('%s/tmp/autotua' % self.chrootdir):
+ shutil.move('%s/tmp/autotua' % (self.chrootdir),
+ '%s/tmp/autotua-%s' % (self.chrootdir, strftime('%Y%m%d%H%M%S')))