From 8e35c394f7bdbfc14e24c0a56d5b90373e65a6bc Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 23 Jan 2014 12:56:30 +0100 Subject: [PATCH] using virsh lxc-enter-namespace instead of lxcsu first this is better b/c it removes a dependency second it should improve our ability to run debian build containers drawback is the lack of a PATH-searching feature --- build.common | 18 +++++++++++++++++- lbuild-initvm.sh | 19 ++----------------- lbuild-nightly.sh | 44 +++++++++++++++++++------------------------- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/build.common b/build.common index 527d222e..08b8feae 100644 --- a/build.common +++ b/build.common @@ -7,11 +7,27 @@ # Copyright (C) 2007 The Trustees of Princeton University # Thierry Parmentelat INRIA # -# supported distros f8, f12, f14, f16, f18, centos5, sl6 +# supported distros f12 f14 f16 f18 f20 +# and debians/ubuntus to a lesser extent # # for locating pkgs.py export PATH=.:$PATH +# old guests have e.g. mount in /bin but this is no longer part of +# the standard PATH in recent hosts after usrmove, so let's keep it simple +export PATH=$PATH:/bin:/sbin + +# would be much simpler if enter-lxc-namespace was looking along a PATH... +function bin_in_container () { + lxc=$1; shift + binary=$1; shift + for path in $(echo $PATH | sed -e s,:, ); do + [ -f /vservers/$lxc/$path/$binary ] && { echo $path/$binary; return; } + [ -f /vservers/$lxc/rootfs/$path/$binary ] && { echo $path/$binary; return; } + done + echo bin_in_container_cannot_find_$binary +} + # returns 'Fedora' or 'CentOS' for now function pl_getDistro() { if [ -f "/etc/redhat-release" ] ; then diff --git a/lbuild-initvm.sh b/lbuild-initvm.sh index 193be78d..886bff1b 100755 --- a/lbuild-initvm.sh +++ b/lbuild-initvm.sh @@ -8,11 +8,7 @@ DIRNAME=$(dirname $0) BUILD_DIR=$(pwd) # pkgs parsing utilities -PATH=$(dirname $0):$PATH export PATH - -# old guests have e.g. mount in /bin but this is no longer part of -# the standard PATH in recent hosts after usrmove, so let's keep it simple -PATH=$PATH:/bin:/sbin export PATH +export PATH=$(dirname $0):$PATH . build.common @@ -749,17 +745,6 @@ function devel_or_vtest_tools () { return 0 } -# would be much simpler if enter-lxc-namespace was looking along a PATH... -function bin_in_container () { - binary=$1; shift - lxc=$1; shift - - for path in /sbin /bin /usr/bin /usr/sbin; do - [ -f $rootfs_path/$path/$binary ] && { echo $path/$binary; return; } - done - echo bin_in_container_cannot_find_$binary -} - function post_install () { lxc=$1; shift personality=$1; shift @@ -767,7 +752,7 @@ function post_install () { post_install_build $lxc $personality lxc_start $lxc # manually run dhclient in guest - somehow this network won't start on its own - virsh -c lxc:/// lxc-enter-namespace $lxc $(bin_in_container dhclient $lxc) $VIF_GUEST + virsh -c lxc:/// lxc-enter-namespace $lxc $(bin_in_container $lxc dhclient) $VIF_GUEST else post_install_myplc $lxc $personality lxc_start $lxc diff --git a/lbuild-nightly.sh b/lbuild-nightly.sh index 6bb142c5..2b2f2c48 100755 --- a/lbuild-nightly.sh +++ b/lbuild-nightly.sh @@ -1,19 +1,11 @@ #!/bin/bash -# NOTE on lxcsu -# this tool derives from the PL code, from the lxc-userspace module -# can be obtained through rpm/yum -# it is used here as a replacement for 'vserver <> exec' -# that is used throughout this code -RUN_IN_DOMAIN="lxcsu -ro" -# PS. -# virsh lxc-enter-namespace $dom command to run -# could maybe be used instead but it seems to require command's full path.. -#RUN_IN_DOMAIN="virsh lxc-enter-namespace" - COMMANDPATH=$0 COMMAND=$(basename $0) +# needed only so we can share bin_in_container +. build.common + # default values, tunable with command-line options DEFAULT_FCDISTRO=f20 DEFAULT_PLDISTRO=planetlab @@ -219,6 +211,12 @@ function success () { exit 0 } +############################## +# manage root / container contexts +function in_root_context () { + rpm -q libvirt > /dev/null +} + # run in the vm - do not manage success/failure, will be done from the root ctx function build () { set -x @@ -293,7 +291,7 @@ function run_log () { ssh -n ${testmaster_ssh} rm -rf ${testdir} ${testdir}.git # check it out in the build - $RUN_IN_DOMAIN $BASE -- make -C /build tests-module + virsh -c lxc:/// lxc-enter-namespace $BASE -- $(bin_in_container $BASE make) -C /build tests-module # push it onto the testmaster - just the 'system' subdir is enough rsync --verbose --archive $(rootdir $BASE)/build/MODULES/tests/system/ ${testmaster_ssh}:${BASE} @@ -324,10 +322,6 @@ function run_log () { } -function in_root_context () { - rpm -q libvirt > /dev/null -} - # this part won't work if WEBHOST does not match the local host # would need to be made webpublish_* compliant # but do we really need this feature anyway ? @@ -622,19 +616,19 @@ function main () { set -x echo "XXXXXXXXXX $COMMAND: using existing vm $BASE" $(date) # start in case e.g. we just rebooted - virsh --connect lxc:/// start ${BASE} || : + virsh -c lxc:/// start ${BASE} || : # retrieve environment from the previous run - FCDISTRO=$($RUN_IN_DOMAIN ${BASE} /build/getdistroname.sh) - BUILD_SCM_URL=$($RUN_IN_DOMAIN ${BASE} -- make --no-print-directory -C /build stage1=skip +build-GITPATH) + FCDISTRO=$(virsh -c lxc:/// lxc-enter-namespace ${BASE} /build/getdistroname.sh) + BUILD_SCM_URL=$(virsh -c lxc:/// lxc-enter-namespace ${BASE} -- $(bin_in_container $BASE make) --no-print-directory -C /build stage1=skip +build-GITPATH) # for efficiency, crop everything in one make run tmp=/tmp/${BASE}-env.sh - $RUN_IN_DOMAIN ${BASE} -- make --no-print-directory -C /build stage1=skip \ + virsh -c lxc:/// lxc-enter-namespace ${BASE} -- $(bin_in_container $BASE make) --no-print-directory -C /build stage1=skip \ ++PLDISTRO ++PLDISTROTAGS ++PERSONALITY ++MAILTO ++WEBPATH ++TESTBUILDURL ++WEBROOT > $tmp . $tmp rm -f $tmp # update build [ -n "$SSH_KEY" ] && setupssh ${BASE} ${SSH_KEY} - $RUN_IN_DOMAIN $BASE -- "cd /build; git pull; make tests-clean" + virsh -c lxc:/// lxc-enter-namespace $BASE /bin/bash -c "cd /build; git pull; make tests-clean" # make sure we refresh the tests place in case it has changed rm -f /build/MODULES/tests options=(${options[@]} -d $PLDISTRO -t $PLDISTROTAGS -s $BUILD_SCM_URL) @@ -682,7 +676,7 @@ function main () { # Extract build again - in the vm [ -n "$SSH_KEY" ] && setupssh ${BASE} ${SSH_KEY} # xxx not working as of now - waiting for Sapan to look into this - $RUN_IN_DOMAIN $BASE -- "git clone $GIT_REPO /build; cd /build; git checkout $GIT_TAG" + virsh -c lxc:/// lxc-enter-namespace $BASE /bin/bash -c "git clone $GIT_REPO /build; cd /build; git checkout $GIT_TAG" fi echo "XXXXXXXXXX $COMMAND: preparation of vm $BASE done" $(date) @@ -714,8 +708,8 @@ function main () { cp $COMMANDPATH $(rootdir ${BASE})/build/ # invoke this command in the vm for building (-T) - $RUN_IN_DOMAIN ${BASE} chmod +x /build/$COMMAND - $RUN_IN_DOMAIN ${BASE} -- /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}" + virsh -c lxc:/// lxc-enter-namespace ${BASE} $(bin_in_container $BASE chmod) +x /build/$COMMAND + virsh -c lxc:/// lxc-enter-namespace ${BASE} /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}" fi # publish to the web so run_log can find them @@ -729,7 +723,7 @@ function main () { else # run scanpackages so we can use apt-get on this # (not needed on fedora b/c this is done by the regular build already) - $RUN_IN_DOMAIN $BASE -- -c "(cd /build ; dpkg-scanpackages DEBIAN/ | gzip -9c > Packages.gz)" + virsh -c lxc:/// lxc-enter-namespace $BASE /bin/bash -c "(cd /build ; dpkg-scanpackages DEBIAN/ | gzip -9c > Packages.gz)" webpublish mkdir -p $WEBPATH/$BASE/DEBIAN webpublish_rsync_files $WEBPATH/$BASE/DEBIAN/ $(rootdir $BASE)/build/DEBIAN/*.deb webpublish_rsync_files $WEBPATH/$BASE/ $(rootdir $BASE)/build/Packages.gz -- 2.43.0