| ... | ... |
@@ -7,6 +7,8 @@ if [ ! "$#" -eq "1" ]; then |
| 7 | 7 |
exit 1 |
| 8 | 8 |
fi |
| 9 | 9 |
|
| 10 |
+IMG_FILE=$1 |
|
| 11 |
+ |
|
| 10 | 12 |
PROGDIR=`dirname $0` |
| 11 | 13 |
CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
|
| 12 | 14 |
|
| ... | ... |
@@ -24,51 +26,79 @@ STACKSH_PARAMS=${STACKSH_PARAMS:-}
|
| 24 | 24 |
# Option to use the version of devstack on which we are currently working |
| 25 | 25 |
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
|
| 26 | 26 |
|
| 27 |
+# Set up nbd |
|
| 28 |
+modprobe nbd max_part=63 |
|
| 29 |
+NBD=${NBD:-/dev/nbd9}
|
|
| 30 |
+NBD_DEV=`basename $NBD` |
|
| 31 |
+ |
|
| 27 | 32 |
# clean install of natty |
| 28 |
-if [ ! -d $CHROOTCACHE/natty-base ]; then |
|
| 29 |
- $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base |
|
| 30 |
- # copy kernel modules... |
|
| 31 |
- # NOTE(ja): is there a better way to do this? |
|
| 32 |
- cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules |
|
| 33 |
- # a simple password - pass |
|
| 34 |
- echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd |
|
| 33 |
+if [ ! -r $CHROOTCACHE/natty-base.img ]; then |
|
| 34 |
+ $PROGDIR/get_uec_image.sh natty $CHROOTCACHE/natty-base.img |
|
| 35 |
+# # copy kernel modules... |
|
| 36 |
+# # NOTE(ja): is there a better way to do this? |
|
| 37 |
+# cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules |
|
| 38 |
+# # a simple password - pass |
|
| 39 |
+# echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd |
|
| 35 | 40 |
fi |
| 36 | 41 |
|
| 37 | 42 |
# prime natty with as many apt/pips as we can |
| 38 |
-if [ ! -d $CHROOTCACHE/natty-dev ]; then |
|
| 39 |
- rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/ |
|
| 40 |
- chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
|
| 41 |
- chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*` |
|
| 43 |
+if [ ! -r $CHROOTCACHE/natty-dev.img ]; then |
|
| 44 |
+ cp -p $CHROOTCACHE/natty-base.img $CHROOTCACHE/natty-dev.img |
|
| 45 |
+ |
|
| 46 |
+ qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img |
|
| 47 |
+ if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then |
|
| 48 |
+ echo "Couldn't connect $NBD" |
|
| 49 |
+ exit 1 |
|
| 50 |
+ fi |
|
| 51 |
+ MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX` |
|
| 52 |
+ mount -t ext4 ${NBD}p1 $MNTDIR
|
|
| 53 |
+ cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf |
|
| 54 |
+ |
|
| 55 |
+ chroot $MNTDIR apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
|
| 56 |
+ chroot $MNTDIR pip install `cat files/pips/*` |
|
| 42 | 57 |
|
| 43 | 58 |
# Create a stack user that is a member of the libvirtd group so that stack |
| 44 | 59 |
# is able to interact with libvirt. |
| 45 |
- chroot $CHROOTCACHE/natty-dev groupadd libvirtd |
|
| 46 |
- chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd |
|
| 47 |
- mkdir -p $CHROOTCACHE/natty-dev/$DEST |
|
| 48 |
- chroot $CHROOTCACHE/natty-dev chown stack $DEST |
|
| 60 |
+ chroot $MNTDIR groupadd libvirtd |
|
| 61 |
+ chroot $MNTDIR useradd stack -s /bin/bash -d $DEST -G libvirtd |
|
| 62 |
+ mkdir -p $MNTDIR/$DEST |
|
| 63 |
+ chroot $MNTDIR chown stack $DEST |
|
| 49 | 64 |
|
| 50 | 65 |
# a simple password - pass |
| 51 |
- echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd |
|
| 66 |
+ echo stack:pass | chroot $MNTDIR chpasswd |
|
| 52 | 67 |
|
| 53 | 68 |
# and has sudo ability (in the future this should be limited to only what |
| 54 | 69 |
# stack requires) |
| 55 |
- echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers |
|
| 70 |
+ echo "stack ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers |
|
| 71 |
+ |
|
| 72 |
+ umount $MNTDIR |
|
| 73 |
+ rmdir $MNTDIR |
|
| 74 |
+ qemu-nbd -d $NBD |
|
| 56 | 75 |
fi |
| 57 | 76 |
|
| 58 | 77 |
# clone git repositories onto the system |
| 59 | 78 |
# ====================================== |
| 60 | 79 |
|
| 61 |
-if [ ! -d $CHROOTCACHE/natty-stack ]; then |
|
| 62 |
- rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/ |
|
| 80 |
+if [ ! -r $IMG_FILE ]; then |
|
| 81 |
+ qemu-img convert -O raw $CHROOTCACHE/natty-dev.img $IMG_FILE |
|
| 63 | 82 |
fi |
| 64 | 83 |
|
| 84 |
+qemu-nbd -c $NBD $IMG_FILE |
|
| 85 |
+if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then |
|
| 86 |
+ echo "Couldn't connect $NBD" |
|
| 87 |
+ exit 1 |
|
| 88 |
+fi |
|
| 89 |
+MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX` |
|
| 90 |
+mount -t ext4 ${NBD}p1 $MNTDIR
|
|
| 91 |
+cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf |
|
| 92 |
+ |
|
| 65 | 93 |
# git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 66 | 94 |
# be owned by the installation user, we create the directory and change the |
| 67 | 95 |
# ownership to the proper user. |
| 68 | 96 |
function git_clone {
|
| 69 | 97 |
|
| 70 | 98 |
# clone new copy or fetch latest changes |
| 71 |
- CHECKOUT=$CHROOTCACHE/natty-stack$2 |
|
| 99 |
+ CHECKOUT=${MNTDIR}$2
|
|
| 72 | 100 |
if [ ! -d $CHECKOUT ]; then |
| 73 | 101 |
mkdir -p $CHECKOUT |
| 74 | 102 |
git clone $1 $CHECKOUT |
| ... | ... |
@@ -88,7 +118,7 @@ function git_clone {
|
| 88 | 88 |
popd |
| 89 | 89 |
|
| 90 | 90 |
# give ownership to the stack user |
| 91 |
- chroot $CHROOTCACHE/natty-stack/ chown -R stack $2 |
|
| 91 |
+ chroot $MNTDIR chown -R stack $2 |
|
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 | 94 |
git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH |
| ... | ... |
@@ -100,13 +130,13 @@ git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH |
| 100 | 100 |
git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH |
| 101 | 101 |
|
| 102 | 102 |
# Use this version of devstack |
| 103 |
-rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack |
|
| 104 |
-cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack |
|
| 105 |
-chroot $CHROOTCACHE/natty-stack chown -R stack $DEST/devstack |
|
| 103 |
+rm -rf $MNTDIR/$DEST/devstack |
|
| 104 |
+cp -pr $CWD $MNTDIR/$DEST/devstack |
|
| 105 |
+chroot $MNTDIR chown -R stack $DEST/devstack |
|
| 106 | 106 |
|
| 107 | 107 |
# Configure host network for DHCP |
| 108 |
-mkdir -p $CHROOTCACHE/natty-stack/etc/network |
|
| 109 |
-cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF |
|
| 108 |
+mkdir -p $MNTDIR/etc/network |
|
| 109 |
+cat > $MNTDIR/etc/network/interfaces <<EOF |
|
| 110 | 110 |
auto lo |
| 111 | 111 |
iface lo inet loopback |
| 112 | 112 |
|
| ... | ... |
@@ -115,11 +145,11 @@ iface eth0 inet dhcp |
| 115 | 115 |
EOF |
| 116 | 116 |
|
| 117 | 117 |
# Set hostname |
| 118 |
-echo "ramstack" >$CHROOTCACHE/natty-stack/etc/hostname |
|
| 119 |
-echo "127.0.0.1 localhost ramstack" >$CHROOTCACHE/natty-stack/etc/hosts |
|
| 118 |
+echo "ramstack" >$MNTDIR/etc/hostname |
|
| 119 |
+echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts |
|
| 120 | 120 |
|
| 121 | 121 |
# Configure the runner |
| 122 |
-RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh |
|
| 122 |
+RUN_SH=$MNTDIR/$DEST/run.sh |
|
| 123 | 123 |
cat > $RUN_SH <<EOF |
| 124 | 124 |
#!/usr/bin/env bash |
| 125 | 125 |
|
| ... | ... |
@@ -140,27 +170,10 @@ EOF |
| 140 | 140 |
|
| 141 | 141 |
# Make the run.sh executable |
| 142 | 142 |
chmod 755 $RUN_SH |
| 143 |
-chroot $CHROOTCACHE/natty-stack chown stack $DEST/run.sh |
|
| 144 |
- |
|
| 145 |
-# build a new image |
|
| 146 |
-BASE=$CHROOTCACHE/build.$$ |
|
| 147 |
-IMG=$BASE.img |
|
| 148 |
-MNT=$BASE/ |
|
| 149 |
- |
|
| 150 |
-# (quickly) create a 2GB blank filesystem |
|
| 151 |
-dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG |
|
| 152 |
-# force it to be initialized as ext2 |
|
| 153 |
-mkfs.ext2 -F $IMG |
|
| 154 |
- |
|
| 155 |
-# mount blank image loopback and load it |
|
| 156 |
-mkdir -p $MNT |
|
| 157 |
-mount -o loop $IMG $MNT |
|
| 158 |
-rsync -azH $CHROOTCACHE/natty-stack/ $MNT |
|
| 159 |
- |
|
| 160 |
-# umount and cleanup |
|
| 161 |
-umount $MNT |
|
| 162 |
-rmdir $MNT |
|
| 143 |
+chroot $MNTDIR chown stack $DEST/run.sh |
|
| 163 | 144 |
|
| 164 |
-# gzip into final location |
|
| 165 |
-gzip -1 $IMG -c > $1 |
|
| 145 |
+umount $MNTDIR |
|
| 146 |
+rmdir $MNTDIR |
|
| 147 |
+qemu-nbd -d $NBD |
|
| 166 | 148 |
|
| 149 |
+gzip -1 $IMG_FILE |