Browse code

enable testing of openvz guests

This patch adds several options to allow using OpenVZ virt layer.
- modifies stack.sh and stackrc to recognize a new VIRT_TYPE option
- set IMAGE_URLS to an openvz image, if VIRT_TYPE == openvz

It also makes a few changes to some tests so that some implicit
defaults (such as the guest user account) can be overridden.

Change-Id: I0dde2dffbf3848fac1dd27eb37af84c0ac73d9aa

Devananda van der Veen authored on 2012/07/07 09:49:12
Showing 6 changed files
... ...
@@ -46,6 +46,8 @@ DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
46 46
 # Default floating IP pool name
47 47
 DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
48 48
 
49
+# Default user
50
+DEFAULT_INSTANCE_USER=${DEFAULT_INSTANCE_USER:-cirros}
49 51
 
50 52
 # Launching servers
51 53
 # =================
... ...
@@ -150,7 +152,7 @@ fi
150 150
 # To do this, ssh to the builder instance, mount volume, and build a volume-backed image.
151 151
 STAGING_DIR=/tmp/stage
152 152
 CIRROS_DIR=/tmp/cirros
153
-ssh -o StrictHostKeyChecking=no -i $KEY_FILE cirros@$FLOATING_IP << EOF
153
+ssh -o StrictHostKeyChecking=no -i $KEY_FILE ${DEFAULT_INSTANCE_USER}@$FLOATING_IP << EOF
154 154
 set -o errexit
155 155
 set -o xtrace
156 156
 sudo mkdir -p $STAGING_DIR
... ...
@@ -168,10 +170,10 @@ if [ ! -e cirros-0.3.0-x86_64-rootfs.img.gz ]; then
168 168
 fi
169 169
 
170 170
 # Copy cirros onto the volume
171
-scp -o StrictHostKeyChecking=no -i $KEY_FILE cirros-0.3.0-x86_64-rootfs.img.gz cirros@$FLOATING_IP:$STAGING_DIR
171
+scp -o StrictHostKeyChecking=no -i $KEY_FILE cirros-0.3.0-x86_64-rootfs.img.gz ${DEFAULT_INSTANCE_USER}@$FLOATING_IP:$STAGING_DIR
172 172
 
173 173
 # Unpack cirros into volume
174
-ssh -o StrictHostKeyChecking=no -i $KEY_FILE cirros@$FLOATING_IP << EOF
174
+ssh -o StrictHostKeyChecking=no -i $KEY_FILE ${DEFAULT_INSTANCE_USER}@$FLOATING_IP << EOF
175 175
 set -o errexit
176 176
 set -o xtrace
177 177
 cd $STAGING_DIR
... ...
@@ -221,7 +223,7 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sle
221 221
 fi
222 222
 
223 223
 # Make sure our volume-backed instance launched
224
-ssh -o StrictHostKeyChecking=no -i $KEY_FILE cirros@$FLOATING_IP << EOF
224
+ssh -o StrictHostKeyChecking=no -i $KEY_FILE ${DEFAULT_INSTANCE_USER}@$FLOATING_IP << EOF
225 225
 echo "success!"
226 226
 EOF
227 227
 
... ...
@@ -40,12 +40,15 @@ source $TOP_DIR/exerciserc
40 40
 # Instance type to create
41 41
 DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
42 42
 
43
+# Boot this image, use first AMI-format image if unset
44
+DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
45
+
43 46
 
44 47
 # Launching a server
45 48
 # ==================
46 49
 
47 50
 # Find a machine image to boot
48
-IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
51
+IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
49 52
 
50 53
 # Define secgroup
51 54
 SECGROUP=euca_secgroup
... ...
@@ -185,7 +185,7 @@ fi
185 185
 nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 || die "Failure deleting security group rule from $SECGROUP"
186 186
 
187 187
 # FIXME (anthony): make xs support security groups
188
-if [ "$VIRT_DRIVER" != "xenserver" ]; then
188
+if [ "$VIRT_DRIVER" != "xenserver" -a "$VIRT_DRIVER" != "openvz" ]; then
189 189
     # test we can aren't able to ping our floating ip within ASSOCIATE_TIMEOUT seconds
190 190
     if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
191 191
         print "Security group failure - ping should not be allowed!"
... ...
@@ -276,12 +276,6 @@ VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
276 276
 VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
277 277
 INSTANCE_NAME_PREFIX=${INSTANCE_NAME_PREFIX:-instance-}
278 278
 
279
-# Nova hypervisor configuration.  We default to libvirt with **kvm** but will
280
-# drop back to **qemu** if we are unable to load the kvm module.  ``stack.sh`` can
281
-# also install an **LXC** based system.
282
-VIRT_DRIVER=${VIRT_DRIVER:-libvirt}
283
-LIBVIRT_TYPE=${LIBVIRT_TYPE:-kvm}
284
-
285 279
 # Nova supports pluggable schedulers.  ``FilterScheduler`` should work in most
286 280
 # cases.
287 281
 SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler}
... ...
@@ -1957,6 +1951,13 @@ if [ "$VIRT_DRIVER" = 'xenserver' ]; then
1957 1957
     # Need to avoid crash due to new firewall support
1958 1958
     XEN_FIREWALL_DRIVER=${XEN_FIREWALL_DRIVER:-"nova.virt.firewall.IptablesFirewallDriver"}
1959 1959
     add_nova_opt "firewall_driver=$XEN_FIREWALL_DRIVER"
1960
+elif [ "$VIRT_DRIVER" = 'openvz' ]; then
1961
+    # TODO(deva): OpenVZ driver does not yet work if compute_driver is set here.
1962
+    #             Replace connection_type when this is fixed.
1963
+    #             add_nova_opt "compute_driver=openvz.connection.OpenVzConnection"
1964
+    add_nova_opt "connection_type=openvz"
1965
+    LIBVIRT_FIREWALL_DRIVER=${LIBVIRT_FIREWALL_DRIVER:-"nova.virt.libvirt.firewall.IptablesFirewallDriver"}
1966
+    add_nova_opt "firewall_driver=$LIBVIRT_FIREWALL_DRIVER"
1960 1967
 else
1961 1968
     add_nova_opt "compute_driver=libvirt.LibvirtDriver"
1962 1969
     LIBVIRT_FIREWALL_DRIVER=${LIBVIRT_FIREWALL_DRIVER:-"nova.virt.libvirt.firewall.IptablesFirewallDriver"}
... ...
@@ -2212,6 +2213,14 @@ if is_service_enabled g-reg; then
2212 2212
             wget -c $image_url -O $FILES/$IMAGE_FNAME
2213 2213
         fi
2214 2214
 
2215
+        # OpenVZ-format images are provided as .tar.gz, but not decompressed prior to loading
2216
+        if [[ "$image_url" =~ 'openvz' ]]; then
2217
+            IMAGE="$FILES/${IMAGE_FNAME}"
2218
+            IMAGE_NAME="${IMAGE_FNAME%.tar.gz}"
2219
+            glance --os-auth-token $TOKEN --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --public --container-format ami --disk-format ami < "$IMAGE"
2220
+            continue
2221
+        fi
2222
+
2215 2223
         KERNEL=""
2216 2224
         RAMDISK=""
2217 2225
         DISK_FORMAT=""
... ...
@@ -99,6 +99,17 @@ MELANGE_BRANCH=master
99 99
 MELANGECLIENT_REPO=${GIT_BASE}/openstack/python-melangeclient.git
100 100
 MELANGECLIENT_BRANCH=master
101 101
 
102
+# Nova hypervisor configuration.  We default to libvirt with **kvm** but will
103
+# drop back to **qemu** if we are unable to load the kvm module.  ``stack.sh`` can
104
+# also install an **LXC** or **OpenVZ** based system.
105
+VIRT_DRIVER=${VIRT_DRIVER:-libvirt}
106
+LIBVIRT_TYPE=${LIBVIRT_TYPE:-kvm}
107
+
108
+# allow local overrides of env variables
109
+if [ -f $RC_DIR/localrc ]; then
110
+    source $RC_DIR/localrc
111
+fi
112
+
102 113
 # Specify a comma-separated list of uec images to download and install into glance.
103 114
 # supported urls here are:
104 115
 #  * "uec-style" images:
... ...
@@ -114,19 +125,27 @@ MELANGECLIENT_BRANCH=master
114 114
 #      http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-rootfs.img.gz
115 115
 #IMAGE_URLS="http://smoser.brickies.net/ubuntu/ttylinux-uec/ttylinux-uec-amd64-11.2_2.6.35-15_1.tar.gz" # old ttylinux-uec image
116 116
 #IMAGE_URLS="http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img" # cirros full disk image
117
-case "$LIBVIRT_TYPE" in
118
-    lxc) # the cirros root disk in the uec tarball is empty, so it will not work for lxc
119
-        DEFAULT_IMAGE_NAME=cirros-0.3.0-x86_64-rootfs
120
-        IMAGE_URLS="http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-rootfs.img.gz";;
121
-    *)  # otherwise, use the uec style image (with kernel, ramdisk, disk)
122
-        DEFAULT_IMAGE_NAME=cirros-0.3.0-x86_64-uec
123
-        IMAGE_URLS="http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-uec.tar.gz";;
117
+#
118
+# Set default image based on LIBVIRT_TYPE or VIRT_DRIVER, which may be set in localrc
119
+# but allow DEFAULT_IMAGE_NAME and IMAGE_URLS to be set directly in localrc, too.
120
+case "$VIRT_DRIVER" in
121
+    openvz) # OpenVZ uses its own format of image, and does not support uec style images
122
+        DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ubuntu-11.10-x86_64}
123
+        IMAGE_URLS=${IMAGE_URLS:-"http://download.openvz.org/template/precreated/ubuntu-11.10-x86_64.tar.gz"};;
124
+    libvirt)
125
+        case "$LIBVIRT_TYPE" in
126
+            lxc) # the cirros root disk in the uec tarball is empty, so it will not work for lxc
127
+                DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-0.3.0-x86_64-rootfs}
128
+                IMAGE_URLS=${IMAGE_URLS:-"http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-rootfs.img.gz"};;
129
+            *) # otherwise, use the uec style image (with kernel, ramdisk, disk)
130
+                DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-0.3.0-x86_64-uec}
131
+                IMAGE_URLS=${IMAGE_URLS:-"http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-uec.tar.gz"};;
132
+        esac
133
+        ;;
134
+    *) # otherwise, use the uec style image (with kernel, ramdisk, disk)
135
+        DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-0.3.0-x86_64-uec}
136
+        IMAGE_URLS=${IMAGE_URLS:-"http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-uec.tar.gz"};;
124 137
 esac
125 138
 
126
-# allow local overrides of env variables
127
-if [ -f $RC_DIR/localrc ]; then
128
-    source $RC_DIR/localrc
129
-fi
130
-
131 139
 # 5Gb default volume backing file size
132 140
 VOLUME_BACKING_FILE_SIZE=${VOLUME_BACKING_FILE_SIZE:-5130M}
... ...
@@ -67,15 +67,20 @@ fi
67 67
 # Glance should already contain images to be used in tempest
68 68
 # testing. Here we simply look for images stored in Glance
69 69
 # and set the appropriate variables for use in the tempest config
70
-# We ignore ramdisk and kernel images and set the IMAGE_UUID to
71
-# the first image returned and set IMAGE_UUID_ALT to the second,
70
+# We ignore ramdisk and kernel images, look for the default image
71
+# DEFAULT_IMAGE_NAME. If not found, we set the IMAGE_UUID to the
72
+# first image returned and set IMAGE_UUID_ALT to the second,
72 73
 # if there is more than one returned...
73 74
 # ... Also ensure we only take active images, so we don't get snapshots in process
74 75
 IMAGE_LINES=`glance image-list`
75 76
 IFS="$(echo -e "\n\r")"
76 77
 IMAGES=""
77 78
 for line in $IMAGE_LINES; do
78
-    IMAGES="$IMAGES `echo $line | grep -v "^\(ID\|+--\)" | grep -v "\(aki\|ari\)" | grep 'active' | cut -d' ' -f2`"
79
+    if [ -z $DEFAULT_IMAGE_NAME ]; then
80
+        IMAGES="$IMAGES `echo $line | grep -v "^\(ID\|+--\)" | grep -v "\(aki\|ari\)" | grep 'active' | cut -d' ' -f2`"
81
+    else
82
+        IMAGES="$IMAGES `echo $line | grep -v "^\(ID\|+--\)" | grep -v "\(aki\|ari\)" | grep 'active' | grep "$DEFAULT_IMAGE_NAME" | cut -d' ' -f2`"
83
+    fi
79 84
 done
80 85
 # Create array of image UUIDs...
81 86
 IFS=" "
... ...
@@ -127,9 +132,31 @@ ALT_USERNAME=${ALT_USERNAME:-alt_demo}
127 127
 ALT_TENANT_NAME=${ALT_TENANT_NAME:-alt_demo}
128 128
 ALT_PASSWORD=$OS_PASSWORD
129 129
 
130
-# TODO(jaypipes): Support configurable flavor refs here...
131
-FLAVOR_REF=1
132
-FLAVOR_REF_ALT=2
130
+# Check Nova for existing flavors and, if set, look for the
131
+# DEFAULT_INSTANCE_TYPE and use that. Otherwise, just use the first flavor.
132
+FLAVOR_LINES=`nova flavor-list`
133
+IFS="$(echo -e "\n\r")"
134
+FLAVORS=""
135
+for line in $FLAVOR_LINES; do
136
+    if [ -z $DEFAULT_INSTANCE_TYPE ]; then
137
+        FLAVORS="$FLAVORS `echo $line | grep -v "^\(ID\|+--\)" | cut -d' ' -f2`"
138
+    else
139
+        FLAVORS="$FLAVORS `echo $line | grep -v "^\(ID\|+--\)" | grep "$DEFAULT_INSTANCE_TYPE" | cut -d' ' -f2`"
140
+    fi
141
+done
142
+IFS=" "
143
+FLAVORS=($FLAVORS)
144
+NUM_FLAVORS=${#FLAVORS[*]}
145
+echo "Found $NUM_FLAVORS flavors"
146
+if [[ $NUM_FLAVORS -eq 0 ]]; then
147
+    echo "Found no valid flavors to use!"
148
+    exit 1
149
+fi
150
+FLAVOR_REF=${FLAVORS[0]}
151
+FLAVOR_REF_ALT=$FLAVOR_REF
152
+if [[ $NUM_FLAVORS -gt 1 ]]; then
153
+    FLAVOR_REF_ALT=${FLAVORS[1]}
154
+fi
133 155
 
134 156
 # Do any of the following need to be configurable?
135 157
 COMPUTE_CATALOG_TYPE=compute
... ...
@@ -141,7 +168,8 @@ COMPUTE_LOG_LEVEL=ERROR
141 141
 BUILD_INTERVAL=3
142 142
 BUILD_TIMEOUT=400
143 143
 RUN_SSH=True
144
-SSH_USER=$OS_USERNAME
144
+# Check for DEFAULT_INSTANCE_USER and try to connect with that account
145
+SSH_USER=${DEFAULT_INSTANCE_USER:-$OS_USERNAME}
145 146
 NETWORK_FOR_SSH=private
146 147
 IP_VERSION_FOR_SSH=4
147 148
 SSH_TIMEOUT=4