blob: 1a9cad2862fa7635f61107e3ec21f04fbe34017e [file] [log] [blame]
Sean Dagued0931212012-10-04 16:06:44 -04001# lib/tempest
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Install and configure Tempest
Sean Dagued0931212012-10-04 16:06:44 -04003
4# Dependencies:
5# ``functions`` file
Attila Fazekas2aa35172012-12-05 20:03:40 +01006# ``lib/nova`` service is runing
Sean Dagued0931212012-10-04 16:06:44 -04007# <list other global vars that are assumed to be defined>
Attila Fazekas3c529222013-01-21 06:50:33 +01008# - ``DEST``, ``FILES``
Attila Fazekas65c08462012-12-07 14:20:51 +01009# - ``ADMIN_PASSWORD``
10# - ``DEFAULT_IMAGE_NAME``
11# - ``S3_SERVICE_PORT``
12# - ``SERVICE_HOST``
13# - ``BASE_SQL_CONN`` ``lib/database`` declares
Maru Newby31c94ab2012-12-19 03:59:20 +000014# - ``PUBLIC_NETWORK_NAME``
15# - ``Q_USE_NAMESPACE``
16# - ``Q_ROUTER_NAME``
Attila Fazekas1d29d8b2013-01-07 15:51:32 +010017# - ``VIRT_DRIVER``
18# - ``LIBVIRT_TYPE``
Attila Fazekas97d3d202013-01-19 19:20:49 +010019# - ``KEYSTONE_SERVICE_PROTOCOL``, ``KEYSTONE_SERVICE_HOST`` from lib/keystone
Attila Fazekas2aa35172012-12-05 20:03:40 +010020# Optional Dependencies:
Attila Fazekas2aa35172012-12-05 20:03:40 +010021# ALT_* (similar vars exists in keystone_data.sh)
Attila Fazekas65c08462012-12-07 14:20:51 +010022# ``LIVE_MIGRATION_AVAILABLE``
23# ``USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION``
24# ``DEFAULT_INSTANCE_TYPE``
25# ``DEFAULT_INSTANCE_USER``
Sean Dagued0931212012-10-04 16:06:44 -040026# ``stack.sh`` calls the entry points in this order:
27#
Attila Fazekas2aa35172012-12-05 20:03:40 +010028# install_tempest
29# configure_tempest
Attila Fazekas1d29d8b2013-01-07 15:51:32 +010030# init_tempest
Sean Dagued0931212012-10-04 16:06:44 -040031
32# Save trace setting
33XTRACE=$(set +o | grep xtrace)
34set +o xtrace
35
Dean Troyer6d04fd72012-12-21 11:03:37 -060036
Sean Dagued0931212012-10-04 16:06:44 -040037# Defaults
38# --------
39
Sean Dagued0931212012-10-04 16:06:44 -040040# Set up default directories
41TEMPEST_DIR=$DEST/tempest
Attila Fazekas2aa35172012-12-05 20:03:40 +010042TEMPEST_CONF_DIR=$TEMPEST_DIR/etc
43TEMPEST_CONF=$TEMPEST_CONF_DIR/tempest.conf
44
Dean Troyer6d04fd72012-12-21 11:03:37 -060045NOVA_SOURCE_DIR=$DEST/nova
46
Attila Fazekas2aa35172012-12-05 20:03:40 +010047BUILD_INTERVAL=3
48BUILD_TIMEOUT=400
Sean Dagued0931212012-10-04 16:06:44 -040049
Dean Troyer6d04fd72012-12-21 11:03:37 -060050
Scott Mosercde655a2013-02-20 12:33:39 -050051BOTO_MATERIALS_PATH="$FILES/images/s3-materials/cirros-0.3.1"
Attila Fazekas1d29d8b2013-01-07 15:51:32 +010052
Dean Troyercc6b4432013-04-08 15:38:03 -050053
54# Functions
55# ---------
Sean Dagued0931212012-10-04 16:06:44 -040056
Sean Dagued0931212012-10-04 16:06:44 -040057# configure_tempest() - Set config files, create data dirs, etc
58function configure_tempest() {
Matthew Treinish95fb0d42013-01-28 16:24:14 -050059 setup_develop $TEMPEST_DIR
Attila Fazekas65c08462012-12-07 14:20:51 +010060 local image_lines
61 local images
62 local num_images
63 local image_uuid
64 local image_uuid_alt
Attila Fazekas2aa35172012-12-05 20:03:40 +010065 local errexit
Attila Fazekas65c08462012-12-07 14:20:51 +010066 local password
67 local line
68 local flavors
69 local flavors_ref
70 local flavor_lines
Maru Newbya5c774e2012-12-10 10:40:01 +000071 local public_network_id
Maru Newby31c94ab2012-12-19 03:59:20 +000072 local public_router_id
Maru Newbya5c774e2012-12-10 10:40:01 +000073 local tenant_networks_reachable
Attila Fazekas1d29d8b2013-01-07 15:51:32 +010074 local boto_instance_type="m1.tiny"
Attila Fazekas2aa35172012-12-05 20:03:40 +010075
Dean Troyer6d04fd72012-12-21 11:03:37 -060076 # TODO(afazekas):
Sean Dagued0931212012-10-04 16:06:44 -040077 # sudo python setup.py deploy
Attila Fazekas2aa35172012-12-05 20:03:40 +010078
79 # This function exits on an error so that errors don't compound and you see
80 # only the first error that occured.
81 errexit=$(set +o | grep errexit)
82 set -o errexit
83
Dean Troyer6d04fd72012-12-21 11:03:37 -060084 # Save IFS
Attila Fazekas2aa35172012-12-05 20:03:40 +010085 ifs=$IFS
86
87 # Glance should already contain images to be used in tempest
88 # testing. Here we simply look for images stored in Glance
89 # and set the appropriate variables for use in the tempest config
90 # We ignore ramdisk and kernel images, look for the default image
Attila Fazekas65c08462012-12-07 14:20:51 +010091 # ``DEFAULT_IMAGE_NAME``. If not found, we set the ``image_uuid`` to the
92 # first image returned and set ``image_uuid_alt`` to the second,
Attila Fazekas2aa35172012-12-05 20:03:40 +010093 # if there is more than one returned...
94 # ... Also ensure we only take active images, so we don't get snapshots in process
Cody A.W. Somervillec24e23b2012-12-21 02:10:45 -050095 declare -a images
96
97 while read -r IMAGE_NAME IMAGE_UUID; do
98 if [ "$IMAGE_NAME" = "$DEFAULT_IMAGE_NAME" ]; then
99 image_uuid="$IMAGE_UUID"
100 image_uuid_alt="$IMAGE_UUID"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100101 fi
Cody A.W. Somervillec24e23b2012-12-21 02:10:45 -0500102 images+=($IMAGE_UUID)
103 done < <(glance image-list --status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }')
104
105 case "${#images[*]}" in
106 0)
107 echo "Found no valid images to use!"
108 exit 1
109 ;;
110 1)
111 if [ -z "$image_uuid" ]; then
112 image_uuid=${images[0]}
113 image_uuid_alt=${images[0]}
114 fi
115 ;;
116 *)
117 if [ -z "$image_uuid" ]; then
118 image_uuid=${images[0]}
119 image_uuid_alt=${images[1]}
120 fi
121 ;;
122 esac
Attila Fazekas2aa35172012-12-05 20:03:40 +0100123
124 # Create tempest.conf from tempest.conf.sample
125 # copy every time, because the image UUIDS are going to change
126 cp $TEMPEST_CONF.sample $TEMPEST_CONF
127
Attila Fazekas65c08462012-12-07 14:20:51 +0100128 password=${ADMIN_PASSWORD:-secrete}
Attila Fazekas2aa35172012-12-05 20:03:40 +0100129
130 # See files/keystone_data.sh where alt_demo user
131 # and tenant are set up...
132 ALT_USERNAME=${ALT_USERNAME:-alt_demo}
133 ALT_TENANT_NAME=${ALT_TENANT_NAME:-alt_demo}
134
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100135 # If the ``DEFAULT_INSTANCE_TYPE`` not declared, use the new behavior
136 # Tempest creates instane types for himself
137 if [[ -z "$DEFAULT_INSTANCE_TYPE" ]]; then
Attila Fazekas02c0bcc2013-01-14 19:10:17 +0100138 nova flavor-create m1.nano 42 64 0 1
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100139 flavor_ref=42
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100140 boto_instance_type=m1.nano
Attila Fazekas02c0bcc2013-01-14 19:10:17 +0100141 nova flavor-create m1.micro 84 128 0 1
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100142 flavor_ref_alt=84
143 else
144 # Check Nova for existing flavors and, if set, look for the
145 # ``DEFAULT_INSTANCE_TYPE`` and use that.
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100146 boto_instance_type=$DEFAULT_INSTANCE_TYPE
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100147 flavor_lines=`nova flavor-list`
148 IFS=$'\r\n'
149 flavors=""
Dean Troyerceaa38b2012-12-12 17:09:57 -0600150 for line in $flavor_lines; do
151 f=$(echo $line | awk "/ $DEFAULT_INSTANCE_TYPE / { print \$2 }")
152 flavors="$flavors $f"
153 done
Attila Fazekas2aa35172012-12-05 20:03:40 +0100154
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100155 for line in $flavor_lines; do
156 flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | cut -d' ' -f2`"
157 done
158
159 IFS=" "
160 flavors=($flavors)
161 num_flavors=${#flavors[*]}
162 echo "Found $num_flavors flavors"
163 if [[ $num_flavors -eq 0 ]]; then
164 echo "Found no valid flavors to use!"
165 exit 1
166 fi
167 flavor_ref=${flavors[0]}
168 flavor_ref_alt=$flavor_ref
Adalberto Medeiros63a71a22013-06-06 08:46:04 -0400169
170 # ensure flavor_ref and flavor_ref_alt have different values
171 # some resize instance in tempest tests depends on this.
172 for f in ${flavors[@]:1}; do
173 if [[ $f -ne $flavor_ref ]]; then
174 flavor_ref_alt=$f
175 break
176 fi
177 done
Attila Fazekas2aa35172012-12-05 20:03:40 +0100178 fi
179
Maru Newbya5c774e2012-12-10 10:40:01 +0000180 if [ "$Q_USE_NAMESPACE" != "False" ]; then
181 tenant_networks_reachable=false
182 else
183 tenant_networks_reachable=true
184 fi
185
186 if is_service_enabled q-l3; then
187 public_network_id=$(quantum net-list | grep $PUBLIC_NETWORK_NAME | \
188 awk '{print $2}')
Maru Newby31c94ab2012-12-19 03:59:20 +0000189 if [ "$Q_USE_NAMESPACE" == "False" ]; then
190 # If namespaces are disabled, devstack will create a single
191 # public router that tempest should be configured to use.
192 public_router_id=$(quantum router-list | awk "/ $Q_ROUTER_NAME / \
193 { print \$2 }")
194 fi
Maru Newbya5c774e2012-12-10 10:40:01 +0000195 fi
196
Attila Fazekas2aa35172012-12-05 20:03:40 +0100197 # Timeouts
198 iniset $TEMPEST_CONF compute build_timeout $BUILD_TIMEOUT
199 iniset $TEMPEST_CONF volume build_timeout $BUILD_TIMEOUT
200 iniset $TEMPEST_CONF boto build_timeout $BUILD_TIMEOUT
201 iniset $TEMPEST_CONF compute build_interval $BUILD_INTERVAL
202 iniset $TEMPEST_CONF volume build_interval $BUILD_INTERVAL
203 iniset $TEMPEST_CONF boto build_interval $BUILD_INTERVAL
204 iniset $TEMPEST_CONF boto http_socket_timeout 5
205
Attila Fazekas97d3d202013-01-19 19:20:49 +0100206 # Identity
207 iniset $TEMPEST_CONF identity uri "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:5000/v2.0/"
208 iniset $TEMPEST_CONF identity password "$password"
209 iniset $TEMPEST_CONF identity alt_username $ALT_USERNAME
210 iniset $TEMPEST_CONF identity alt_password "$password"
211 iniset $TEMPEST_CONF identity alt_tenant_name $ALT_TENANT_NAME
212 iniset $TEMPEST_CONF identity admin_password "$password"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100213
Attila Fazekas97d3d202013-01-19 19:20:49 +0100214 # Compute
Attila Fazekas2aa35172012-12-05 20:03:40 +0100215 iniset $TEMPEST_CONF compute change_password_available False
Nachi Ueno06fac372012-12-26 14:09:43 -0800216 # Note(nati) current tempest don't create network for each tenant
217 # so reuse same tenant for now
218 if is_service_enabled quantum; then
219 TEMPEST_ALLOW_TENANT_ISOLATION=${TEMPEST_ALLOW_TENANT_ISOLATION:-False}
220 fi
221 iniset $TEMPEST_CONF compute allow_tenant_isolation ${TEMPEST_ALLOW_TENANT_ISOLATION:-True}
Attila Fazekas97d3d202013-01-19 19:20:49 +0100222 iniset $TEMPEST_CONF compute ssh_user ${DEFAULT_INSTANCE_USER:-cirros} # DEPRECATED
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900223 iniset $TEMPEST_CONF compute network_for_ssh $PRIVATE_NETWORK_NAME
Attila Fazekas2aa35172012-12-05 20:03:40 +0100224 iniset $TEMPEST_CONF compute ip_version_for_ssh 4
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100225 iniset $TEMPEST_CONF compute ssh_timeout $BUILD_TIMEOUT
Attila Fazekas65c08462012-12-07 14:20:51 +0100226 iniset $TEMPEST_CONF compute image_ref $image_uuid
Attila Fazekas97d3d202013-01-19 19:20:49 +0100227 iniset $TEMPEST_CONF compute image_ssh_user ${DEFAULT_INSTANCE_USER:-cirros}
Attila Fazekas65c08462012-12-07 14:20:51 +0100228 iniset $TEMPEST_CONF compute image_ref_alt $image_uuid_alt
Attila Fazekas97d3d202013-01-19 19:20:49 +0100229 iniset $TEMPEST_CONF compute image_alt_ssh_user ${DEFAULT_INSTANCE_USER:-cirros}
Attila Fazekas65c08462012-12-07 14:20:51 +0100230 iniset $TEMPEST_CONF compute flavor_ref $flavor_ref
231 iniset $TEMPEST_CONF compute flavor_ref_alt $flavor_ref_alt
Attila Fazekas2aa35172012-12-05 20:03:40 +0100232 iniset $TEMPEST_CONF compute live_migration_available ${LIVE_MIGRATION_AVAILABLE:-False}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900233 iniset $TEMPEST_CONF compute use_block_migration_for_live_migration ${USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION:-False}
Attila Fazekas97d3d202013-01-19 19:20:49 +0100234
235 # Whitebox
236 iniset $TEMPEST_CONF whitebox source_dir $NOVA_SOURCE_DIR
237 iniset $TEMPEST_CONF whitebox bin_dir $NOVA_BIN_DIR
Attila Fazekas2aa35172012-12-05 20:03:40 +0100238 # TODO(jaypipes): Create the key file here... right now, no whitebox
239 # tests actually use a key.
Attila Fazekas97d3d202013-01-19 19:20:49 +0100240 iniset $TEMPEST_CONF whitebox path_to_private_key $TEMPEST_DIR/id_rsa
241 iniset $TEMPEST_CONF whitebox db_uri $BASE_SQL_CONN/nova
242
Attila Fazekas2aa35172012-12-05 20:03:40 +0100243
Attila Fazekas2aa35172012-12-05 20:03:40 +0100244 # compute admin
Attila Fazekas97d3d202013-01-19 19:20:49 +0100245 iniset $TEMPEST_CONF "compute-admin" password "$password" # DEPRECATED
Attila Fazekas2aa35172012-12-05 20:03:40 +0100246
247 # network
Sean Dague4a20f9a2013-03-01 07:23:38 -0500248 if is_service_enabled quantum; then
249 iniset $TEMPEST_CONF network quantum_available "True"
250 fi
Attila Fazekas2aa35172012-12-05 20:03:40 +0100251 iniset $TEMPEST_CONF network api_version 2.0
Maru Newbya5c774e2012-12-10 10:40:01 +0000252 iniset $TEMPEST_CONF network tenant_networks_reachable "$tenant_networks_reachable"
253 iniset $TEMPEST_CONF network public_network_id "$public_network_id"
Maru Newby31c94ab2012-12-19 03:59:20 +0000254 iniset $TEMPEST_CONF network public_router_id "$public_router_id"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100255
256 #boto
257 iniset $TEMPEST_CONF boto ec2_url "http://$SERVICE_HOST:8773/services/Cloud"
258 iniset $TEMPEST_CONF boto s3_url "http://$SERVICE_HOST:${S3_SERVICE_PORT:-3333}"
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100259 iniset $TEMPEST_CONF boto s3_materials_path "$BOTO_MATERIALS_PATH"
260 iniset $TEMPEST_CONF boto instance_type "$boto_instance_type"
261 iniset $TEMPEST_CONF boto http_socket_timeout 30
Attila Fazekas97d3d202013-01-19 19:20:49 +0100262 iniset $TEMPEST_CONF boto ssh_user ${DEFAULT_INSTANCE_USER:-cirros}
Attila Fazekas2aa35172012-12-05 20:03:40 +0100263
264 echo "Created tempest configuration file:"
265 cat $TEMPEST_CONF
266
267 # Restore IFS
268 IFS=$ifs
269 #Restore errexit
270 $errexit
Sean Dagued0931212012-10-04 16:06:44 -0400271}
272
Sean Dagued0931212012-10-04 16:06:44 -0400273# install_tempest() - Collect source and prepare
274function install_tempest() {
275 git_clone $TEMPEST_REPO $TEMPEST_DIR $TEMPEST_BRANCH
Sean Dagued0931212012-10-04 16:06:44 -0400276}
277
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100278# init_tempest() - Initialize ec2 images
279function init_tempest() {
Scott Mosercde655a2013-02-20 12:33:39 -0500280 local base_image_name=cirros-0.3.1-x86_64
281 # /opt/stack/devstack/files/images/cirros-0.3.1-x86_64-uec
Attila Fazekas3c529222013-01-21 06:50:33 +0100282 local image_dir="$FILES/images/${base_image_name}-uec"
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100283 local kernel="$image_dir/${base_image_name}-vmlinuz"
284 local ramdisk="$image_dir/${base_image_name}-initrd"
285 local disk_image="$image_dir/${base_image_name}-blank.img"
286 # if the cirros uec downloaded and the system is uec capable
287 if [ -f "$kernel" -a -f "$ramdisk" -a -f "$disk_image" -a "$VIRT_DRIVER" != "openvz" \
288 -a \( "$LIBVIRT_TYPE" != "lxc" -o "$VIRT_DRIVER" != "libvirt" \) ]; then
289 echo "Prepare aki/ari/ami Images"
290 ( #new namespace
291 # tenant:demo ; user: demo
Chris Yeohb0b98b72013-01-23 21:14:49 +1030292 source $TOP_DIR/accrc/demo/demo
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100293 euca-bundle-image -i "$kernel" --kernel true -d "$BOTO_MATERIALS_PATH"
294 euca-bundle-image -i "$ramdisk" --ramdisk true -d "$BOTO_MATERIALS_PATH"
295 euca-bundle-image -i "$disk_image" -d "$BOTO_MATERIALS_PATH"
296 ) 2>&1 </dev/null | cat
297 else
298 echo "Boto materials are not prepared"
299 fi
300}
301
Sean Dagued0931212012-10-04 16:06:44 -0400302# Restore xtrace
303$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400304
305# Local variables:
306# mode: shell-script
307# End: