blob: c08a4306987139cea923f87a408e0957007a6fe3 [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 Fazekas65c08462012-12-07 14:20:51 +01008# - ``DEST``
9# - ``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 Fazekas2aa35172012-12-05 20:03:40 +010019# Optional Dependencies:
Attila Fazekas65c08462012-12-07 14:20:51 +010020# IDENTITY_USE_SSL, IDENTITY_HOST, IDENTITY_PORT, IDENTITY_PATH
Attila Fazekas2aa35172012-12-05 20:03:40 +010021# ALT_* (similar vars exists in keystone_data.sh)
Attila Fazekas65c08462012-12-07 14:20:51 +010022# ``IMAGE_PORT``, ``IMAGE_HOST``
23# ``LIVE_MIGRATION_AVAILABLE``
24# ``USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION``
25# ``DEFAULT_INSTANCE_TYPE``
26# ``DEFAULT_INSTANCE_USER``
Sean Dagued0931212012-10-04 16:06:44 -040027# ``stack.sh`` calls the entry points in this order:
28#
Attila Fazekas2aa35172012-12-05 20:03:40 +010029# install_tempest
30# configure_tempest
Attila Fazekas1d29d8b2013-01-07 15:51:32 +010031# init_tempest
Sean Dagued0931212012-10-04 16:06:44 -040032
33# Save trace setting
34XTRACE=$(set +o | grep xtrace)
35set +o xtrace
36
Dean Troyer6d04fd72012-12-21 11:03:37 -060037
Sean Dagued0931212012-10-04 16:06:44 -040038# Defaults
39# --------
40
Sean Dagued0931212012-10-04 16:06:44 -040041# Set up default directories
42TEMPEST_DIR=$DEST/tempest
Attila Fazekas2aa35172012-12-05 20:03:40 +010043TEMPEST_CONF_DIR=$TEMPEST_DIR/etc
44TEMPEST_CONF=$TEMPEST_CONF_DIR/tempest.conf
45
Dean Troyer6d04fd72012-12-21 11:03:37 -060046NOVA_SOURCE_DIR=$DEST/nova
47
Attila Fazekas2aa35172012-12-05 20:03:40 +010048BUILD_INTERVAL=3
49BUILD_TIMEOUT=400
Sean Dagued0931212012-10-04 16:06:44 -040050
Dean Troyer6d04fd72012-12-21 11:03:37 -060051
Attila Fazekas1d29d8b2013-01-07 15:51:32 +010052BOTO_MATERIALS_PATH="$DEST/devstack/files/images/s3-materials/cirros-0.3.0"
53
Sean Dagued0931212012-10-04 16:06:44 -040054# Entry Points
55# ------------
56
Sean Dagued0931212012-10-04 16:06:44 -040057# configure_tempest() - Set config files, create data dirs, etc
58function configure_tempest() {
Attila Fazekas65c08462012-12-07 14:20:51 +010059 local image_lines
60 local images
61 local num_images
62 local image_uuid
63 local image_uuid_alt
Attila Fazekas2aa35172012-12-05 20:03:40 +010064 local errexit
Attila Fazekas65c08462012-12-07 14:20:51 +010065 local password
66 local line
67 local flavors
68 local flavors_ref
69 local flavor_lines
Maru Newbya5c774e2012-12-10 10:40:01 +000070 local public_network_id
Maru Newby31c94ab2012-12-19 03:59:20 +000071 local public_router_id
Maru Newbya5c774e2012-12-10 10:40:01 +000072 local tenant_networks_reachable
Attila Fazekas1d29d8b2013-01-07 15:51:32 +010073 local boto_instance_type="m1.tiny"
Attila Fazekas2aa35172012-12-05 20:03:40 +010074
Dean Troyer6d04fd72012-12-21 11:03:37 -060075 # TODO(afazekas):
Sean Dagued0931212012-10-04 16:06:44 -040076 # sudo python setup.py deploy
Attila Fazekas2aa35172012-12-05 20:03:40 +010077
78 # This function exits on an error so that errors don't compound and you see
79 # only the first error that occured.
80 errexit=$(set +o | grep errexit)
81 set -o errexit
82
Dean Troyer6d04fd72012-12-21 11:03:37 -060083 # Save IFS
Attila Fazekas2aa35172012-12-05 20:03:40 +010084 ifs=$IFS
85
86 # Glance should already contain images to be used in tempest
87 # testing. Here we simply look for images stored in Glance
88 # and set the appropriate variables for use in the tempest config
89 # We ignore ramdisk and kernel images, look for the default image
Attila Fazekas65c08462012-12-07 14:20:51 +010090 # ``DEFAULT_IMAGE_NAME``. If not found, we set the ``image_uuid`` to the
91 # first image returned and set ``image_uuid_alt`` to the second,
Attila Fazekas2aa35172012-12-05 20:03:40 +010092 # if there is more than one returned...
93 # ... Also ensure we only take active images, so we don't get snapshots in process
Cody A.W. Somervillec24e23b2012-12-21 02:10:45 -050094 declare -a images
95
96 while read -r IMAGE_NAME IMAGE_UUID; do
97 if [ "$IMAGE_NAME" = "$DEFAULT_IMAGE_NAME" ]; then
98 image_uuid="$IMAGE_UUID"
99 image_uuid_alt="$IMAGE_UUID"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100100 fi
Cody A.W. Somervillec24e23b2012-12-21 02:10:45 -0500101 images+=($IMAGE_UUID)
102 done < <(glance image-list --status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }')
103
104 case "${#images[*]}" in
105 0)
106 echo "Found no valid images to use!"
107 exit 1
108 ;;
109 1)
110 if [ -z "$image_uuid" ]; then
111 image_uuid=${images[0]}
112 image_uuid_alt=${images[0]}
113 fi
114 ;;
115 *)
116 if [ -z "$image_uuid" ]; then
117 image_uuid=${images[0]}
118 image_uuid_alt=${images[1]}
119 fi
120 ;;
121 esac
Attila Fazekas2aa35172012-12-05 20:03:40 +0100122
123 # Create tempest.conf from tempest.conf.sample
124 # copy every time, because the image UUIDS are going to change
125 cp $TEMPEST_CONF.sample $TEMPEST_CONF
126
127 IDENTITY_USE_SSL=${IDENTITY_USE_SSL:-False}
128 IDENTITY_HOST=${IDENTITY_HOST:-127.0.0.1}
129 IDENTITY_PORT=${IDENTITY_PORT:-5000}
130 # TODO(jaypipes): This is dumb and needs to be removed
131 # from the Tempest configuration file entirely...
132 IDENTITY_PATH=${IDENTITY_PATH:-tokens}
133
Attila Fazekas65c08462012-12-07 14:20:51 +0100134 password=${ADMIN_PASSWORD:-secrete}
Attila Fazekas2aa35172012-12-05 20:03:40 +0100135
136 # See files/keystone_data.sh where alt_demo user
137 # and tenant are set up...
138 ALT_USERNAME=${ALT_USERNAME:-alt_demo}
139 ALT_TENANT_NAME=${ALT_TENANT_NAME:-alt_demo}
140
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100141 # If the ``DEFAULT_INSTANCE_TYPE`` not declared, use the new behavior
142 # Tempest creates instane types for himself
143 if [[ -z "$DEFAULT_INSTANCE_TYPE" ]]; then
Attila Fazekas02c0bcc2013-01-14 19:10:17 +0100144 nova flavor-create m1.nano 42 64 0 1
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100145 flavor_ref=42
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100146 boto_instance_type=m1.nano
Attila Fazekas02c0bcc2013-01-14 19:10:17 +0100147 nova flavor-create m1.micro 84 128 0 1
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100148 flavor_ref_alt=84
149 else
150 # Check Nova for existing flavors and, if set, look for the
151 # ``DEFAULT_INSTANCE_TYPE`` and use that.
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100152 boto_instance_type=$DEFAULT_INSTANCE_TYPE
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100153 flavor_lines=`nova flavor-list`
154 IFS=$'\r\n'
155 flavors=""
Dean Troyerceaa38b2012-12-12 17:09:57 -0600156 for line in $flavor_lines; do
157 f=$(echo $line | awk "/ $DEFAULT_INSTANCE_TYPE / { print \$2 }")
158 flavors="$flavors $f"
159 done
Attila Fazekas2aa35172012-12-05 20:03:40 +0100160
Attila Fazekas7bf1dd32013-01-12 17:31:26 +0100161 for line in $flavor_lines; do
162 flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | cut -d' ' -f2`"
163 done
164
165 IFS=" "
166 flavors=($flavors)
167 num_flavors=${#flavors[*]}
168 echo "Found $num_flavors flavors"
169 if [[ $num_flavors -eq 0 ]]; then
170 echo "Found no valid flavors to use!"
171 exit 1
172 fi
173 flavor_ref=${flavors[0]}
174 flavor_ref_alt=$flavor_ref
175 if [[ $num_flavors -gt 1 ]]; then
176 flavor_ref_alt=${flavors[1]}
177 fi
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
206 iniset $TEMPEST_CONF identity use_ssl $IDENTITY_USE_SSL
207 iniset $TEMPEST_CONF identity host $IDENTITY_HOST
208 iniset $TEMPEST_CONF identity port $IDENTITY_PORT
209 iniset $TEMPEST_CONF identity path $IDENTITY_PATH
210
Attila Fazekas65c08462012-12-07 14:20:51 +0100211 iniset $TEMPEST_CONF compute password "$password"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100212 iniset $TEMPEST_CONF compute alt_username $ALT_USERNAME
Attila Fazekas65c08462012-12-07 14:20:51 +0100213 iniset $TEMPEST_CONF compute alt_password "$password"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100214 iniset $TEMPEST_CONF compute alt_tenant_name $ALT_TENANT_NAME
215 iniset $TEMPEST_CONF compute resize_available False
216 iniset $TEMPEST_CONF compute change_password_available False
217 iniset $TEMPEST_CONF compute compute_log_level ERROR
Nachi Ueno06fac372012-12-26 14:09:43 -0800218 # Note(nati) current tempest don't create network for each tenant
219 # so reuse same tenant for now
220 if is_service_enabled quantum; then
221 TEMPEST_ALLOW_TENANT_ISOLATION=${TEMPEST_ALLOW_TENANT_ISOLATION:-False}
222 fi
223 iniset $TEMPEST_CONF compute allow_tenant_isolation ${TEMPEST_ALLOW_TENANT_ISOLATION:-True}
Attila Fazekas2aa35172012-12-05 20:03:40 +0100224 #Skip until #1074039 is fixed
225 iniset $TEMPEST_CONF compute run_ssh False
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100226 iniset $TEMPEST_CONF compute ssh_user ${DEFAULT_INSTANCE_USER:-cirros}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900227 iniset $TEMPEST_CONF compute network_for_ssh $PRIVATE_NETWORK_NAME
Attila Fazekas2aa35172012-12-05 20:03:40 +0100228 iniset $TEMPEST_CONF compute ip_version_for_ssh 4
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100229 iniset $TEMPEST_CONF compute ssh_timeout $BUILD_TIMEOUT
Attila Fazekas65c08462012-12-07 14:20:51 +0100230 iniset $TEMPEST_CONF compute image_ref $image_uuid
231 iniset $TEMPEST_CONF compute image_ref_alt $image_uuid_alt
232 iniset $TEMPEST_CONF compute flavor_ref $flavor_ref
233 iniset $TEMPEST_CONF compute flavor_ref_alt $flavor_ref_alt
Attila Fazekas2aa35172012-12-05 20:03:40 +0100234 iniset $TEMPEST_CONF compute source_dir $NOVA_SOURCE_DIR
235 iniset $TEMPEST_CONF compute live_migration_available ${LIVE_MIGRATION_AVAILABLE:-False}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900236 iniset $TEMPEST_CONF compute use_block_migration_for_live_migration ${USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION:-False}
Attila Fazekas2aa35172012-12-05 20:03:40 +0100237 # Inherited behavior, might be wrong
238 iniset $TEMPEST_CONF compute bin_dir $NOVA_BIN_DIR
239 # TODO(jaypipes): Create the key file here... right now, no whitebox
240 # tests actually use a key.
241 iniset $TEMPEST_CONF compute path_to_private_key $TEMPEST_DIR/id_rsa
242 iniset $TEMPEST_CONF compute db_uri $BASE_SQL_CONN/nova
243
244 # image
245 iniset $TEMPEST_CONF image host ${IMAGE_HOST:-127.0.0.1}
246 iniset $TEMPEST_CONF image port ${IMAGE_PORT:-9292}
Attila Fazekas65c08462012-12-07 14:20:51 +0100247 iniset $TEMPEST_CONF image password "$password"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100248
249 # identity-admin
Attila Fazekas65c08462012-12-07 14:20:51 +0100250 iniset $TEMPEST_CONF "identity-admin" password "$password"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100251
252 # compute admin
Attila Fazekas65c08462012-12-07 14:20:51 +0100253 iniset $TEMPEST_CONF "compute-admin" password "$password"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100254
Maru Newbya5c774e2012-12-10 10:40:01 +0000255 # network admin
256 iniset $TEMPEST_CONF "network-admin" password "$password"
257
Attila Fazekas2aa35172012-12-05 20:03:40 +0100258 # network
259 iniset $TEMPEST_CONF network api_version 2.0
Maru Newbya5c774e2012-12-10 10:40:01 +0000260 iniset $TEMPEST_CONF network password "$password"
261 iniset $TEMPEST_CONF network tenant_networks_reachable "$tenant_networks_reachable"
262 iniset $TEMPEST_CONF network public_network_id "$public_network_id"
Maru Newby31c94ab2012-12-19 03:59:20 +0000263 iniset $TEMPEST_CONF network public_router_id "$public_router_id"
Attila Fazekas2aa35172012-12-05 20:03:40 +0100264
265 #boto
266 iniset $TEMPEST_CONF boto ec2_url "http://$SERVICE_HOST:8773/services/Cloud"
267 iniset $TEMPEST_CONF boto s3_url "http://$SERVICE_HOST:${S3_SERVICE_PORT:-3333}"
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100268 iniset $TEMPEST_CONF boto s3_materials_path "$BOTO_MATERIALS_PATH"
269 iniset $TEMPEST_CONF boto instance_type "$boto_instance_type"
270 iniset $TEMPEST_CONF boto http_socket_timeout 30
Attila Fazekas2aa35172012-12-05 20:03:40 +0100271
272 echo "Created tempest configuration file:"
273 cat $TEMPEST_CONF
274
275 # Restore IFS
276 IFS=$ifs
277 #Restore errexit
278 $errexit
Sean Dagued0931212012-10-04 16:06:44 -0400279}
280
Sean Dagued0931212012-10-04 16:06:44 -0400281# install_tempest() - Collect source and prepare
282function install_tempest() {
283 git_clone $TEMPEST_REPO $TEMPEST_DIR $TEMPEST_BRANCH
Jeremy Stanley9a352da2012-11-28 17:22:39 +0000284
285 # Tempest doesn't satisfy its dependencies on its own, so
286 # install them here instead.
jiajun xud75bc1f2012-12-04 08:51:35 +0800287 pip_install -r $TEMPEST_DIR/tools/pip-requires
Sean Dagued0931212012-10-04 16:06:44 -0400288}
289
Attila Fazekas1d29d8b2013-01-07 15:51:32 +0100290# init_tempest() - Initialize ec2 images
291function init_tempest() {
292 local base_image_name=cirros-0.3.0-x86_64
293 # /opt/stack/devstack/files/images/cirros-0.3.0-x86_64-uec
294 local devstack_dir="$DEST/devstack"
295 local image_dir="$devstack_dir/files/images/${base_image_name}-uec"
296 local kernel="$image_dir/${base_image_name}-vmlinuz"
297 local ramdisk="$image_dir/${base_image_name}-initrd"
298 local disk_image="$image_dir/${base_image_name}-blank.img"
299 # if the cirros uec downloaded and the system is uec capable
300 if [ -f "$kernel" -a -f "$ramdisk" -a -f "$disk_image" -a "$VIRT_DRIVER" != "openvz" \
301 -a \( "$LIBVIRT_TYPE" != "lxc" -o "$VIRT_DRIVER" != "libvirt" \) ]; then
302 echo "Prepare aki/ari/ami Images"
303 ( #new namespace
304 # tenant:demo ; user: demo
305 source $devstack_dir/accrc/demo/demo
306 euca-bundle-image -i "$kernel" --kernel true -d "$BOTO_MATERIALS_PATH"
307 euca-bundle-image -i "$ramdisk" --ramdisk true -d "$BOTO_MATERIALS_PATH"
308 euca-bundle-image -i "$disk_image" -d "$BOTO_MATERIALS_PATH"
309 ) 2>&1 </dev/null | cat
310 else
311 echo "Boto materials are not prepared"
312 fi
313}
314
Sean Dagued0931212012-10-04 16:06:44 -0400315# Restore xtrace
316$XTRACE