From daf7a8b942549aad2bc828be381d1323419a8f03 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 6 Oct 2006 20:11:25 +0100 Subject: [PATCH] changes from samual to make it all work --- debian/rules | 13 ++--- settings.make | 2 + xen/Makefile | 6 +-- xen/README | 82 +++++++++++++++++++++++++++- xen/cleanup | 13 +++-- xen/example-config | 8 ++- xen/fixups | 6 ++- xen/fixups-inside | 10 +--- xen/initscript | 57 ++++++++++++++++---- xen/on-testbed | 7 ++- xen/pbuilderrc | 65 ----------------------- xen/readconfig.in | 129 ++++++++++++++++++++++++++++++++++----------- xen/setup | 59 +++++++++++++-------- xen/with-testbed | 16 ++++-- 14 files changed, 316 insertions(+), 157 deletions(-) delete mode 100644 xen/pbuilderrc diff --git a/debian/rules b/debian/rules index edb8998..5c96b5a 100755 --- a/debian/rules +++ b/debian/rules @@ -25,7 +25,7 @@ SHELL=/bin/bash p=autopkgtest -px=autopkgtest-xenlvm +x=xenlvm topdir=`pwd` build build-indep: @@ -41,14 +41,15 @@ binary binary-indep: checkdir $(MAKE) install-here prefix=debian/$p/usr $(MAKE) -C xen install \ - pkgname=autopkgtest-xenlvm \ - prefix=$(topdir)/debian/$(px)/usr \ - sharedir=$(topdir)/debian/$(px)/usr/share/autopkgtest/xenlvm \ - etcdir=$(topdir)/debian/$(px)/etc cfg_suffix='' + pkgname=$p-$x \ + prefix=$(topdir)/debian/$p-$x/usr \ + sharedir_lnfrom=/usr/share/$p/$x \ + sharedir=$(topdir)/debian/$p-$x/usr/share/$p/$x \ + etcdir=$(topdir)/debian/$p-$x/etc cfg_suffix='' cat CREDITS debian/copyright.suffix \ >debian/$p/usr/share/doc/$p/copyright - dh_installinit -p $(px) --onlyscripts --name=adtxenlvm -- defaults 19 + dh_installinit -p $p-$x --onlyscripts --name=adt$x -- defaults 19 dh_compress dh_link dh_md5sums diff --git a/settings.make b/settings.make index 279482a..a8d78d7 100644 --- a/settings.make +++ b/settings.make @@ -6,7 +6,9 @@ man1dir = $(mandir)/man1 pkgname = autopkgtest docdir = $(share)/doc/$(pkgname) sharedir = $(share)/$(pkgname) +sharedir_lnfrom = $(share)/$(pkgname) etcdir = /etc +etcconfdir = $(etcdir)/autopkgtest etcinitddir = $(etcdir)/init.d xenscripts = $(etcdir)/xen/scripts cfg_suffix = .dist diff --git a/xen/Makefile b/xen/Makefile index 38f6dab..0a192ac 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -31,13 +31,13 @@ exec_prefix = adt-xenlvm- all: readconfig install: all - $(INSTALL_DIRS) $(bindir) $(docdir) $(man1dir) \ + $(INSTALL_DIRS) $(bindir) $(docdir) $(man1dir) $(etcconfdir) \ $(sharedir) $(etcinitddir) $(xenscripts) set -e; for f in $(programs) $(shareprograms); do \ $(INSTALL_PROGRAM) $$f $(sharedir); \ done set -e; for f in $(programs); do \ - ln -sf $(sharedir)/$$f $(bindir)/$(exec_prefix)$$f; \ + ln -sf $(sharedir_lnfrom)/$$f $(bindir)/$(exec_prefix)$$f; \ test ! -f $$f.1 || $(INSTALL_DOC) $$f.1 \ $(man1dir)/$(exec_prefix)$$f; \ done @@ -46,7 +46,7 @@ install: all done $(INSTALL_DATA) initscript $(etcinitddir)/adtxenlvm$(cfg_suffix) $(INSTALL_DATA) vif-route-adt $(xenscripts)/vif-route-adt$(cfg_suffix) - $(INSTALL_DOC) README $(docdir) + $(INSTALL_DOC) README example-config $(docdir) readconfig: sed-readconfig readconfig.in sed -f $^ >$@.new && mv -f $@.new $@ diff --git a/xen/README b/xen/README index e85c023..edba52d 100644 --- a/xen/README +++ b/xen/README @@ -1,10 +1,68 @@ ----------- Introduction ---------- +========== Introduction ========== + +Basic approach: + 1. Get yourself a working Xen dom0 setup, eg according to + https://wiki.ubuntu.com/XenOnEdgy + 2. Configure adtxenlvm: + - assign a fixed IP address for the host and the testbed + - create DNS entries (forward and reverse) + for the testbed hostname edgy.adt. + - read below about settings you might want to set + creating /etc/autopkgtest/xenlvm_adt_config if needed + 3. adt-xenlvm-setup + 4. adt-xenlvm-with-testbed + 5. adt-xenlvm-on-testbed + +In some more detail, there are four main programs provided: + + adt-xenlvm-setup [] + Creates the snapshot. Broadly speaking, does the following: + - deletes any existing snapshot, virtual machine, etc. + - creates a new lvm volume and filesystem for the snapshot base + - runs debootstrap to install a system into the new filesystem + - makes necessary config changes to the testbed and the host + - boots the testbed and waits for it to start + - freezes the testbed into a snapshot file + After this, you can run with-testbed. + + adt-xenlvm-with-testbed [] [ []] + Starts the testbed and runs _on the HOST_. When + finishes, the testbed state will be discarded. While + is running, you can interact with the testbed. If + is not specified, you get an interactive shell. + + adt-xenlvm-on-testbed [] [] + Runs on the running testbed. A + child of adt-xenlvm-with-testbed must be running, or the + behaviour is not defined. However, adt-xenlvm-on-testbed does + not need to be a descendent of adt-xenlvm-with-testbed. + The arguments are passed to ssh verbatim + and are therefore subject to ssh's unpleasant mangling. + + adt-xenlvm-cleanup [] + Cleans up any running testbed state. This is not normally + needed, as adt-xenlvm-with-testbed and adt-xenlvm-setup run it + at appropriate moments. However, if one of these should fail + and it is desirable to reclaim any resources used by the + testbed, cleanup will do this job. + +Note that there is NO LOCKING. If you run more than one of either +adt-xenlvm-with-testbed or adt-xenlvm-setup (or one of each) +simultaneously, the behaviour is not defined, except that the host +will definitely not be trashed, and just two or more copies of +adt-xenlvm-with-testbed at once has no bad effects that +adt-xenlvm-cleanup won't fix. + + +========== Configuration ========== The configuration is read as follows: 1. set all variables whose defaults are fixed strings to those built-in default values 2. process the command line arguments 3. read the user configuration file (sourced by bash) + this file must not use fds 10 onwards, which may have been used + for other purposes by other adtxenlvm machinery 4. process the command line arguments again, so they can easily be made to override the user configuration file 5. calculate the values for variables which haven't been set @@ -46,6 +104,10 @@ adt_fw_allowglobalports 80 List of ports to which the testbed will be allowed to make outgoing connections. +adt_fw_hook with _config replaced with _fwhook + or none of doesn't end in _config + bash fragment to source during firewall setup + ---------- Items that are likely to need attention ---------- adt_kernel the booted kernel file /boot/xen*`uname -r` @@ -64,6 +126,24 @@ adt_lvm_vg the system's LVM volume group if there is only one adt_pbuilder_args Extra arguments to pass to pbuilder. +adt_lvm_erasebase yes + Whether the base filesystem image needs to be filled with + zeroes. If you are going to be using the image only locally + and so don't care whether the base image contains bits of + previous data from the disk, you may set this to `no'. + +adt_debootstrap_includemore +adt_debootstrap_include libc6-xen,openssh-server,ed + Comma-separated lists of packages for --include option to + debootstrap. It is best to set includemore. + +adt_debootstrap_components * + Components of the distribution to consider. (Eg, `main'.) + +adt_debootstrap_mirrors +adt_debootstrap_script + Third and fourth arguments to debootstrap. + ---------- Tuning parameters ---------- adt_fs_type ext3 diff --git a/xen/cleanup b/xen/cleanup index 145df5e..8ce6325 100755 --- a/xen/cleanup +++ b/xen/cleanup @@ -1,12 +1,17 @@ #!/bin/bash set -e . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig +test $nonoptargs = 0 || fail "non-option arguments not allowed" mkdir -p $adt_play $snap -try () { "$@" >/dev/null 2>&1 ||:; } +try () { printf "%s\n" "- $*"; "$@" >/dev/null 2>&1 ||:; } -try xm destroy $adt_xmname -try umount $adt_lvm_baselv +n=0 +while x xm destroy $adt_xmname 2>/dev/null; do + sleep $n + n=$(( $n+1 )) +done +try umount $lvm_baselv_namepath try dmsetup remove $adt_devmapper_cowdev -rm -f $lvfsptr +rm -f $lvm_fslink_ptr diff --git a/xen/example-config b/xen/example-config index 237dbbb..fa1696d 100644 --- a/xen/example-config +++ b/xen/example-config @@ -1,6 +1,12 @@ -adt_pbuilder_args='--mirror http://mirror.relativity.greenend.org.uk/mirror/ubuntu.early' +adt_debootstrap_mirrors=http://mirror.relativity.greenend.org.uk/mirror/ubuntu adt_guests_domain=.relativity.greenend.org.uk adt_host_hostname=samual.relativity.greenend.org.uk adt_fw_localmirrors=172.18.45.6 adt_fw_testbedclients='172.18.45.97 172.18.45.6' + +adt_lvm_erasebase=n + +#export http_proxy=http://www-cache.relativity.greenend.org.uk:3128/ + + diff --git a/xen/fixups b/xen/fixups index 3ab114c..b7d725b 100755 --- a/xen/fixups +++ b/xen/fixups @@ -1,5 +1,5 @@ -#!/bin/sh -set -ex +#!/bin/bash +set -e . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig dest=$adt_play/base @@ -11,6 +11,8 @@ cp ${ADT_XENLVM_SHARE}/fixups-inside $dest/root/ mkdir -p $dest/lib/modules cp -a "${adt_modules}" $dest/lib/modules/. +echo xennet >>$dest/etc/modules + if ! test -f "${adt_ssh_pubkey}"; then if [ "x${adt_ssh_pubkey}" != "x${adt_ssh_privkey}.priv" ]; then fail "cannot generate keypair automatically because adt_ssh_privkey \`$adt_ssh_privkey' and adt_ssh_pubkey \`$adt_ssh_pubkey' do not match up in the way required by ssh-keygen ( must be .pub>" diff --git a/xen/fixups-inside b/xen/fixups-inside index 67fea31..2a38051 100755 --- a/xen/fixups-inside +++ b/xen/fixups-inside @@ -1,5 +1,5 @@ -#!/bin/sh -set -ex +#!/bin/bash +set -e${ADT_SHELLX} adt_host_hostname=$1 adt_guest_hostname=$2 @@ -19,9 +19,6 @@ if test -f /etc/lsb-release; then fi fi -apt-get update -apt-get -y --force-yes install libc6-xen - ldconfig cat >/etc/fstab </etc/hostname -apt-get -y --force-yes install \ - openssh-server ed build-essential - perl -i~ -wne ' BEGIN { $pep= PermitEmptyPasswords; diff --git a/xen/initscript b/xen/initscript index 578b1db..7b37270 100755 --- a/xen/initscript +++ b/xen/initscript @@ -1,12 +1,16 @@ -#!/bin/sh +#!/bin/bash set -e -. ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -default=/etc/default/adt-xen -if test -f $default; then - . $default +lsbif=/lib/lsb/init-functions +if test -e $lsbif; then + . $lsbif +else + log_daemon_msg () { printf "%s: " "$1"; } + log_progress_msg () { printf "%s " "$1"; } + log_end_msg () { echo "done."; } fi +. /etc/default/rcS chains='AdtXenIn AdtXenFwd AdtXenIcmp' @@ -15,6 +19,7 @@ if ! type iptables >/dev/null 2>&1 || ! type xm >/dev/null 2>&1; then fi safety () { + log_progress_msg block iptables -I INPUT -j DROP iptables -I FORWARD -j DROP trap ' @@ -25,6 +30,7 @@ safety () { } unsafety () { + log_progress_msg unblock iptables -D INPUT -j DROP iptables -D FORWARD -j DROP trap '' 0 @@ -32,14 +38,18 @@ unsafety () { case "$1" in stop) + log_daemon_msg "adtxenlvm: removing firewall rules" safety + log_progress_msg clear for chain in $chains; do - if iptables -L $chain >/dev/null 2>&1; then + if iptables -L -n $chain >/dev/null 2>&1; then + log_progress_msg $chain iptables -F $chain iptables -X $chain fi done unsafety + log_end_msg 0 exit 0 ;; start|restart|force-reload) @@ -54,13 +64,32 @@ start|restart|force-reload) ;; esac +set -- + +exec 10>&1 +case "$VERBOSE" in +no) exec >/dev/null ;; +esac + +printf "adtxenlvm: reading configuration for firewall setup:\n" +. ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig + +exec >&10 10>&- + +log_daemon_msg "adtxenlvm: installing firewall rules" + safety + +log_progress_msg create for chain in $chains; do + log_progress_msg $chain iptables -N $chain >/dev/null 2>&1 || iptables -F $chain iptables -I $chain -j DROP done unsafety +log_progress_msg rules + iptables -A AdtXenIcmp -j ACCEPT -p icmp --icmp-type echo-request # per RFC1122, allow ICMP echo exchanges with anyone we can talk to at all @@ -105,17 +134,27 @@ for port in $adt_fw_allowglobalports; do iptables -A $main -p tcp --dport $port -j ACCEPT done -if test -f $default-rules; then - . $default-rules +if [ "x$adt_fw_hook" != x ]; then + log_progress_msg hook + . $adt_fw_hook fi +log_progress_msg confirm + iptables -A $main -j REJECT --reject-with icmp-admin-prohibited -iptables -A $main -j ACCEPT iptables -D $main -j DROP +log_progress_msg engage + iptables -A AdtXenIn -j ACCEPT -p icmp --icmp-type echo-request iptables -A AdtXenIn -j ACCEPT -m conntrack --ctstate ESTABLISHED iptables -A AdtXenIn -j AdtXenFwd iptables -D AdtXenIn -j DROP +iptables -D AdtXenIcmp -j DROP + +log_progress_msg proxyarp + echo 1 >/proc/sys/net/ipv4/conf/eth0/proxy_arp + +log_end_msg 0 diff --git a/xen/on-testbed b/xen/on-testbed index 96a4b7b..0fb2459 100755 --- a/xen/on-testbed +++ b/xen/on-testbed @@ -1,4 +1,9 @@ -#!/bin/sh +#!/bin/bash set -e +exec 10>&1 >/dev/null . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig +exec >&10 +exec 10>&- +while test $# -gt $nonoptargs; do shift; done + ssh $adt_ssh_keyident_args $adt_guest_ipaddr "$@" diff --git a/xen/pbuilderrc b/xen/pbuilderrc deleted file mode 100644 index 671a35e..0000000 --- a/xen/pbuilderrc +++ /dev/null @@ -1,65 +0,0 @@ -# this is your configuration file for pbuilder. -# the file in /usr/share/pbuilder/pbuilderrc is the default template. -# /etc/pbuilderrc is the one meant for editing. -# -# read pbuilderrc.5 document for notes on specific options. - -BASETGZ=/var/cache/pbuilder/base.tgz -#EXTRAPACKAGES=gcc3.0-athlon-builder -#export DEBIAN_BUILDARCH=athlon -BUILDPLACE=/var/cache/pbuilder/build/ -MIRRORSITE=http://ftp.jp.debian.org/debian -#NONUSMIRRORSITE="http://ftp.jp.debian.org/debian-non-US" -#OTHERMIRROR="deb http://www.home.com/updates/ ./" -#export http_proxy=http://your-proxy:8080/ -USEPROC=yes -USEDEVPTS=yes -USEDEVFS=no -BUILDRESULT=/var/cache/pbuilder/result/ - -# specifying the distribution forces the distribution on "pbuilder update" -#DISTRIBUTION=sarge -#specify the cache for APT -APTCACHE="/var/cache/pbuilder/aptcache/" -APTCACHEHARDLINK="no" -REMOVEPACKAGES="lilo" -#HOOKDIR="/usr/lib/pbuilder/hooks" -HOOKDIR="" - -# make debconf not interact with user -export DEBIAN_FRONTEND="noninteractive" - -DEBEMAIL="" - -#for pbuilder debuild -BUILDSOURCEROOTCMD="fakeroot" -PBUILDERROOTCMD="sudo" - -#default is to build everything. Passed on to dpkg-buildpackage -#DEBBUILDOPTS="-b" -DEBBUILDOPTS="" - -#APT configuration files directory -APTCONFDIR="" - -# the username and ID used by pbuilder, inside chroot. Needs fakeroot, really -BUILDUSERID=1234 -BUILDUSERNAME=pbuilder - -# BINDMOUNTS is a space separated list of things to mount -# inside the chroot. -BINDMOUNTS="" - -# Set the debootstrap variant to 'buildd' type. -# DEBOOTSTRAPOPTS[0]='--variant=buildd' -# or work around bug in debootstrap 3.0.0 (314858) -unset DEBOOTSTRAPOPTS - -# Set the PATH I am going to use inside pbuilder: default is "/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" -export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" - -# SHELL variable is used inside pbuilder by commands like 'su'; and they need sane values -export SHELL=/bin/bash - -# The name of debootstrap command. -DEBOOTSTRAP="debootstrap" diff --git a/xen/readconfig.in b/xen/readconfig.in index 19598d3..c63748c 100644 --- a/xen/readconfig.in +++ b/xen/readconfig.in @@ -1,6 +1,8 @@ # This bash script is sourced by the various tools to set the # adt_... variables and some other useful ones. +set -e${ADT_SHELLX} + #---------- useful general functions ---------- fail () { @@ -8,6 +10,13 @@ fail () { exit 16 } +x () { echo "x $*"; "$@"; } + +case "$BASH_VERSION" in +'') fail 'scripts using adtxenlvm readconfig must be bash scripts' ;; +*) ;; +esac + #---------- default values for simple settings ---------- adt_nominum=adt @@ -22,6 +31,12 @@ adt_fs_mkfs_args='' adt_vm_reduce_retries=10 adt_ssh_keytype=dsa +adt_debootstrap_components='*' +adt_debootstrap_include=libc6-xen,openssh-server,ed +adt_debootstrap_includemore= +adt_debootstrap_mirrors='' +adt_debootstrap_script='' + adt_fw_localmirrors='' adt_fw_prohibnets='192.168.0.0/24 172.16.0.0/12 10.0.0.0/8' adt_fw_allowglobalports='80' @@ -53,44 +68,49 @@ cmdline_args () { eval "$var=\"\$value\"" shift ;; - --) break ;; + --) shift; break ;; -*) fail "unknown option \`$arg'" ;; - *) shift; break ;; + *) break ;; esac done - test $# = 0 || fail "non-option arguments not allowed" + nonoptargs=$# } -cmdline_args -. ${adt_config} -cmdline_args +cmdline_args "$@" +: "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}" +test ! -e "${adt_config}" || . "${adt_config}" +cmdline_args "$@" #---------- calculated defaults for complex settings ---------- case "$adt_lvm_vg" in '') - echo "searching for default volume group ..." - vgdisplay_out=`vgdisplay -c` + printf "searching for default volume group ... " + vgdisplay_out=`vgdisplay -c 10>&-` case "$vgdisplay_out" in "") fail 'no volume groups found';; *" "*) fail 'several volume groups, config must specify which';; esac - $adt_lvm_vg=${vgdisplay_out%%:*} - echo "system has one volume group, $adt_vg, using that." + adt_lvm_vg=${vgdisplay_out%%:*} + case "$adt_lvm_vg" in + *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";; + esac + adt_lvm_vg=${adt_lvm_vg##* } + echo "using system's only volume group: $adt_lvm_vg" ;; esac case "$adt_kernel" in '') - echo "searching for kernel ..." + printf "searching for kernel ... " for f in /boot/xen*"`uname -r`"; do - test -f "$f" || continue + test -e "$f" || continue test "x$adt_kernel" = x || \ fail 'several kernels, config must specify which' adt_kernel="$f" done - echo "... using currently booted kernel $adt_kernel" + echo "using currently booted kernel: $adt_kernel" ;; esac @@ -98,22 +118,23 @@ case "$adt_ramdisk" in none) echo "ramdisk \`none' specified, using static kernel" adt_ramdisk='' ;; '') adt_ramdisk="$adt_kernel.initrd.img" - echo "using default ramdisk .initrd.img, $adt_ramdisk" ;; + echo "using default ramdisk .initrd.img: $adt_ramdisk" ;; *) ;; esac case "$adt_modules" in -'') /lib/modules/`uname -r` ;; +'') adt_modules="/lib/modules/`uname -r`" ;; *) ;; esac case "$adt_distro" in '') - echo "considering which distro to use ..." - test -f /etc/lsb-release || \ + printf "considering which distro to use ... " + test -e /etc/lsb-release || \ fail 'no /etc/lsb-version, config must specify adt_distro' . /etc/lsb-release - $adt_distro=$DISTRIB_CODENAME + adt_distro=$DISTRIB_CODENAME + echo "using same distro as host: $adt_distro" ;; esac @@ -121,8 +142,9 @@ hostname_from_ipaddr () { eval ' if [ x"$adt_'$1'_hostname" = x ] && \ [ x"$adt_'$1'_ipaddr" != x ]; then - echo "finding '$1' hostname from IP address $adt_'$1'_ipaddr" + printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: " adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr` + printf "%s\n" "${adt_'$1'_hostname}" fi ' } @@ -131,27 +153,30 @@ hostname_from_ipaddr guest hostname_from_ipaddr host if [ x"$adt_host_hostname" = x ]; then - echo "finding host hostname, supposely our own FQDN ..." + printf "finding host hostname, supposely our own FQDN: " adt_host_hostname=`hostname -f` + printf "%s\n" "$adt_host_hostname" fi if [ x"$adt_guest_hostname" = x ]; then case "$adt_guests_domain" in - '') echo "guessing guest hostname from host hostname ..." + '') printf "guessing guest hostname from host hostname: " adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;; - .*) echo "setting guest hostname using distro and nominum ..." + .*) printf "setting guest hostname using distro and nominum: " adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;; - *) echo "setting guest hostname using distro and domain ..." + *) printf "setting guest hostname using distro and domain: " adt_guest_hostname=$adt_distro.$adt_guests_domain ;; esac + printf "%s\n" "$adt_guest_hostname" fi ipaddr_from_hostname () { eval ' if [ x"$adt_'$1'_ipaddr" = x ] && \ [ x"$adt_'$1'_hostname" != x ]; then - echo "finding '$1' IP address from hostname $adt_'$1'_hostname" - adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc -i - "$adt_'$1'_hostname"` + printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: " + adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"` + echo "${adt_'$1'_ipaddr}" fi ' } @@ -159,7 +184,45 @@ ipaddr_from_hostname () { ipaddr_from_hostname guest ipaddr_from_hostname host -: ${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config} +printf "looking for firewall hook ... " +case "$adt_fw_hook" in +'') + case "$adt_config" in + *_config) + adt_fw_hook=${adt_config%_config}_fwhook + if test -e "$adt_fw_hook"; then + echo "default exists: $adt_fw_hook" + else + echo "default $adt_fw_hook is not a file, so: none" + adt_fw_hook='' + fi + ;; + *) + echo "not specified, not computable from config, so: none" + adt_fw_hook='' + ;; + esac + ;; +*) + if test -e "$adt_fw_hook"; then + echo "exists: $adt_fw_hook" + else + echo "specified as $adt_fw_hook, but not a file, so: none" + adt_fw_hook='' + fi + ;; +esac + +boolean_config () { + eval ' + case "${adt_'$1'}" in + y*|Y*|1*|t*) adt_'$1'=true ;; + n*|N*|0*|f*) adt_'$1'=false ;; + "") adt_'$1'=$2 ;; + *) fail "unknown boolean value \`$1'\'' for adt_'$1'" ;; + esac + ' +} # SSH : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}} @@ -173,8 +236,10 @@ ipaddr_from_hostname host # In-host-file-system playground : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}} : ${adt_xmconfig:=${adt_play}/xmconfig} +: ${adt_lock:=${adt_play}/lock} # LVM +boolean_config lvm_erasebase true : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base} : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata} : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap} @@ -185,14 +250,16 @@ ipaddr_from_hostname host # Firewall : ${adt_fw_testbedclients:=${adt_host_ipaddr}} -lvm_baselv_namerhs=${adt_vg}/${adt_lvm_baselv} -lvm_baselv_namepath=/dev/${adt_lvbaserhs} +lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv} +lvm_baselv_namepath=/dev/${lvm_baselv_namerhs} -lvm_cowdata_namerhs:=${adt_vg}/${adt_lvm_cowdatalv} -lvm_cowdata_namepath:=/dev/${lvm_cowdata_namerhs} +lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv} +lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs} lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev} lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name} lvm_fslink_dirpath=/dev/${adt_fslink_dir} -lvm_fslink_ptr=/dev/${lvm_fslink_dir}/${adt_fslink_name} +lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name} + +echo "adtxenlvm: configuration for read for nominum=${adt_nominum}" diff --git a/xen/setup b/xen/setup index f1d5253..b33048d 100755 --- a/xen/setup +++ b/xen/setup @@ -1,23 +1,37 @@ #!/bin/bash set -e . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig +test $nonoptargs = 0 || fail "non-option arguments not allowed" $ADT_XENLVM_SHARE/cleanup -lvchange -a n $lvm_cowdata_namepath ||: -lvremove $lvm_baselv_namepath ||: -lvremove $lvm_cowdata_namepath ||: +x lvchange -a n $lvm_baselv_namepath ||: +x lvchange -a n $lvm_cowdata_namepath ||: +x lvremove $lvm_baselv_namepath ||: +x lvremove $lvm_cowdata_namepath ||: -lvcreate -L $adt_fs_size -n $adt_lvm_baselv $adt_lvm_vg -lvcreate -L $adt_fs_snapsize -n $adt_lvm_cowdatalv $adt_lvm_vg -dd if=/dev/zero of=$lvm_baselv_namepath -mkfs -t $adt_fs_type $adt_mkfs_args $lvm_baselv_namepath +x lvcreate -L $adt_fs_size -n $adt_lvm_baselv $adt_lvm_vg +x lvcreate -L $adt_fs_snapsize -n $adt_lvm_cowdatalv $adt_lvm_vg + +if $adt_lvm_erasebase; then + x dd if=/dev/zero of=$lvm_baselv_namepath +fi +x mkfs -t $adt_fs_type $adt_mkfs_args $lvm_baselv_namepath mkdir -p $adt_play/base -mount $adt_lvm_baselv $adt_play/base +x mount $lvm_baselv_namepath $adt_play/base + +x debootstrap \ + --components="${adt_debootstrap_components}" \ + --include=${adt_debootstrap_include},${adt_debootstrap_includemore} \ + $adt_debootstrap_opts \ + "$adt_distro" "$adt_play/base" \ + "$adt_debootstrap_mirrors" "$adt_debootstrap_script" -pbuilder create --configfile /dev/null --distribution $distro \ - --no-targz --buildplace $adt_play/base \ - $adt_pbuilder_args --debootstrapopts --variant='' +#x pbuilder create \ +# --configfile /usr/share/autopkgtest/xenlvm/pbuilderrc \ +# --distribution "$adt_distro" \ +# --no-targz --buildplace $adt_play/base \ +# $adt_pbuilder_args --debootstrapopts --variant='' $ADT_XENLVM_SHARE/fixups "$@" @@ -26,7 +40,7 @@ echo " " cat <$adt_xmconfig -kernel = "$kernel" +kernel = "$adt_kernel" memory = $adt_testbed_ram root = "/dev/hda1" extra = "ro console=tty0" @@ -37,37 +51,38 @@ on_reboot = "preserve" on_shutdown = "preserve" END -if [ "x$ramdisk" != x ]; then +if [ "x$adt_ramdisk" != x ]; then cat <>$adt_xmconfig -ramdisk = "$ramdisk" +ramdisk = "$adt_ramdisk" END fi -umount $adt_lvm_baselv +x umount $lvm_baselv_namepath -mkdir -p /dev/${lvm_fslink_dirpath} +mkdir -p ${lvm_fslink_dirpath} ln -sf ../$lvm_baselv_namerhs ${lvm_fslink_ptr} -xm create $adt_xmconfig name=$adt_xmname +x xm create $adt_xmconfig name=$adt_xmname retries=10 while true; do - if ping -c 1 $adt_guest_ipaddr && ./on-testbed id; then break; fi + if ping -c 1 $adt_guest_ipaddr && \ + /usr/share/autopkgtest/xenlvm/on-testbed id; then break; fi if [ $retries -le 0 ]; then echo >&2 'no response from guest' - xm console $adt_xmname + x xm console $adt_xmname exit 1 fi retries=$(($retries-1)) sleep 2 done -xm mem-set $adt_xmname $adt_freeze_ram +x xm mem-set $adt_xmname $adt_freeze_ram retries=$adt_vm_reduce_retries while sleep 1; do - if xm mem-max $adt_xmname $adt_freeze_ram; then break; fi + if x xm mem-max $adt_xmname $adt_freeze_ram; then break; fi if [ $retries -le 0 ]; then echo >&2 'cannot reduce memory'; exit 1; fi retries=$(($retries-1)) done -xm save $adt_xmname $adt_play/xen-save +x xm save $adt_xmname $adt_play/xen-save rm ${lvm_fslink_ptr} diff --git a/xen/with-testbed b/xen/with-testbed index 209183b..89515d9 100755 --- a/xen/with-testbed +++ b/xen/with-testbed @@ -3,14 +3,19 @@ set -e trap 'exit 127' 0 +exec 10>&1 >/dev/null . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig -${ADT_XENLVM_SHARE}/cleanup +exec >&10 10>&- + +while test $# -gt $nonoptargs; do shift; done + +${ADT_XENLVM_SHARE}/cleanup >/dev/null modprobe dm-snapshot ||: -bdsize=$(blockdev --getsize $adt_lvm_baselv) +bdsize=$(blockdev --getsize $lvm_baselv_namepath) dmsetup create $adt_devmapper_cowdev <