| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 1 | # lib/tempest | 
|  | 2 |  | 
|  | 3 | # Dependencies: | 
|  | 4 | # ``functions`` file | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 5 | # ``lib/nova`` service is runing | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 6 | # <list other global vars that are assumed to be defined> | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 7 | # - ``DEST`` | 
|  | 8 | # - ``ADMIN_PASSWORD`` | 
|  | 9 | # - ``DEFAULT_IMAGE_NAME`` | 
|  | 10 | # - ``S3_SERVICE_PORT`` | 
|  | 11 | # - ``SERVICE_HOST`` | 
|  | 12 | # - ``BASE_SQL_CONN`` ``lib/database`` declares | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 13 | # Optional Dependencies: | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 14 | # IDENTITY_USE_SSL, IDENTITY_HOST, IDENTITY_PORT, IDENTITY_PATH | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 15 | # ALT_* (similar vars exists in keystone_data.sh) | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 16 | # ``OS_USERNAME`` | 
|  | 17 | # ``IMAGE_PORT``, ``IMAGE_HOST`` | 
|  | 18 | # ``LIVE_MIGRATION_AVAILABLE`` | 
|  | 19 | # ``USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION`` | 
|  | 20 | # ``DEFAULT_INSTANCE_TYPE`` | 
|  | 21 | # ``DEFAULT_INSTANCE_USER`` | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 22 | # ``stack.sh`` calls the entry points in this order: | 
|  | 23 | # | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 24 | # install_tempest | 
|  | 25 | # configure_tempest | 
|  | 26 | # init_tempest | 
|  | 27 | ## start_tempest | 
|  | 28 | ## stop_tempest | 
|  | 29 | ## cleanup_tempest | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 30 |  | 
|  | 31 | # Save trace setting | 
|  | 32 | XTRACE=$(set +o | grep xtrace) | 
|  | 33 | set +o xtrace | 
|  | 34 |  | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 35 | # Defaults | 
|  | 36 | # -------- | 
|  | 37 |  | 
|  | 38 | # <define global variables here that belong to this project> | 
|  | 39 |  | 
|  | 40 | # Set up default directories | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 41 | NOVA_SOURCE_DIR=$DEST/nova | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 42 | TEMPEST_DIR=$DEST/tempest | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 43 | TEMPEST_CONF_DIR=$TEMPEST_DIR/etc | 
|  | 44 | TEMPEST_CONF=$TEMPEST_CONF_DIR/tempest.conf | 
|  | 45 |  | 
|  | 46 | BUILD_INTERVAL=3 | 
|  | 47 | BUILD_TIMEOUT=400 | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 48 |  | 
|  | 49 | # Entry Points | 
|  | 50 | # ------------ | 
|  | 51 |  | 
|  | 52 |  | 
|  | 53 | # configure_tempest() - Set config files, create data dirs, etc | 
|  | 54 | function configure_tempest() { | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 55 | local image_lines | 
|  | 56 | local images | 
|  | 57 | local num_images | 
|  | 58 | local image_uuid | 
|  | 59 | local image_uuid_alt | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 60 | local errexit | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 61 | local password | 
|  | 62 | local line | 
|  | 63 | local flavors | 
|  | 64 | local flavors_ref | 
|  | 65 | local flavor_lines | 
| Maru Newby | a5c774e | 2012-12-10 10:40:01 +0000 | [diff] [blame] | 66 | local public_network_id | 
|  | 67 | local tenant_networks_reachable | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 68 |  | 
|  | 69 | #TODO(afazekas): | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 70 | # sudo python setup.py deploy | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 71 |  | 
|  | 72 | # This function exits on an error so that errors don't compound and you see | 
|  | 73 | # only the first error that occured. | 
|  | 74 | errexit=$(set +o | grep errexit) | 
|  | 75 | set -o errexit | 
|  | 76 |  | 
|  | 77 | #Save IFS | 
|  | 78 | ifs=$IFS | 
|  | 79 |  | 
|  | 80 | # Glance should already contain images to be used in tempest | 
|  | 81 | # testing. Here we simply look for images stored in Glance | 
|  | 82 | # and set the appropriate variables for use in the tempest config | 
|  | 83 | # We ignore ramdisk and kernel images, look for the default image | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 84 | # ``DEFAULT_IMAGE_NAME``. If not found, we set the ``image_uuid`` to the | 
|  | 85 | # first image returned and set ``image_uuid_alt`` to the second, | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 86 | # if there is more than one returned... | 
|  | 87 | # ... Also ensure we only take active images, so we don't get snapshots in process | 
| Cody A.W. Somerville | c24e23b | 2012-12-21 02:10:45 -0500 | [diff] [blame^] | 88 | declare -a images | 
|  | 89 |  | 
|  | 90 | while read -r IMAGE_NAME IMAGE_UUID; do | 
|  | 91 | if [ "$IMAGE_NAME" = "$DEFAULT_IMAGE_NAME" ]; then | 
|  | 92 | image_uuid="$IMAGE_UUID" | 
|  | 93 | image_uuid_alt="$IMAGE_UUID" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 94 | fi | 
| Cody A.W. Somerville | c24e23b | 2012-12-21 02:10:45 -0500 | [diff] [blame^] | 95 | images+=($IMAGE_UUID) | 
|  | 96 | done < <(glance image-list --status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }') | 
|  | 97 |  | 
|  | 98 | case "${#images[*]}" in | 
|  | 99 | 0) | 
|  | 100 | echo "Found no valid images to use!" | 
|  | 101 | exit 1 | 
|  | 102 | ;; | 
|  | 103 | 1) | 
|  | 104 | if [ -z "$image_uuid" ]; then | 
|  | 105 | image_uuid=${images[0]} | 
|  | 106 | image_uuid_alt=${images[0]} | 
|  | 107 | fi | 
|  | 108 | ;; | 
|  | 109 | *) | 
|  | 110 | if [ -z "$image_uuid" ]; then | 
|  | 111 | image_uuid=${images[0]} | 
|  | 112 | image_uuid_alt=${images[1]} | 
|  | 113 | fi | 
|  | 114 | ;; | 
|  | 115 | esac | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 116 |  | 
|  | 117 | # Create tempest.conf from tempest.conf.sample | 
|  | 118 | # copy every time, because the image UUIDS are going to change | 
|  | 119 | cp $TEMPEST_CONF.sample $TEMPEST_CONF | 
|  | 120 |  | 
|  | 121 | IDENTITY_USE_SSL=${IDENTITY_USE_SSL:-False} | 
|  | 122 | IDENTITY_HOST=${IDENTITY_HOST:-127.0.0.1} | 
|  | 123 | IDENTITY_PORT=${IDENTITY_PORT:-5000} | 
|  | 124 | # TODO(jaypipes): This is dumb and needs to be removed | 
|  | 125 | # from the Tempest configuration file entirely... | 
|  | 126 | IDENTITY_PATH=${IDENTITY_PATH:-tokens} | 
|  | 127 |  | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 128 | password=${ADMIN_PASSWORD:-secrete} | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 129 |  | 
|  | 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 |  | 
|  | 135 | # Check Nova for existing flavors and, if set, look for the | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 136 | # ``DEFAULT_INSTANCE_TYPE`` and use that. Otherwise, just use the first flavor. | 
|  | 137 | flavor_lines=`nova flavor-list` | 
|  | 138 | IFS=$'\r\n' | 
|  | 139 | flavors="" | 
|  | 140 | for line in $flavor_lines; do | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 141 | if [ -z $DEFAULT_INSTANCE_TYPE ]; then | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 142 | flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | cut -d' ' -f2`" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 143 | else | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 144 | flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | grep "$DEFAULT_INSTANCE_TYPE" | cut -d' ' -f2`" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 145 | fi | 
|  | 146 | done | 
|  | 147 |  | 
|  | 148 | IFS=" " | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 149 | flavors=($flavors) | 
|  | 150 | num_flavors=${#flavors[*]} | 
|  | 151 | echo "Found $num_flavors flavors" | 
|  | 152 | if [[ $num_flavors -eq 0 ]]; then | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 153 | echo "Found no valid flavors to use!" | 
|  | 154 | exit 1 | 
|  | 155 | fi | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 156 | flavor_ref=${flavors[0]} | 
|  | 157 | flavor_ref_alt=$flavor_ref | 
|  | 158 | if [[ $num_flavors -gt 1 ]]; then | 
|  | 159 | flavor_ref_alt=${flavors[1]} | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 160 | fi | 
|  | 161 |  | 
| Maru Newby | a5c774e | 2012-12-10 10:40:01 +0000 | [diff] [blame] | 162 | if [ "$Q_USE_NAMESPACE" != "False" ]; then | 
|  | 163 | tenant_networks_reachable=false | 
|  | 164 | else | 
|  | 165 | tenant_networks_reachable=true | 
|  | 166 | fi | 
|  | 167 |  | 
|  | 168 | if is_service_enabled q-l3; then | 
|  | 169 | public_network_id=$(quantum net-list | grep $PUBLIC_NETWORK_NAME | \ | 
|  | 170 | awk '{print $2}') | 
|  | 171 | fi | 
|  | 172 |  | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 173 | # Timeouts | 
|  | 174 | iniset $TEMPEST_CONF compute build_timeout $BUILD_TIMEOUT | 
|  | 175 | iniset $TEMPEST_CONF volume build_timeout $BUILD_TIMEOUT | 
|  | 176 | iniset $TEMPEST_CONF boto build_timeout $BUILD_TIMEOUT | 
|  | 177 | iniset $TEMPEST_CONF compute build_interval $BUILD_INTERVAL | 
|  | 178 | iniset $TEMPEST_CONF volume build_interval $BUILD_INTERVAL | 
|  | 179 | iniset $TEMPEST_CONF boto build_interval $BUILD_INTERVAL | 
|  | 180 | iniset $TEMPEST_CONF boto http_socket_timeout 5 | 
|  | 181 |  | 
|  | 182 | iniset $TEMPEST_CONF identity use_ssl $IDENTITY_USE_SSL | 
|  | 183 | iniset $TEMPEST_CONF identity host $IDENTITY_HOST | 
|  | 184 | iniset $TEMPEST_CONF identity port $IDENTITY_PORT | 
|  | 185 | iniset $TEMPEST_CONF identity path $IDENTITY_PATH | 
|  | 186 |  | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 187 | iniset $TEMPEST_CONF compute password "$password" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 188 | iniset $TEMPEST_CONF compute alt_username $ALT_USERNAME | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 189 | iniset $TEMPEST_CONF compute alt_password "$password" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 190 | iniset $TEMPEST_CONF compute alt_tenant_name $ALT_TENANT_NAME | 
|  | 191 | iniset $TEMPEST_CONF compute resize_available False | 
|  | 192 | iniset $TEMPEST_CONF compute change_password_available False | 
|  | 193 | iniset $TEMPEST_CONF compute compute_log_level ERROR | 
|  | 194 | #Skip until #1074039 is fixed | 
|  | 195 | iniset $TEMPEST_CONF compute run_ssh False | 
|  | 196 | iniset $TEMPEST_CONF compute ssh_user ${DEFAULT_INSTANCE_USER:-$OS_USERNAME} | 
|  | 197 | iniset $TEMPEST_CONF compute network_for_ssh private | 
|  | 198 | iniset $TEMPEST_CONF compute ip_version_for_ssh 4 | 
|  | 199 | iniset $TEMPEST_CONF compute ssh_timeout 4 | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 200 | iniset $TEMPEST_CONF compute image_ref $image_uuid | 
|  | 201 | iniset $TEMPEST_CONF compute image_ref_alt $image_uuid_alt | 
|  | 202 | iniset $TEMPEST_CONF compute flavor_ref $flavor_ref | 
|  | 203 | iniset $TEMPEST_CONF compute flavor_ref_alt $flavor_ref_alt | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 204 | iniset $TEMPEST_CONF compute source_dir $NOVA_SOURCE_DIR | 
|  | 205 | iniset $TEMPEST_CONF compute live_migration_available ${LIVE_MIGRATION_AVAILABLE:-False} | 
|  | 206 | iniset $TEMPEST_CONF compute use_block_migration_for_live_migration	${USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION:-False} | 
|  | 207 | # Inherited behavior, might be wrong | 
|  | 208 | iniset $TEMPEST_CONF compute bin_dir $NOVA_BIN_DIR | 
|  | 209 | # TODO(jaypipes): Create the key file here... right now, no whitebox | 
|  | 210 | # tests actually use a key. | 
|  | 211 | iniset $TEMPEST_CONF compute path_to_private_key $TEMPEST_DIR/id_rsa | 
|  | 212 | iniset $TEMPEST_CONF compute db_uri $BASE_SQL_CONN/nova | 
|  | 213 |  | 
|  | 214 | # image | 
|  | 215 | iniset $TEMPEST_CONF image host ${IMAGE_HOST:-127.0.0.1} | 
|  | 216 | iniset $TEMPEST_CONF image port ${IMAGE_PORT:-9292} | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 217 | iniset $TEMPEST_CONF image password "$password" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 218 |  | 
|  | 219 | # identity-admin | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 220 | iniset $TEMPEST_CONF "identity-admin" password "$password" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 221 |  | 
|  | 222 | # compute admin | 
| Attila Fazekas | 65c0846 | 2012-12-07 14:20:51 +0100 | [diff] [blame] | 223 | iniset $TEMPEST_CONF "compute-admin" password "$password" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 224 |  | 
| Maru Newby | a5c774e | 2012-12-10 10:40:01 +0000 | [diff] [blame] | 225 | # network admin | 
|  | 226 | iniset $TEMPEST_CONF "network-admin" password "$password" | 
|  | 227 |  | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 228 | # network | 
|  | 229 | iniset $TEMPEST_CONF network api_version 2.0 | 
| Maru Newby | a5c774e | 2012-12-10 10:40:01 +0000 | [diff] [blame] | 230 | iniset $TEMPEST_CONF network password "$password" | 
|  | 231 | iniset $TEMPEST_CONF network tenant_networks_reachable "$tenant_networks_reachable" | 
|  | 232 | iniset $TEMPEST_CONF network public_network_id "$public_network_id" | 
| Attila Fazekas | 2aa3517 | 2012-12-05 20:03:40 +0100 | [diff] [blame] | 233 |  | 
|  | 234 | #boto | 
|  | 235 | iniset $TEMPEST_CONF boto ec2_url "http://$SERVICE_HOST:8773/services/Cloud" | 
|  | 236 | iniset $TEMPEST_CONF boto s3_url "http://$SERVICE_HOST:${S3_SERVICE_PORT:-3333}" | 
|  | 237 |  | 
|  | 238 | echo "Created tempest configuration file:" | 
|  | 239 | cat $TEMPEST_CONF | 
|  | 240 |  | 
|  | 241 | # Restore IFS | 
|  | 242 | IFS=$ifs | 
|  | 243 | #Restore errexit | 
|  | 244 | $errexit | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 245 | } | 
|  | 246 |  | 
|  | 247 |  | 
|  | 248 | # install_tempest() - Collect source and prepare | 
|  | 249 | function install_tempest() { | 
|  | 250 | git_clone $TEMPEST_REPO $TEMPEST_DIR $TEMPEST_BRANCH | 
| Jeremy Stanley | 9a352da | 2012-11-28 17:22:39 +0000 | [diff] [blame] | 251 |  | 
|  | 252 | # Tempest doesn't satisfy its dependencies on its own, so | 
|  | 253 | # install them here instead. | 
| jiajun xu | d75bc1f | 2012-12-04 08:51:35 +0800 | [diff] [blame] | 254 | pip_install -r $TEMPEST_DIR/tools/pip-requires | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 255 | } | 
|  | 256 |  | 
| Sean Dague | d093121 | 2012-10-04 16:06:44 -0400 | [diff] [blame] | 257 | # Restore xtrace | 
|  | 258 | $XTRACE |