Browse code

Merge branch 'master' of github.com:cloudbuilders/devstack

Jesse Andrews authored on 2011/10/27 00:51:59
Showing 5 changed files
... ...
@@ -93,7 +93,7 @@ IP=`nova show $NAME | grep "private network" | cut -d"|" -f3`
93 93
 
94 94
 # for single node deployments, we can ping private ips
95 95
 MULTI_HOST=${MULTI_HOST:-0}
96
-if [ "$MULTI_HOST" = "0"]; then
96
+if [ "$MULTI_HOST" = "0" ]; then
97 97
     # ping it once (timeout of a second)
98 98
     ping -c1 -w1 $IP || true
99 99
 
... ...
@@ -302,20 +302,31 @@ sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $FILES/pips/*`
302 302
 # be owned by the installation user, we create the directory and change the
303 303
 # ownership to the proper user.
304 304
 function git_clone {
305
-    # if there is an existing checkout, move it out of the way
306
-    if [[ "$RECLONE" == "yes" ]]; then
307
-        # FIXME(ja): if we were smarter we could speed up RECLONE by
308
-        # using the old git repo as the basis of our new clone...
309
-        if [ -d $2 ]; then
310
-            mv $2 /tmp/stack.`date +%s`
311
-        fi
312
-    fi
313 305
 
314
-    if [ ! -d $2 ]; then
315
-        git clone $1 $2
306
+    GIT_REMOTE=$1
307
+    GIT_DEST=$2
308
+    GIT_BRANCH=$3
309
+
310
+    # do a full clone only if the directory doesn't exist
311
+    if [ ! -d $GIT_DEST ]; then
312
+        git clone $GIT_REMOTE $GIT_DEST
316 313
         cd $2
317 314
         # This checkout syntax works for both branches and tags
318
-        git checkout $3
315
+        git checkout $GIT_BRANCH
316
+    elif [[ "$RECLONE" == "yes" ]]; then
317
+        # if it does exist then simulate what clone does if asked to RECLONE
318
+        cd $GIT_DEST
319
+        # set the url to pull from and fetch
320
+        git remote set-url origin $GIT_REMOTE
321
+        git fetch origin
322
+        # remove the existing ignored files (like pyc) as they cause breakage
323
+        # (due to the py files having older timestamps than our pyc, so python
324
+        # thinks the pyc files are correct using them)
325
+        sudo git clean -f -d
326
+        git checkout -f origin/$GIT_BRANCH
327
+        # a local branch might not exist
328
+        git branch -D $GIT_BRANCH || true
329
+        git checkout -b $GIT_BRANCH
319 330
     fi
320 331
 }
321 332
 
... ...
@@ -470,11 +481,15 @@ fi
470 470
 # Nova
471 471
 # ----
472 472
 
473
-# We are going to use the sample http middleware configuration from the keystone
474
-# project to launch nova.  This paste config adds the configuration required
475
-# for nova to validate keystone tokens - except we need to switch the config
476
-# to use our service token instead (instead of the invalid token 999888777666).
477
-sudo sed -e "s,999888777666,$SERVICE_TOKEN,g" -i $KEYSTONE_DIR/examples/paste/nova-api-paste.ini
473
+if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
474
+    # We are going to use the sample http middleware configuration from the
475
+    # keystone project to launch nova.  This paste config adds the configuration
476
+    # required for nova to validate keystone tokens - except we need to switch
477
+    # the config to use our service token instead (instead of the invalid token
478
+    # 999888777666).
479
+    cp $KEYSTONE_DIR/examples/paste/nova-api-paste.ini $NOVA_DIR/bin
480
+    sed -e "s,999888777666,$SERVICE_TOKEN,g" -i $NOVA_DIR/bin/nova-api-paste.ini
481
+fi
478 482
 
479 483
 if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
480 484
 
... ...
@@ -591,7 +606,7 @@ add_nova_flag "--libvirt_type=$LIBVIRT_TYPE"
591 591
 add_nova_flag "--osapi_extensions_path=$OPENSTACKX_DIR/extensions"
592 592
 add_nova_flag "--vncproxy_url=http://$HOST_IP:6080"
593 593
 add_nova_flag "--vncproxy_wwwroot=$NOVNC_DIR/"
594
-add_nova_flag "--api_paste_config=$KEYSTONE_DIR/examples/paste/nova-api-paste.ini"
594
+add_nova_flag "--api_paste_config=$NOVA_DIR/bin/nova-api-paste.ini"
595 595
 add_nova_flag "--image_service=nova.image.glance.GlanceImageService"
596 596
 add_nova_flag "--ec2_dmz_host=$EC2_DMZ_HOST"
597 597
 add_nova_flag "--rabbit_host=$RABBIT_HOST"
... ...
@@ -285,6 +285,15 @@ if [ "$COPYENV" = "1" ]; then
285 285
     cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc
286 286
 fi
287 287
 
288
+# pre-cache uec images
289
+for image_url in ${IMAGE_URLS//,/ }; do
290
+    IMAGE_FNAME=`basename "$image_url"`
291
+    if [ ! -f $IMAGES_DIR/$IMAGE_FNAME ]; then
292
+        wget -c $image_url -O $IMAGES_DIR/$IMAGE_FNAME
293
+    fi
294
+    cp $IMAGES_DIR/$IMAGE_FNAME $ROOTFS/$DEST/devstack/files
295
+done
296
+
288 297
 # Configure the runner
289 298
 RUN_SH=$ROOTFS/$DEST/run.sh
290 299
 cat > $RUN_SH <<EOF
291 300
new file mode 100755
... ...
@@ -0,0 +1,159 @@
0
+#!/bin/bash
1
+# get_uec_image.sh - Prepare Ubuntu images in various formats
2
+#
3
+# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc), raw
4
+#
5
+# Required to run as root
6
+
7
+CACHEDIR=${CACHEDIR:-/var/cache/devstack}
8
+FORMAT=${FORMAT:-qcow2}
9
+ROOTSIZE=${ROOTSIZE:-2000}
10
+MIN_PKGS=${MIN_PKGS:-"apt-utils gpgv openssh-server"}
11
+
12
+usage() {
13
+    echo "Usage: $0 - Prepare Ubuntu images"
14
+    echo ""
15
+    echo "$0 [-f format] [-r rootsize] release imagefile"
16
+    echo ""
17
+    echo "-f format - image format: qcow2 (default), vmdk, vdi, vhd, xen, raw, fs"
18
+    echo "-r size   - root fs size in MB (min 2000MB)"
19
+    echo "release   - Ubuntu release: jaunty - oneric"
20
+    echo "imagefile - output image file"
21
+    exit 1
22
+}
23
+
24
+while getopts f:hmr: c; do
25
+    case $c in
26
+        f)  FORMAT=$OPTARG
27
+            ;;
28
+        h)  usage
29
+            ;;
30
+        m)  MINIMAL=1
31
+            ;;
32
+        r)  ROOTSIZE=$OPTARG
33
+            if $(( ROOTSIZE < 2000 )); then
34
+                echo "root size must be greater than 2000MB"
35
+                exit 1
36
+            fi
37
+            ;;
38
+    esac
39
+done
40
+shift `expr $OPTIND - 1`
41
+
42
+if [ ! "$#" -eq "2" ]; then
43
+    usage
44
+fi
45
+
46
+# Default args
47
+DIST_NAME=$1
48
+IMG_FILE=$2
49
+
50
+case $FORMAT in
51
+    kvm|qcow2)  FORMAT=qcow2
52
+                QFORMAT=qcow2
53
+                ;;
54
+    vmserver|vmdk)
55
+                FORMAT=vmdk
56
+                QFORMAT=vmdk
57
+                ;;
58
+    vbox|vdi)   FORMAT=vdi
59
+                QFORMAT=vdi
60
+                ;;
61
+    vhd|vpc)    FORMAT=vhd
62
+                QFORMAT=vpc
63
+                ;;
64
+    xen)        FORMAT=raw
65
+                QFORMAT=raw
66
+                ;;
67
+    raw)        FORMAT=raw
68
+                QFORMAT=raw
69
+                ;;
70
+    *)          echo "Unknown format: $FORMAT"
71
+                usage
72
+esac
73
+
74
+case $DIST_NAME in
75
+    oneiric)    ;;
76
+    natty)      ;;
77
+    maverick)   ;;
78
+    lucid)      ;;
79
+    karmic)     ;;
80
+    jaunty)     ;;
81
+    *)          echo "Unknown release: $DIST_NAME"
82
+                usage
83
+                ;;
84
+esac
85
+
86
+# Set up nbd
87
+modprobe nbd max_part=63
88
+NBD=${NBD:-/dev/nbd9}
89
+NBD_DEV=`basename $NBD`
90
+
91
+# Prepare the base image
92
+
93
+# Get the UEC image
94
+UEC_NAME=$DIST_NAME-server-cloudimg-amd64
95
+if [ ! -e $CACHEDIR/$UEC_NAME-disk1.img ]; then
96
+    (cd $CACHEDIR; wget -N http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME-disk1.img)
97
+
98
+
99
+    # Connect to nbd and wait till it is ready
100
+    qemu-nbd -d $NBD
101
+    qemu-nbd -c $NBD $CACHEDIR/$UEC_NAME-disk1.img
102
+    if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
103
+        echo "Couldn't connect $NBD"
104
+        exit 1
105
+    fi
106
+    MNTDIR=`mktemp -d mntXXXXXXXX`
107
+    mount -t ext4 ${NBD}p1 $MNTDIR
108
+
109
+    # Install our required packages
110
+    cp -p files/sources.list $MNTDIR/etc/apt/sources.list
111
+    cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
112
+    chroot $MNTDIR apt-get update
113
+    chroot $MNTDIR apt-get install -y $MIN_PKGS
114
+    rm -f $MNTDIR/etc/resolv.conf
115
+
116
+    umount $MNTDIR
117
+    rmdir $MNTDIR
118
+    qemu-nbd -d $NBD
119
+fi
120
+
121
+if [ "$FORMAT" = "qcow2" ]; then
122
+    # Just copy image
123
+    cp -p $CACHEDIR/$UEC_NAME-disk1.img $IMG_FILE
124
+else
125
+    # Convert image
126
+    qemu-img convert -O $QFORMAT $CACHEDIR/$UEC_NAME-disk1.img $IMG_FILE
127
+fi
128
+
129
+# Resize the image if necessary
130
+if [ $ROOTSIZE -gt 2000 ]; then
131
+    # Resize the container
132
+    qemu-img resize $IMG_FILE +$((ROOTSIZE - 2000))M
133
+
134
+    # Connect to nbd and wait till it is ready
135
+    qemu-nbd -c $NBD $IMG_FILE
136
+    if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
137
+        echo "Couldn't connect $NBD"
138
+        exit 1
139
+    fi
140
+
141
+    # Resize partition 1 to full size of the disk image
142
+    echo "d
143
+n
144
+p
145
+1
146
+2
147
+
148
+t
149
+83
150
+a
151
+1
152
+w
153
+" | fdisk $NBD
154
+    fsck -t ext4 -f ${NBD}p1
155
+    resize2fs ${NBD}p1
156
+
157
+    qemu-nbd -d $NBD
158
+fi
... ...
@@ -65,6 +65,13 @@ if [ -n "$IMAGEONLY" ]; then
65 65
     RELEASE="pass"
66 66
 fi
67 67
 
68
+# Make sure that we have the proper version of ubuntu
69
+UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
70
+if [ "$UBUNTU_VERSION" = "natty" -a "$RELEASE" = "oneiric" ]; then
71
+    echo "natty installs can't build oneiric images"
72
+    exit 1
73
+fi
74
+
68 75
 case $FORMAT in
69 76
     kvm|qcow2)  FORMAT=qcow2
70 77
                 QFORMAT=qcow2