From: Ian Jackson Date: Thu, 28 Sep 2006 18:24:19 +0000 (+0100) Subject: wip productisation X-Git-Tag: converted-from-bzr~64^2~10 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=2e45130595169e0e8decbc8bf076f2daa041b92d;p=autopkgtest.git wip productisation --- diff --git a/debian/control b/debian/control index 211ab21..a98d844 100644 --- a/debian/control +++ b/debian/control @@ -21,4 +21,4 @@ Description: automatic as-installed testing for Debian packages Package: autopkgtest-xen Architecture: all -Depends: pbuilder, libadns1-bin, chiark-utils-bin +Depends: pbuilder, libadns1-bin, chiark-utils-bin, iproute diff --git a/xen/README b/xen/README new file mode 100644 index 0000000..2a80a26 --- /dev/null +++ b/xen/README @@ -0,0 +1,155 @@ +---------- Introduction ---------- + +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) + 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 + and whose default values depend on circumstances (including + on other variables) + +---------- Items which definitely need attention ---------- + +adt_guests_domain . +adt_guest_hostname .[.] +adt_guest_ipaddr from looking hostname up in the DNS + Hostname and IP address for the testbed. + If the configuration specifies one of the address and hostname + but not the other, the missing information will be found with + a DNS lookup. If neither is specified, adt_guests_domain is + used; if it starts with `.' then . is + prepended; otherwise just . is prepended. NOTE: some + effort by the local network administrator to allocate an IP + address (and ideally create DNS entries) is essential. It is + not possible to use DHCP for IP address allocation for the + testbed. + +---------- Items that are likely to need attention ---------- + +adt_kernel the booted kernel file /boot/xen*`uname -r` + Kernel to boot in the testbed image + +adt_ramdisk .initrd.img + Initial ramdisk to provide to the testbid image. + "none" means do not provide an initial ramdisk. + +adt_modules /lib/modules/`uname -r` + Directory with modules to be copied into the testbed. + +adt_lvm_vg the system's LVM volume group if there is only one + LVM volume group to create base filesystem image in. + +adt_fs_type ext3 +adt_fs_mkfs_args + Filesystem type and any additional arguments to mkfs. If + _args contains whitespace, it results in multiple arguments; + it is not possible to pass whitespace-containing arguments to + mkfs. + +adt_pbuilder_args + Extra arguments to pass to pbuilder. + +---------- Tuning parameters ---------- + +adt_testbed_ram 256 [Mby] + Physical RAM allocated for each testbed instance while + creating and running. + +adt_freeze_ram 32 [Mby] + Physical RAM size for frozen image; we reduce the testbed + to this before freezing it and grow it again when we resume + it. + +adt_fs_size 1G + Size of base filesystem image. Should be big enough to + contain all of the software under test and all of its working + space, as no running testbed can ever use more than this + (despite copy-on-write). + +adt_fs_snapsize 500M + Space to allocate for copy-on-write snapshot data. This is + the maximum amount of data that a running testbed can use. + This value should be less than the adt_fs_size. + +adt_fs_cowchunk 8 [Mby] + Copy-on-write chunk size. + +adt_vm_reduce_retries 10 [seconds] + Time to wait for VM to reduce its memory following + xm mem-set. + +---------- Configuration for advanced uses ---------- + +adt_config /etc/autopkgtest/xenlvm__conf + +adt_ssh_keytype dsa +adt_ssh_privkey /root/.ssh/id__ +adt_ssh_pubkey .pub +adt_ssh_keyident_args -i +adt_ssh_keygen_args -t + SSH keypair to use for authentication to the testbed. + If the pubkey file and privkey file do not exist and + correspond to each other, a new key will be generated. + The best combinations of these variables to set are: + keytype [& keygen_args] - just change the key type + privkey [& keygen_args] - generate/use a different keypair + pubkey, keyident_args - use an existing key via agent etc., + privkey is ignored if pubkey and keyident_args + are set and pubkey file exists + +adt_nominum adt + Namespace prefix for Xen domains, LVM volumes, devmapper + devices, entries in /dev, files in /var, and so on. You may + run several instances of the adt virtualisation system with + different nominums and they won't interact. It is best for + this to be a legal DNS label (using alphanumerics and hyphens + only); normally it when it is used to construct an identifier + it will be separated by other parts by underscores `_', so + they should be avoided. + + +---------- Items which should not usually need to be changed ---------- + +adt_host_hostname `hostname -f` +adt_host_ipaddr from looking hostname up in the DNS + Hostname and IP address for the host, ie the Xen dom0 system. + If the configuration specifies one of the address and hostname + but not the other, the missing information will be found with + a DNS lookup. Note that if the host system uses a dynamically + allocated DHCP address, things will go wrong when the address + changes. + +adt_playbase /var/lib/autopkgtest/xenlvm + Base of filesystem playground areas. + +adt_play /_ + Playground area for this particular testbed construction and + data. + +adt_xmconfig /xmconfig + Xen virtual machine creation configuration for xm create. + This file will be (over)written during testbed setup. + +adt_lvm_baselv __base +adt_lvm_cowdatalv __cowdata + LVM volume for base filesystem image, and copy-on-write + buffer. Will be created during testbed setup, destroying any + previous volume if necessary. This is the logical volume name + not including /dev/. + +adt_devmapper_cowdev __snap + devmapper device for copy-on-write image used by testbed when + running. This is the device name in the devmapper namespace, + ie not including /dev/mapper. + +adt_fslink_dir adt-xenlvm +adt_fslink_name __fs + Directory in /dev, and filename in that directory, where the + scripts put the symlink used to trick Xen into using a + different block device on resume than was used for creation. + +adt_xmname _ + Xen virtual machine name, as passed to xm create. diff --git a/xen/README.config-processing b/xen/README.config-processing deleted file mode 100644 index bf524e8..0000000 --- a/xen/README.config-processing +++ /dev/null @@ -1,5 +0,0 @@ -1. read config-defaults -2. process command line args -3. read user config -4. process command line args again -5. process tail-config diff --git a/xen/cleanup b/xen/cleanup index 1b87b3a..e822dd7 100755 --- a/xen/cleanup +++ b/xen/cleanup @@ -2,11 +2,11 @@ set -e . ./config -mkdir -p $play $snap +mkdir -p $adt_play $snap try () { "$@" >/dev/null 2>&1 ||:; } -try xm destroy $xmname -try umount $lvbase -try dmsetup remove $nsnap +try xm destroy $adt_xmname +try umount $adt_lvm_baselv +try dmsetup remove $adt_devmapper_cowdev rm -f $lvfsptr diff --git a/xen/config-vars b/xen/config-vars index 63aee6e..e69de29 100644 --- a/xen/config-vars +++ b/xen/config-vars @@ -1,39 +0,0 @@ -adt_testbed_ram 256 [Mby] - Physical RAM allocated for each testbed instance while - creating and running. - -adt_freeze_ram 32 [Mby] - Physical RAM size for frozen image; we reduce the testbed - to this before freezing it and grow it again when we resume - it. - -adt_filesys_size 1G - Size of base filesystem image. Should be big enough to - contain all of the software under test and all of its working - space, as no running testbed can ever use more than this - (despite copy-on-write). - -adt_filesys_snapsize 500M - Space to allocate for copy-on-write snapshot data. This is - the maximum amount of data that a running testbed can use. - This value should be less than the adt_filesys_size. - -adt_filesys_cowchunk 8 [Mby] - Copy-on-write chunk size. - -adt_nominum adt - Namespace prefix for Xen domains, LVM volumes, devmapper - devices, entries in /dev, files in /var, and so on. You may - run several instances of the adt virtualisation system with - different nominums and they won't interact. - -adt_lvm_vg the system's LVM volume group if there is only one - LVM volume group to create base filesystem image in. - -adt_kernel the booted kernel file /boot/xen*`uname -r` - Kernel to boot in the testbed image - -adt_ramdisk .initrd.img - Initial ramdisk to provide to the testbid image. - "none" means do not provide an initial ramdisk. - diff --git a/xen/default-config b/xen/default-config index bb414a5..c862257 100644 --- a/xen/default-config +++ b/xen/default-config @@ -1,7 +1,11 @@ +adt_nominum=${adt_nominum} adt_testbed_ram=256 adt_freeze_ram=32 -adt_filesys_size=1G -adt_filesys_snapsize=100M -adt_filesys_cowchunk=8 - -adt_nominum=${adt_nominum} +adt_fs_size=1G +adt_fs_snapsize=100M +adt_fs_cowchunk=8 +adt_playbase=/var/lib/autopkgtest/xenlvm +adt_fs_type=ext3 +adt_fs_mkfs_args='' +adt_vm_reduce_retries=10 +adt_ssh_keytype=dsa diff --git a/xen/example-config b/xen/example-config index b95bed0..d14fa57 100644 --- a/xen/example-config +++ b/xen/example-config @@ -1,3 +1,3 @@ -adt_pbuilderopts='--mirror http://mirror.relativity.greenend.org.uk/mirror/ubuntu.early' +adt_pbuilder_args='--mirror http://mirror.relativity.greenend.org.uk/mirror/ubuntu.early' adt_guests_domain=.relativity.greenend.org.uk adt_host_hostname=samual.relativity.greenend.org.uk diff --git a/xen/fixups b/xen/fixups index 9c9c83d..3ab114c 100755 --- a/xen/fixups +++ b/xen/fixups @@ -1,27 +1,34 @@ #!/bin/sh set -ex +. ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig -dest=$1 -adt_host_hostname=$2 -adt_guest_hostname=$3; shift +dest=$adt_play/base echo '---fixups:' -cp xen-divert-tls-libc \ - fixups-inside \ - $dest/root/ +cp ${ADT_XENLVM_SHARE}/fixups-inside $dest/root/ mkdir -p $dest/lib/modules -cp -a /lib/modules/`uname -r`/ $dest/lib/modules/. +cp -a "${adt_modules}" $dest/lib/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>" + fi + if test -f "${adt_ssh_privkey}"; then + fail "will not overwrite existing private key \`$adt_ssh_privkey' - but where is public key \`$adt_ssh_pubkey' ?" + fi + + mkdir -p /root/.ssh + ssh-keygen -N '' ${adt_ssh_keygen_args} -f "${adt_ssh_privkey}" +fi -mkdir -p /root/.ssh -id_dsa=/root/.ssh/id_dsa_adt -test -f $id_dsa || ssh-keygen -t dsa -N '' -f $id_dsa mkdir -m 02700 -p $dest/root/.ssh -cp $id_dsa.pub $dest/root/.ssh/authorized_keys +cp -- "${adt_ssh_pubkey}" $dest/root/.ssh/authorized_keys cat <$dest/etc/init.d/xenethtoolk #!/bin/sh +# work around checksum offload bug in Xen network bridge driver case "$1" in start) ethtool -K eth0 tx off @@ -32,7 +39,10 @@ END chmod +x $dest/etc/init.d/xenethtoolk ln -s ../init.d/xenethtoolk $dest/etc/rc2.d/S21xenethtoolk -chroot $dest root/fixups-inside "$@" "$adt_host_ipaddr" "$adt_guest_ipaddr" +chroot $dest root/fixups-inside \ + "$adt_host_hostname" "$adt_guest_hostname" \ + "$adt_host_ipaddr" "$adt_guest_ipaddr" \ + "$adt_fs_type" kh=/etc/ssh/ssh_known_hosts test ! -f $kh || cp $kh $kh.new diff --git a/xen/fixups-inside b/xen/fixups-inside index 4bee8d8..67fea31 100755 --- a/xen/fixups-inside +++ b/xen/fixups-inside @@ -5,21 +5,28 @@ adt_host_hostname=$1 adt_guest_hostname=$2 adt_host_ipaddr=$3 adt_guest_ipaddr=$4 +adt_fs_type=$5 echo '(---' cd /root -perl -i~ -pe 's/ main$/ main universe/ if m/^deb http/' /etc/apt/sources.list -apt-get update +if test -f /etc/lsb-release; then + . /etc/lsb-release + if [ "x$DISTRIB_ID" = xUbuntu ]; then + perl -i~ -pe 's/ main$/ main universe/ if m/^deb http/' \ + /etc/apt/sources.list + fi +fi -apt-get -y --force-yes install libc6-xen || ./xen-divert-tls-libc do +apt-get update +apt-get -y --force-yes install libc6-xen ldconfig cat >/etc/fstab <&2 "xenlvm: ${0##*/}: error: $*" + exit 16 +} + +cmdline_args () { + while [ $# -gt 0 ]; do + arg="$1" + case "$arg" in + --*=*) + value="${arg#*=}" + + var=${arg%%=*} + var=${var#--} + case "$var" in + *-*) var="$(printf "%s" "$var" | tr -- - _)" ;; + esac + var=${var#adt_} + + case $var in + *) ;; # @@varlist@@ + *) fail "unknown configuration variable \`$var'" ;; + esac + + eval "$var=\"\$value\"" + shift ;; + + --) break ;; + -*) fail "unknown option \`$arg'" ;; + *) shift; break ;; + esac + done + test $# = 0 || fail "non-option arguments not allowed" +} + +. $ADT_XENLVM_SHARE/config-default +cmdline_args +. ${adt_config} + +. + + +lvm_baselv_namerhs=${adt_vg}/${adt_lvm_baselv} +lvm_baselv_namepath=/dev/${adt_lvbaserhs} + +lvm_cowdata_namerhs:=${adt_vg}/${adt_lvm_cowdatalv} +adt_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} diff --git a/xen/setup b/xen/setup index 786e62f..83e5ab4 100755 --- a/xen/setup +++ b/xen/setup @@ -1,39 +1,36 @@ #!/bin/bash set -e -. ./config -./cleanup -lvchange -a n $lvcowdata ||: -lvremove $lvbase ||: -lvremove $lvcowdata ||: +. ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig -lvcreate -L $adt_filesys_size -n $lvbase $adt_lvm_vg -lvcreate -L $adt_filesys_snapsize -n $ncowdata $adt_lvm_vg -#dd if=/dev/zero of=$lvbase -mkfs -t ext3 $lvbase +$ADT_XENLVM_SHARE/cleanup +lvchange -a n $lvm_cowdata_namepath ||: +lvremove $lvm_baselv_namepath ||: +lvremove $lvm_cowdata_namepath ||: -mkdir -p $play/base -mount $lvbase $play/base +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 -#--basetgz $play/base.tgz --buildplace +mkdir -p $adt_play/base +mount $adt_lvm_baselv $adt_play/base -pbuilder create --configfile ./pbuilderrc --distribution $distro \ - --no-targz --buildplace $play/base \ - $pbuilderopts --debootstrapopts --variant='' +pbuilder create --configfile /dev/null --distribution $distro \ + --no-targz --buildplace $adt_play/base \ + $adt_pbuilder_args --debootstrapopts --variant='' -./fixups $play/base $adt_host_hostname $adt_guest_hostname +$ADT_XENLVM_SHARE/fixups "$@" echo " --- writing $adt_xmconfig --- " -adt_host_ipaddr=`adnshost -t a +Do +Dt +Dc $adt_host_hostname` - cat <$adt_xmconfig kernel = "$kernel" memory = $adt_testbed_ram root = "/dev/hda1" extra = "ro console=tty0" -disk = [ "phy:$lvfsptrrhs,hda1,w" ] +disk = [ "phy:$lvm_fslink_ptrrhs,hda1,w" ] vif = [ "bridge=none,mac=00:16:3e:7c:aa:7f,ip=$adt_guest_ipaddr,script=/etc/xen/scripts/vif-route-adt" ] on_crash = "preserve" on_reboot = "preserve" @@ -46,31 +43,31 @@ ramdisk = "$ramdisk" END fi -umount $lvbase +umount $adt_lvm_baselv -mkdir -p /dev/${pfx}_fs -ln -sf ../$lvbaserhs $lvfsptr -xm create $adt_xmconfig name=$xmname +mkdir -p /dev/${lvm_fslink_dirpath} +ln -sf ../$lvm_baselv_namerhs ${lvm_fslink_ptr} +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 [ $retries -le 0 ]; then echo >&2 'no response from guest' - xm console $xmname + xm console $adt_xmname exit 1 fi retries=$(($retries-1)) sleep 2 done -xm mem-set $xmname $adt_freeze_ram -retries=10 +xm mem-set $adt_xmname $adt_freeze_ram +retries=$adt_vm_reduce_retries while sleep 1; do - if xm mem-max $xmname $adt_freeze_ram; then break; fi + if 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 $xmname $play/xen-save -rm $lvfsptr +xm save $adt_xmname $adt_play/xen-save +rm ${lvm_fslink_ptr} diff --git a/xen/tail-config b/xen/tail-config index 22494f7..996c857 100644 --- a/xen/tail-config +++ b/xen/tail-config @@ -33,6 +33,11 @@ none) echo "ramdisk \`none' specified, using static kernel" *) ;; esac +case "$adt_modules" in +'') /lib/modules/`uname -r` ;; +*) ;; +esac + case "$adt_distro" in '') echo "considering which distro to use ..." @@ -85,27 +90,25 @@ ipaddr_from_hostname () { ipaddr_from_hostname guest ipaddr_from_hostname host +: ${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config} + # SSH -: ${adt_sshkey:=/root/.ssh/id_dsa_${adt_nominum}} +: ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}} +: ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub} +: ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}} +: ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}} # Xen : ${adt_xmname:=${adt_nominum}_${adt_distro}} # In-host-file-system playground -: ${adt_play:=${adt_playbase}/${adt_distro}} +: ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}} : ${adt_xmconfig:=${adt_play}/xmconfig} # LVM -: ${adt_nbase:=${adt_nominum}_${adt_distro}_base} -: ${adt_lvbaserhs:=${adt_vg}/${adt_nbase}} -: ${adt_lvbase:=/dev/${adt_lvbaserhs}} - -: ${adt_nsnap:=${adt_nominum}_${adt_distro}_snap} -: ${adt_lvsnap:=/dev/mapper/${adt_nsnap}} - -: ${adt_ncowdata:=${adt_nominum}_${adt_distro}_cowdata} -: ${adt_lvcowdatarhs:=${adt_vg}/${adt_ncowdata}} -: ${adt_lvcowdata:=/dev/${adt_lvcowdatarhs}} +: ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base} +: ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata} +: ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap} -: ${adt_lvfsptrrhs:=${adt_nominum}_fs/${adt_distro}} -: ${adt_lvfsptr:=/dev/${adt_lvfsptrrhs}} +: ${adt_fslink_dir:=adt-xenlvm} +: ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs} diff --git a/xen/with-testbed b/xen/with-testbed index f1212c8..d102f8b 100755 --- a/xen/with-testbed +++ b/xen/with-testbed @@ -8,18 +8,18 @@ trap 'exit 127' 0 modprobe dm-snapshot ||: -#dd if=/dev/zero of=/dev/$lvcowdata bs=512 count=$adt_filesys_cowchunk status=noxfer +#dd if=/dev/zero of=/dev/$lvm_cowdata_namepath bs=512 count=$adt_fs_cowchunk status=noxfer -bdsize=$(blockdev --getsize $lvbase) -dmsetup create $nsnap <