Merge pull request #105 from cloudbuilders/timeout
exercise using timeouts instead of sleeping
diff --git a/files/sudo/nova b/files/sudo/nova
index 3843416..2ce1aac 100644
--- a/files/sudo/nova
+++ b/files/sudo/nova
@@ -1 +1,47 @@
-socat
+Cmnd_Alias NOVACMDS = /bin/chmod /var/lib/nova/tmp/*/root/.ssh, \
+ /bin/chown /var/lib/nova/tmp/*/root/.ssh, \
+ /bin/chown, \
+ /bin/chmod, \
+ /bin/dd, \
+ /sbin/ifconfig, \
+ /sbin/ip, \
+ /sbin/route, \
+ /sbin/iptables, \
+ /sbin/iptables-save, \
+ /sbin/iptables-restore, \
+ /sbin/ip6tables-save, \
+ /sbin/ip6tables-restore, \
+ /sbin/kpartx, \
+ /sbin/losetup, \
+ /sbin/lvcreate, \
+ /sbin/lvdisplay, \
+ /sbin/lvremove, \
+ /bin/mkdir, \
+ /bin/mount, \
+ /sbin/pvcreate, \
+ /usr/bin/tee, \
+ /sbin/tune2fs, \
+ /bin/umount, \
+ /sbin/vgcreate, \
+ /usr/bin/virsh, \
+ /usr/bin/qemu-nbd, \
+ /usr/sbin/brctl, \
+ /sbin/brctl, \
+ /usr/sbin/radvd, \
+ /usr/sbin/vblade-persist, \
+ /sbin/pvcreate, \
+ /sbin/aoe-discover, \
+ /sbin/vgcreate, \
+ /bin/aoe-stat, \
+ /bin/kill, \
+ /sbin/vconfig, \
+ /usr/sbin/ietadm, \
+ /sbin/vgs, \
+ /sbin/iscsiadm, \
+ /usr/bin/socat, \
+ /sbin/parted, \
+ /usr/sbin/dnsmasq, \
+ /usr/bin/arping
+
+%USER% ALL = (root) NOPASSWD: SETENV: NOVACMDS
+
diff --git a/stack.sh b/stack.sh
index 14bcfb2..b885e20 100755
--- a/stack.sh
+++ b/stack.sh
@@ -116,6 +116,14 @@
exec su -c "set -e; cd $STACK_DIR; bash stack.sh" stack
fi
exit 1
+else
+ # Our user needs passwordless priviledges for certain commands which nova
+ # uses internally.
+ # Natty uec images sudoers does not have a '#includedir'. add one.
+ sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
+ echo "#includedir /etc/sudoers.d" | sudo tee -a /etc/sudoers
+ sudo cp $FILES/sudo/nova /etc/sudoers.d/stack_sh_nova
+ sudo sed -e "s,%USER%,$USER,g" -i /etc/sudoers.d/stack_sh_nova
fi
# Set the destination directories for openstack projects
@@ -364,8 +372,6 @@
# it since we are going to run the services in screen for simple
cp $FILES/screenrc ~/.screenrc
-## TODO: update current user to allow sudo for all commands in files/sudo/*
-
# Rabbit
# ---------
diff --git a/tools/build_lxc.sh b/tools/build_lxc.sh
index b629183..786d839 100755
--- a/tools/build_lxc.sh
+++ b/tools/build_lxc.sh
@@ -152,6 +152,15 @@
cp -pr $CWD $CACHEDIR/$DEST/devstack
fi
+# pre-cache uec images
+for image_url in ${IMAGE_URLS//,/ }; do
+ IMAGE_FNAME=`basename "$image_url"`
+ if [ ! -f $CACHEDIR/$IMAGE_FNAME ]; then
+ wget -c $image_url -O $CACHEDIR/$IMAGE_FNAME
+ fi
+ cp $CACHEDIR/$IMAGE_FNAME $CACHEDIR/$DEST/devstack/files
+done
+
# Destroy the old container
lxc-destroy -n $GUEST_NAME
diff --git a/tools/build_pxe_boot.sh b/tools/build_pxe_boot.sh
index 7fd964b..da8bbcc 100755
--- a/tools/build_pxe_boot.sh
+++ b/tools/build_pxe_boot.sh
@@ -1,17 +1,11 @@
#!/bin/bash -e
# build_pxe_boot.sh - Create a PXE boot environment
#
-# build_pxe_boot.sh [-k kernel-version] destdir
+# build_pxe_boot.sh destdir
#
# Assumes syslinux is installed
# Only needs to run as root if the destdir permissions require it
-KVER=`uname -r`
-if [ "$1" = "-k" ]; then
- KVER=$2
- shift;shift
-fi
-
DEST_DIR=${1:-/tmp}/tftpboot
PXEDIR=${PXEDIR:-/var/cache/devstack/pxe}
OPWD=`pwd`
@@ -20,7 +14,7 @@
mkdir -p $DEST_DIR/pxelinux.cfg
cd $DEST_DIR
for i in memdisk menu.c32 pxelinux.0; do
- cp -p /usr/lib/syslinux/$i $DEST_DIR
+ cp -pu /usr/lib/syslinux/$i $DEST_DIR
done
CFG=$DEST_DIR/pxelinux.cfg/default
@@ -38,20 +32,37 @@
if [ ! -d $PXEDIR ]; then
mkdir -p $PXEDIR
fi
-if [ ! -r $PXEDIR/vmlinuz-${KVER} ]; then
- sudo chmod 644 /boot/vmlinuz-${KVER}
- if [ ! -r /boot/vmlinuz-${KVER} ]; then
- echo "No kernel found"
- else
- cp -p /boot/vmlinuz-${KVER} $PXEDIR
- fi
-fi
-cp -p $PXEDIR/vmlinuz-${KVER} $DEST_DIR/ubuntu
-if [ ! -r $PXEDIR/stack-initrd.gz ]; then
+
+# Get image into place
+if [ ! -r $PXEDIR/stack-initrd.img ]; then
cd $OPWD
- sudo $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.gz
+ $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.img
fi
-cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
+if [ ! -r $PXEDIR/stack-initrd.gz ]; then
+ gzip -1 -c $PXEDIR/stack-initrd.img >$PXEDIR/stack-initrd.gz
+fi
+cp -pu $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
+
+if [ ! -r $PXEDIR/vmlinuz-*-generic ]; then
+ MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
+ mount -t ext4 -o loop $PXEDIR/stack-initrd.img $MNTDIR
+
+ if [ ! -r $MNTDIR/boot/vmlinuz-*-generic ]; then
+ echo "No kernel found"
+ umount $MNTDIR
+ rmdir $MNTDIR
+ exit 1
+ else
+ cp -pu $MNTDIR/boot/vmlinuz-*-generic $PXEDIR
+ fi
+ umount $MNTDIR
+ rmdir $MNTDIR
+fi
+
+# Get generic kernel version
+KNAME=`basename $PXEDIR/vmlinuz-*-generic`
+KVER=${KNAME#vmlinuz-}
+cp -pu $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu
cat >>$CFG <<EOF
LABEL devstack
@@ -63,7 +74,7 @@
# Get Ubuntu
if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
- cp -p $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
+ cp -pu $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
cat >>$CFG <<EOF
LABEL ubuntu
diff --git a/tools/build_ramdisk.sh b/tools/build_ramdisk.sh
index be6ca77..d169b9f 100755
--- a/tools/build_ramdisk.sh
+++ b/tools/build_ramdisk.sh
@@ -7,6 +7,8 @@
exit 1
fi
+IMG_FILE=$1
+
PROGDIR=`dirname $0`
CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
@@ -24,42 +26,83 @@
# Option to use the version of devstack on which we are currently working
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
+# Set up nbd
+modprobe nbd max_part=63
+NBD=${NBD:-/dev/nbd9}
+NBD_DEV=`basename $NBD`
+
# clean install of natty
-if [ ! -d $CHROOTCACHE/natty-base ]; then
- $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
- # copy kernel modules...
- # NOTE(ja): is there a better way to do this?
- cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
- # a simple password - pass
- echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
+if [ ! -r $CHROOTCACHE/natty-base.img ]; then
+ $PROGDIR/get_uec_image.sh natty $CHROOTCACHE/natty-base.img
+# # copy kernel modules...
+# # NOTE(ja): is there a better way to do this?
+# cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
+# # a simple password - pass
+# echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
fi
# prime natty with as many apt/pips as we can
-if [ ! -d $CHROOTCACHE/natty-dev ]; then
- rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
- chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
- chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
+if [ ! -r $CHROOTCACHE/natty-dev.img ]; then
+ cp -p $CHROOTCACHE/natty-base.img $CHROOTCACHE/natty-dev.img
+
+ qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img
+ if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
+ echo "Couldn't connect $NBD"
+ exit 1
+ fi
+ MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
+ mount -t ext4 ${NBD}p1 $MNTDIR
+ cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
+
+ chroot $MNTDIR apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
+ chroot $MNTDIR pip install `cat files/pips/*`
# Create a stack user that is a member of the libvirtd group so that stack
# is able to interact with libvirt.
- chroot $CHROOTCACHE/natty-dev groupadd libvirtd
- chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
- mkdir -p $CHROOTCACHE/natty-dev/$DEST
- chroot $CHROOTCACHE/natty-dev chown stack $DEST
+ chroot $MNTDIR groupadd libvirtd
+ chroot $MNTDIR useradd stack -s /bin/bash -d $DEST -G libvirtd
+ mkdir -p $MNTDIR/$DEST
+ chroot $MNTDIR chown stack $DEST
# a simple password - pass
- echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
+ echo stack:pass | chroot $MNTDIR chpasswd
# and has sudo ability (in the future this should be limited to only what
# stack requires)
- echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
+ echo "stack ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers
+
+ umount $MNTDIR
+ rmdir $MNTDIR
+ qemu-nbd -d $NBD
fi
# clone git repositories onto the system
# ======================================
-if [ ! -d $CHROOTCACHE/natty-stack ]; then
- rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
+if [ ! -r $IMG_FILE ]; then
+ qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img
+ if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then
+ echo "Couldn't connect $NBD"
+ exit 1
+ fi
+
+ # Pre-create the image file
+ # FIXME(dt): This should really get the partition size to
+ # pre-create the image file
+ dd if=/dev/zero of=$IMG_FILE bs=1 count=1 seek=$((2*1024*1024*1024))
+ # Create filesystem image for RAM disk
+ dd if=${NBD}p1 of=$IMG_FILE bs=1M
+
+ qemu-nbd -d $NBD
+fi
+
+MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
+mount -t ext4 -o loop $IMG_FILE $MNTDIR
+cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
+
+# We need to install a non-virtual kernel and modules to boot from
+if [ ! -r "`ls $MNTDIR/boot/vmlinuz-*-generic | head -1`" ]; then
+ chroot $MNTDIR apt-get install -y linux-generic
fi
# git clone only if directory doesn't exist already. Since ``DEST`` might not
@@ -68,7 +111,7 @@
function git_clone {
# clone new copy or fetch latest changes
- CHECKOUT=$CHROOTCACHE/natty-stack$2
+ CHECKOUT=${MNTDIR}$2
if [ ! -d $CHECKOUT ]; then
mkdir -p $CHECKOUT
git clone $1 $CHECKOUT
@@ -88,7 +131,7 @@
popd
# give ownership to the stack user
- chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
+ chroot $MNTDIR chown -R stack $2
}
git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
@@ -100,13 +143,13 @@
git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
# Use this version of devstack
-rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack
-cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack
-chroot $CHROOTCACHE/natty-stack chown -R stack $DEST/devstack
+rm -rf $MNTDIR/$DEST/devstack
+cp -pr $CWD $MNTDIR/$DEST/devstack
+chroot $MNTDIR chown -R stack $DEST/devstack
# Configure host network for DHCP
-mkdir -p $CHROOTCACHE/natty-stack/etc/network
-cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF
+mkdir -p $MNTDIR/etc/network
+cat > $MNTDIR/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
@@ -115,11 +158,11 @@
EOF
# Set hostname
-echo "ramstack" >$CHROOTCACHE/natty-stack/etc/hostname
-echo "127.0.0.1 localhost ramstack" >$CHROOTCACHE/natty-stack/etc/hosts
+echo "ramstack" >$MNTDIR/etc/hostname
+echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts
# Configure the runner
-RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh
+RUN_SH=$MNTDIR/$DEST/run.sh
cat > $RUN_SH <<EOF
#!/usr/bin/env bash
@@ -140,27 +183,7 @@
# Make the run.sh executable
chmod 755 $RUN_SH
-chroot $CHROOTCACHE/natty-stack chown stack $DEST/run.sh
+chroot $MNTDIR chown stack $DEST/run.sh
-# build a new image
-BASE=$CHROOTCACHE/build.$$
-IMG=$BASE.img
-MNT=$BASE/
-
-# (quickly) create a 2GB blank filesystem
-dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG
-# force it to be initialized as ext2
-mkfs.ext2 -F $IMG
-
-# mount blank image loopback and load it
-mkdir -p $MNT
-mount -o loop $IMG $MNT
-rsync -azH $CHROOTCACHE/natty-stack/ $MNT
-
-# umount and cleanup
-umount $MNT
-rmdir $MNT
-
-# gzip into final location
-gzip -1 $IMG -c > $1
-
+umount $MNTDIR
+rmdir $MNTDIR
diff --git a/tools/build_usb_boot.sh b/tools/build_usb_boot.sh
index 332c869..fc5e969 100755
--- a/tools/build_usb_boot.sh
+++ b/tools/build_usb_boot.sh
@@ -1,17 +1,11 @@
#!/bin/bash -e
# build_usb_boot.sh - Create a syslinux boot environment
#
-# build_usb_boot.sh [-k kernel-version] destdev
+# build_usb_boot.sh destdev
#
# Assumes syslinux is installed
# Needs to run as root
-KVER=`uname -r`
-if [ "$1" = "-k" ]; then
- KVER=$2
- shift;shift
-fi
-
DEST_DIR=${1:-/tmp/syslinux-boot}
PXEDIR=${PXEDIR:-/var/cache/devstack/pxe}
OPWD=`pwd`
@@ -20,7 +14,7 @@
if [ -b $DEST_DIR ]; then
# We have a block device, install syslinux and mount it
DEST_DEV=$DEST_DIR
- DEST_DIR=`mktemp -d mntXXXXXX`
+ DEST_DIR=`mktemp -d --tmpdir mntXXXXXX`
mount $DEST_DEV $DEST_DIR
if [ ! -d $DEST_DIR/syslinux ]; then
@@ -39,7 +33,7 @@
# Get some more stuff from syslinux
for i in memdisk menu.c32; do
- cp -p /usr/lib/syslinux/$i $DEST_DIR/syslinux
+ cp -pu /usr/lib/syslinux/$i $DEST_DIR/syslinux
done
CFG=$DEST_DIR/syslinux/syslinux.cfg
@@ -57,20 +51,41 @@
if [ ! -d $PXEDIR ]; then
mkdir -p $PXEDIR
fi
-if [ ! -r $PXEDIR/vmlinuz-${KVER} ]; then
- sudo chmod 644 /boot/vmlinuz-${KVER}
- if [ ! -r /boot/vmlinuz-${KVER} ]; then
- echo "No kernel found"
- else
- cp -p /boot/vmlinuz-${KVER} $PXEDIR
- fi
-fi
-cp -p $PXEDIR/vmlinuz-${KVER} $DEST_DIR/ubuntu
-if [ ! -r $PXEDIR/stack-initrd.gz ]; then
+
+# Get image into place
+if [ ! -r $PXEDIR/stack-initrd.img ]; then
cd $OPWD
- sudo $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.gz
+ $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.img
fi
-cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
+if [ ! -r $PXEDIR/stack-initrd.gz ]; then
+ gzip -1 -c $PXEDIR/stack-initrd.img >$PXEDIR/stack-initrd.gz
+fi
+cp -pu $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
+
+if [ ! -r $PXEDIR/vmlinuz-*-generic ]; then
+ MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
+ mount -t ext4 -o loop $PXEDIR/stack-initrd.img $MNTDIR
+
+ if [ ! -r $MNTDIR/boot/vmlinuz-*-generic ]; then
+ echo "No kernel found"
+ umount $MNTDIR
+ rmdir $MNTDIR
+ if [ -n "$DEST_DEV" ]; then
+ umount $DEST_DIR
+ rmdir $DEST_DIR
+ fi
+ exit 1
+ else
+ cp -pu $MNTDIR/boot/vmlinuz-*-generic $PXEDIR
+ fi
+ umount $MNTDIR
+ rmdir $MNTDIR
+fi
+
+# Get generic kernel version
+KNAME=`basename $PXEDIR/vmlinuz-*-generic`
+KVER=${KNAME#vmlinuz-}
+cp -pu $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu
cat >>$CFG <<EOF
LABEL devstack
@@ -82,7 +97,7 @@
# Get Ubuntu
if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
- cp -p $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
+ cp -pu $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
cat >>$CFG <<EOF
LABEL ubuntu
diff --git a/tools/get_uec_image.sh b/tools/get_uec_image.sh
index e9d708d..b903ad7 100755
--- a/tools/get_uec_image.sh
+++ b/tools/get_uec_image.sh
@@ -131,16 +131,17 @@
if [ $ROOTSIZE -gt 2000 ]; then
# Resize the container
qemu-img resize $IMG_FILE +$((ROOTSIZE - 2000))M
+fi
- # Connect to nbd and wait till it is ready
- qemu-nbd -c $NBD $IMG_FILE
- if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
- echo "Couldn't connect $NBD"
- exit 1
- fi
+# Connect to nbd and wait till it is ready
+qemu-nbd -c $NBD $IMG_FILE
+if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
+echo "Couldn't connect $NBD"
+ exit 1
+fi
- # Resize partition 1 to full size of the disk image
- echo "d
+# Resize partition 1 to full size of the disk image
+echo "d
n
p
1
@@ -152,8 +153,7 @@
1
w
" | fdisk $NBD
- fsck -t ext4 -f ${NBD}p1
- resize2fs ${NBD}p1
+fsck -t ext4 -f ${NBD}p1
+resize2fs ${NBD}p1
- qemu-nbd -d $NBD
-fi
+qemu-nbd -d $NBD