diff options
author | 2008-07-06 21:38:41 +0530 | |
---|---|---|
committer | 2008-07-06 21:38:41 +0530 | |
commit | da35f08300367e1841ed4a0c819544f132858e10 (patch) | |
tree | 5fbb47651b7dbb31e3e412ba5f7d59dd94b1a527 | |
parent | autotua.chroot.WorkChroot(): (diff) | |
download | autotua-da35f08300367e1841ed4a0c819544f132858e10.tar.gz autotua-da35f08300367e1841ed4a0c819544f132858e10.tar.bz2 autotua-da35f08300367e1841ed4a0c819544f132858e10.zip |
A revolution in how jobuilds are parsed. All parsing is now done inside the chroot :P
Why? Because everything has to be done in that enviroment stupid!
slave/autotua/jobuild/__init__.py:
- self.jobuild is now relative to the jobtagedir
slave/autotua/bin/jobuild.sh:
- Get AUTOTUA_DIR from autotua.daemon.Spawn()
- Prepend AUTOTUA_DIR (inside the chroot) to the jobuild path
slave/autotua/daemon/__init__.py:
- Chroot all spawned processes
- Send const.CHAUTOTUA_DIR (AUTOTUA_DIR inside the chroot) to the process
slave/autotua/__init__.py:
- Prepare chroot before parsing
-rw-r--r-- | slave/autotua/__init__.py | 6 | ||||
-rw-r--r-- | slave/autotua/bin/jobuild-functions.sh | 9 | ||||
-rwxr-xr-x | slave/autotua/bin/jobuild.sh | 15 | ||||
-rw-r--r-- | slave/autotua/const.py | 3 | ||||
-rw-r--r-- | slave/autotua/daemon/__init__.py | 19 | ||||
-rw-r--r-- | slave/autotua/jobuild/__init__.py | 12 |
6 files changed, 47 insertions, 17 deletions
diff --git a/slave/autotua/__init__.py b/slave/autotua/__init__.py index 019733a..15d68a4 100644 --- a/slave/autotua/__init__.py +++ b/slave/autotua/__init__.py @@ -114,13 +114,15 @@ class Job: #self._fetch_portage_snapshot() def prepare(self): + # Chroot setup needs to be done before parsing jobuilds + # because all parsing is done inside the chroot + print 'Setup the chroot for usage...' + self.chroot.setup() # Create jobuild objects for parsing for atom in self.atoms: self.jobuilds.append(jobuild.Jobuild(self.jobdir, atom)) print 'Fetch jobuild SRC_URI...' self._fetch_src() - print 'Setup the chroot for usage...' - self.chroot.setup() def run(self): print "Rheeet, it's running!~ NOT." diff --git a/slave/autotua/bin/jobuild-functions.sh b/slave/autotua/bin/jobuild-functions.sh index 7bbca8f..6dfda9e 100644 --- a/slave/autotua/bin/jobuild-functions.sh +++ b/slave/autotua/bin/jobuild-functions.sh @@ -9,6 +9,11 @@ # Immortal lh! # +die() { + echo "$*" + exit 1 +} + has() { local this=${1}; shift local those=${@} @@ -26,3 +31,7 @@ get_param() { source "${jobuild}" &>/dev/null eval echo \$${param} } + +get_jobuild_path() { + echo "${AUTOTUA_DIR}/jobtage/${1}" +} diff --git a/slave/autotua/bin/jobuild.sh b/slave/autotua/bin/jobuild.sh index bfd57ec..c75e4ee 100755 --- a/slave/autotua/bin/jobuild.sh +++ b/slave/autotua/bin/jobuild.sh @@ -19,7 +19,7 @@ listen() { } speak() { - echo "$*" >&3 + echo "$*" 1>&3 } listen com @@ -29,21 +29,28 @@ if [ "${com}" != "ping" ]; then fi speak "pong" +listen AUTOTUA_DIR +[ -z "${AUTOTUA_DIR}" ] && die "empty AUTOTUA_DIR variable, bai bai" + get_var() { speak $(get_param "${1}" "${2}") } run_phase() { echo "Placeholder phase \"runner\"" - echo "Running phase \"${1}\" from \"${2}\" inside \"${3}\"" + echo "Running phase \"${1}\" from \"${2}\"" } case "${1}" in GET_VAR) - get_var "${2}" "${3}" + var="${2}" + jobuild="$(get_jobuild_path ${3})" + get_var "${var}" "${jobuild}" ;; RUN_PHASE) - run_phase "${2}" "${3}" "${4}" # phase jobuild chroot + phase="${2}" + jobuild="$(get_jobuild_path ${3})" + run_phase "${phase}" "${jobuild}" ;; *) speak "error: no such action" diff --git a/slave/autotua/const.py b/slave/autotua/const.py index 2946134..de7920c 100644 --- a/slave/autotua/const.py +++ b/slave/autotua/const.py @@ -38,6 +38,9 @@ JOBTAGE_DIR = '/var/tmp/autotua/jobtage' PORTAGE_DIR = '' DISTFILES_DIR = '' +# Autotua variables inside the chroot +CHAUTOTUA_DIR = '/tmp/autotua' + # Let's define a couple of jobs for now. # We'll get them from the server later :P job_list = [ diff --git a/slave/autotua/daemon/__init__.py b/slave/autotua/daemon/__init__.py index 52b971a..35111a5 100644 --- a/slave/autotua/daemon/__init__.py +++ b/slave/autotua/daemon/__init__.py @@ -16,8 +16,12 @@ class Spawn(object): sent to stdin with a 'pong\n' """ - def __init__(self, command, logfile=const.LOGFILE): + def __init__(self, chroot, command, logfile=const.LOGFILE): """ + @param chroot: The path to the chroot in which + the command will be run + @type chroot: string + @param command: The (properly quoted) command to be run in the shell It should listen on stdin and send replies to fd 3 @type command: string @@ -26,10 +30,15 @@ class Spawn(object): # Messages goto 3 and then to /dev/tty1 # stderr goes to stdout # stdout goes to self.logfile - self.command = '%s 3>&2 2>&1 | tee -a \"%s\"' % (command, self.logfile) - self.process = subprocess.Popen(self.command, shell=True, stderr=subprocess.PIPE, stdin=subprocess.PIPE) - self.process.stdin.write('ping\n') - response = self.process.stderr.readline() + self.command = 'chroot \"%s\" /bin/bash -c \'%s\' 3>&2 2>&1 | tee -a \"%s\"' % (chroot, command, self.logfile) + self.process = self._init() + + def _init(self): + process = subprocess.Popen(self.command, shell=True, stderr=subprocess.PIPE, stdin=subprocess.PIPE) + process.stdin.write('ping\n') + response = process.stderr.readline() if not response == 'pong\n': # FIXME: Custom exceptions raise 'Communication error: received %s when expecting "pong"' % response + process.stdin.write(const.CHAUTOTUA_DIR+'\n') + return process diff --git a/slave/autotua/jobuild/__init__.py b/slave/autotua/jobuild/__init__.py index 878b573..f435a77 100644 --- a/slave/autotua/jobuild/__init__.py +++ b/slave/autotua/jobuild/__init__.py @@ -26,7 +26,7 @@ class Jobuild(object): """ self.name = atom self.jobdir = jobdir - self.path = self._best_jobuild(atom) + self.where = self._best_jobuild(atom) def __str__(self): return '%s jobuild object' % self.name @@ -90,7 +90,7 @@ class Jobuild(object): break if i == pv[-1]: # If it's the last pv.. raise 'No matching jobuild found for atom \"%s\"' % atom - return '%(jobtage)s/%(maint)s/%(pn)s/%(pn)s-%(pv)s.jobuild' % data + return '%(maint)s/%(pn)s/%(pn)s-%(pv)s.jobuild' % data class Processor(object): """Jobuild processor""" @@ -109,8 +109,8 @@ class Processor(object): def run_phase(self, phase): """Run the specified phase of the jobuild""" args = {'phase': phase, - 'jobuild': self.jobuild.path, - 'chroot': self.chroot.dir,} + 'jobuild': self.jobuild.where, + 'chroot': self.chroot.chrootdir,} self._msg('RUN_PHASE "%(phase)s" "%(jobuild)s" "%(chroot)s"' % args) def get_var(self, var): @@ -119,10 +119,10 @@ class Processor(object): (yay-something-works function) """ args = {'var': var, - 'jobuild': self.jobuild.path,} + 'jobuild': self.jobuild.where,} return self._msg('GET_VAR "%(var)s" "%(jobuild)s"' % args) def _msg(self, msg): - proc = daemon.Spawn('\"%s\"/bin/jobuild.sh %s' % (const.AUTOTUA_DIR, msg)) + proc = daemon.Spawn(self.chroot.chrootdir, '\"%s\"/bin/jobuild.sh %s' % (const.CHAUTOTUA_DIR, msg)) response = proc.process.stderr.read()[:-1] # Remove trailing newline return response |