Browse code

Merge pull request #47 from dtroyer/master

Updates to build_nfs.sh and build_pxe_ramdisk.sh for common functions

Jesse Andrews authored on 2011/10/04 11:31:42
Showing 4 changed files
... ...
@@ -1,70 +1,117 @@
1 1
 #!/bin/bash
2 2
 
3
+PROGDIR=`dirname $0`
4
+CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
5
+
3 6
 # Source params
4 7
 source ./stackrc
5 8
 
6
-# TODO: make dest not hardcoded
9
+# Store cwd
10
+CWD=`pwd`
7 11
 
8 12
 NAME=$1
9
-DEST="/nfs/$NAME"
13
+NFSDIR="/nfs/$NAME"
14
+DEST=${DEST:-/opt/stack}
15
+
16
+# Option to use the version of devstack on which we are currently working
17
+USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
10 18
 
11 19
 # remove old nfs filesystem if one exists
12 20
 rm -rf $DEST
13 21
 
14
-# build a proto image - natty + packages that will install (optimization)
15
-if [ ! -d proto ]; then
16
-    debootstrap natty proto
17
-    cp files/sources.list proto/etc/apt/sources.list
18
-    chroot proto apt-get update
19
-    chroot proto apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
20
-    chroot proto pip install `cat files/pips/*`
21
-    git_clone $NOVA_REPO proto/opt/nova $NOVA_BRANCH
22
-    git_clone $GLANCE_REPO proto/opt/glance $GLANCE_BRANCH
23
-    git_clone $KEYSTONE_REPO proto/opt/keystone $KEYSTONE_BRANCH
24
-    git_clone $NOVNC_REPO proto/opt/novnc $NOVNC_BRANCH
25
-    git_clone $DASH_REPO proto/opt/dash $DASH_BRANCH $DASH_TAG
26
-    git_clone $NOVACLIENT_REPO proto/opt/python-novaclient $NOVACLIENT_BRANCH
27
-    git_clone $OPENSTACKX_REPO proto/opt/openstackx $OPENSTACKX_BRANCH
28
-    chroot proto mkdir -p /opt/files
29
-    wget -c http://images.ansolabs.com/tty.tgz -O proto/opt/files/tty.tgz
22
+# clean install of natty
23
+if [ ! -d $CHROOTCACHE/natty-base ]; then
24
+    $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
25
+    # copy kernel modules...  
26
+    # NOTE(ja): is there a better way to do this?
27
+    cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
28
+    # a simple password - pass
29
+    echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
30 30
 fi
31 31
 
32
-cp -pr proto $DEST
32
+# prime natty with as many apt/pips as we can
33
+if [ ! -d $CHROOTCACHE/natty-dev ]; then
34
+    rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
35
+    chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
36
+    chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
33 37
 
34
-# set hostname
35
-echo $NAME > $DEST/etc/hostname
36
-echo "127.0.0.1 localhost $NAME" > $DEST/etc/hosts
38
+    # Create a stack user that is a member of the libvirtd group so that stack 
39
+    # is able to interact with libvirt.
40
+    chroot $CHROOTCACHE/natty-dev groupadd libvirtd
41
+    chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
42
+    mkdir -p $CHROOTCACHE/natty-dev/$DEST
43
+    chown stack $CHROOTCACHE/natty-dev/$DEST
44
+
45
+    # a simple password - pass
46
+    echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
47
+
48
+    # and has sudo ability (in the future this should be limited to only what 
49
+    # stack requires)
50
+    echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
51
+fi
52
+
53
+# clone git repositories onto the system
54
+# ======================================
55
+
56
+if [ ! -d $CHROOTCACHE/natty-stack ]; then
57
+    rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
58
+fi
37 59
 
38
-# copy kernel modules
39
-cp -pr /lib/modules/`uname -r` $DEST/lib/modules
60
+# git clone only if directory doesn't exist already.  Since ``DEST`` might not
61
+# be owned by the installation user, we create the directory and change the
62
+# ownership to the proper user.
63
+function git_clone {
40 64
 
65
+    # clone new copy or fetch latest changes
66
+    CHECKOUT=$CHROOTCACHE/natty-stack$2
67
+    if [ ! -d $CHECKOUT ]; then
68
+        mkdir -p $CHECKOUT
69
+        git clone $1 $CHECKOUT
70
+    else
71
+        pushd $CHECKOUT
72
+        git fetch
73
+        popd
74
+    fi
41 75
 
42
-# copy openstack installer and requirement lists to a new directory.
43
-mkdir -p $DEST/opt
76
+    # FIXME(ja): checkout specified version (should works for branches and tags)
44 77
 
45
-# inject stack.sh and dependant files
46
-cp -r files $DEST/opt/files
47
-cp stack.sh $DEST/opt/stack.sh
78
+    pushd $CHECKOUT
79
+    # checkout the proper branch/tag
80
+    git checkout $3
81
+    # force our local version to be the same as the remote version
82
+    git reset --hard origin/$3
83
+    popd
84
+
85
+    # give ownership to the stack user
86
+    chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
87
+}
88
+
89
+git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
90
+git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
91
+git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
92
+git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
93
+git_clone $DASH_REPO $DEST/dash $DASH_BRANCH $DASH_TAG
94
+git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
95
+git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
96
+
97
+chroot $CHROOTCACHE/natty-stack mkdir -p $DEST/files
98
+wget -c http://images.ansolabs.com/tty.tgz -O $CHROOTCACHE/natty-stack$DEST/files/tty.tgz
99
+
100
+# Use this version of devstack?
101
+if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
102
+    rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack
103
+    cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack
104
+fi
105
+
106
+cp -pr $CHROOTCACHE/natty-stack $NFSDIR
107
+
108
+# set hostname
109
+echo $NAME > $NFSDIR/etc/hostname
110
+echo "127.0.0.1 localhost $NAME" > $NFSDIR/etc/hosts
48 111
 
49 112
 # injecting root's public ssh key if it exists
50 113
 if [ -f /root/.ssh/id_rsa.pub ]; then
51
-    mkdir $DEST/root/.ssh
52
-    chmod 700 $DEST/root/.ssh
53
-    cp /root/.ssh/id_rsa.pub $DEST/root/.ssh/authorized_keys
114
+    mkdir $NFSDIR/root/.ssh
115
+    chmod 700 $NFSDIR/root/.ssh
116
+    cp /root/.ssh/id_rsa.pub $NFSDIR/root/.ssh/authorized_keys
54 117
 fi
55
-
56
-# set root password to password
57
-echo root:pass | chroot $DEST chpasswd
58
-
59
-# Create a stack user that is a member of the libvirtd group so that stack 
60
-# is able to interact with libvirt.
61
-chroot $DEST groupadd libvirtd
62
-chroot $DEST useradd stack -s /bin/bash -d /opt -G libvirtd
63
-# a simple password - pass
64
-echo stack:pass | chroot $DEST chpasswd
65
-# give stack ownership over /opt so it may do the work needed
66
-chroot $DEST chown -R stack /opt
67
-
68
-# and has sudo ability (in the future this should be limited to only what 
69
-# stack requires)
70
-echo "stack ALL=(ALL) NOPASSWD: ALL" >> $DEST/etc/sudoers
... ...
@@ -20,6 +20,7 @@ if [ "$1" = "-k" ]; then
20 20
 fi
21 21
 
22 22
 DEST_DIR=${1:-/tmp}/tftpboot
23
+PXEDIR=${PXEDIR:-/var/cache/devstack/pxe}
23 24
 OPWD=`pwd`
24 25
 PROGDIR=`dirname $0`
25 26
 
... ...
@@ -41,23 +42,23 @@ EOF
41 41
 
42 42
 # Setup devstack boot
43 43
 mkdir -p $DEST_DIR/ubuntu
44
-if [ ! -d $OPWD/pxe ]; then
45
-    mkdir -p $OPWD/pxe
44
+if [ ! -d $PXEDIR ]; then
45
+    mkdir -p $PXEDIR
46 46
 fi
47
-if [ ! -r $OPWD/pxe/vmlinuz-${KVER} ]; then
47
+if [ ! -r $PXEDIR/vmlinuz-${KVER} ]; then
48 48
     sudo chmod 644 /boot/vmlinuz-${KVER}
49 49
     if [ ! -r /boot/vmlinuz-${KVER} ]; then
50 50
         echo "No kernel found"
51 51
     else
52
-        cp -p /boot/vmlinuz-${KVER} $OPWD/pxe
52
+        cp -p /boot/vmlinuz-${KVER} $PXEDIR
53 53
     fi
54 54
 fi
55
-cp -p $OPWD/pxe/vmlinuz-${KVER} $DEST_DIR/ubuntu
56
-if [ ! -r $OPWD/pxe/stack-initrd.gz ]; then
55
+cp -p $PXEDIR/vmlinuz-${KVER} $DEST_DIR/ubuntu
56
+if [ ! -r $PXEDIR/stack-initrd.gz ]; then
57 57
     cd $OPWD
58
-    sudo $PROGDIR/build_pxe_ramdisk.sh $OPWD/pxe/stack-initrd.gz
58
+    sudo $PROGDIR/build_pxe_ramdisk.sh $PXEDIR/stack-initrd.gz
59 59
 fi
60
-cp -p $OPWD/pxe/stack-initrd.gz $DEST_DIR/ubuntu
60
+cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
61 61
 cat >>$DEFAULT <<EOF
62 62
 
63 63
 LABEL devstack
... ...
@@ -68,8 +69,8 @@ LABEL devstack
68 68
 EOF
69 69
 
70 70
 # Get Ubuntu
71
-if [ -d $OPWD/pxe ]; then
72
-    cp -p $OPWD/pxe/natty-base-initrd.gz $DEST_DIR/ubuntu
71
+if [ -d $PXEDIR ]; then
72
+    cp -p $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
73 73
 fi
74 74
 cat >>$DEFAULT <<EOF
75 75
 
... ...
@@ -7,44 +7,55 @@ if [ ! "$#" -eq "1" ]; then
7 7
 fi
8 8
 
9 9
 PROGDIR=`dirname $0`
10
+CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
10 11
 
11 12
 # Source params
12 13
 source ./stackrc
13 14
 
15
+# Store cwd
16
+CWD=`pwd`
17
+
18
+DEST=${DEST:-/opt/stack}
19
+
20
+# Option to use the version of devstack on which we are currently working
21
+USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
22
+
14 23
 # clean install of natty
15
-if [ ! -d natty-base ]; then
16
-    $PROGDIR/make_image.sh -C natty natty-base
24
+if [ ! -d $CHROOTCACHE/natty-base ]; then
25
+    $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
17 26
     # copy kernel modules...  
18 27
     # NOTE(ja): is there a better way to do this?
19
-    cp -pr /lib/modules/`uname -r` natty-base/lib/modules
28
+    cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
20 29
     # a simple password - pass
21
-    echo root:pass | chroot natty-base chpasswd
30
+    echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
22 31
 fi
23 32
 
24 33
 # prime natty with as many apt/pips as we can
25
-if [ ! -d primed ]; then
26
-    rsync -azH natty-base/ primed/
27
-    chroot primed apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
28
-    chroot primed pip install `cat files/pips/*`
34
+if [ ! -d $CHROOTCACHE/natty-dev ]; then
35
+    rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
36
+    chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
37
+    chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
29 38
 
30 39
     # Create a stack user that is a member of the libvirtd group so that stack 
31 40
     # is able to interact with libvirt.
32
-    chroot primed groupadd libvirtd
33
-    chroot primed useradd stack -s /bin/bash -d /opt -G libvirtd
41
+    chroot $CHROOTCACHE/natty-dev groupadd libvirtd
42
+    chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
43
+    mkdir -p $CHROOTCACHE/natty-dev/$DEST
44
+    chown stack $CHROOTCACHE/natty-dev/$DEST
34 45
 
35 46
     # a simple password - pass
36
-    echo stack:pass | chroot primed chpasswd
47
+    echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
37 48
 
38 49
     # and has sudo ability (in the future this should be limited to only what 
39 50
     # stack requires)
40
-    echo "stack ALL=(ALL) NOPASSWD: ALL" >> primed/etc/sudoers
51
+    echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
41 52
 fi
42 53
 
43 54
 # clone git repositories onto the system
44 55
 # ======================================
45 56
 
46
-if [ ! -d cloned ]; then
47
-    rsync -azH primed/ cloned/
57
+if [ ! -d $CHROOTCACHE/natty-stack ]; then
58
+    rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
48 59
 fi
49 60
 
50 61
 # git clone only if directory doesn't exist already.  Since ``DEST`` might not
... ...
@@ -53,7 +64,7 @@ fi
53 53
 function git_clone {
54 54
 
55 55
     # clone new copy or fetch latest changes
56
-    CHECKOUT=cloned$2
56
+    CHECKOUT=$CHROOTCACHE/natty-stack$2
57 57
     if [ ! -d $CHECKOUT ]; then
58 58
         mkdir -p $CHECKOUT
59 59
         git clone $1 $CHECKOUT
... ...
@@ -73,19 +84,35 @@ function git_clone {
73 73
     popd
74 74
 
75 75
     # give ownership to the stack user
76
-    chroot cloned/ chown -R stack $2
76
+    chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
77 77
 }
78 78
 
79
-git_clone $NOVA_REPO /opt/stack/nova $NOVA_BRANCH
80
-git_clone $GLANCE_REPO /opt/stack/glance $GLANCE_BRANCH
81
-git_clone $KEYSTONE_REPO /opt/stack/keystone $KEYSTONE_BRANCH
82
-git_clone $NOVNC_REPO /opt/stack/novnc $NOVNC_BRANCH
83
-git_clone $DASH_REPO /opt/stack/dash $DASH_BRANCH
84
-git_clone $NOVACLIENT_REPO /opt/stack/python-novaclient $NOVACLIENT_BRANCH
85
-git_clone $OPENSTACKX_REPO /opt/stack/openstackx $OPENSTACKX_BRANCH
79
+git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
80
+git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
81
+git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
82
+git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
83
+git_clone $DASH_REPO $DEST/dash $DASH_BRANCH
84
+git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
85
+git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
86
+
87
+# Use this version of devstack?
88
+if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
89
+    rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack
90
+    cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack
91
+fi
92
+
93
+# Configure host network for DHCP
94
+mkdir -p $CHROOTCACHE/natty-stack/etc/network
95
+cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF
96
+auto lo
97
+iface lo inet loopback
98
+
99
+auto eth0
100
+iface eth0 inet dhcp
101
+EOF
86 102
 
87 103
 # build a new image
88
-BASE=build.$$
104
+BASE=$CHROOTCACHE/build.$$
89 105
 IMG=$BASE.img
90 106
 MNT=$BASE/
91 107
 
... ...
@@ -97,7 +124,7 @@ mkfs.ext2 -F $IMG
97 97
 # mount blank image loopback and load it
98 98
 mkdir -p $MNT
99 99
 mount -o loop $IMG $MNT
100
-rsync -azH cloned/ $MNT
100
+rsync -azH $CHROOTCACHE/natty-stack/ $MNT
101 101
 
102 102
 # umount and cleanup
103 103
 umount $MNT
... ...
@@ -144,7 +144,7 @@ dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE count=1
144 144
 if [ -n "$IMAGEONLY" ]; then
145 145
     # Build image from chroot
146 146
     sudo vmbuilder $HYPER ubuntu $ARGS \
147
-      --existing-chroot=$CHR \
147
+      --existing-chroot=$CHROOTDIR \
148 148
       --overwrite \
149 149
       --rootsize=$ROOTSIZE \
150 150
       --swapsize=$SWAPSIZE \