lib/tempest
d093121f
 # lib/tempest
6d04fd7b
 # Install and configure Tempest
d093121f
 
 # Dependencies:
 # ``functions`` file
2aa35174
 # ``lib/nova`` service is runing
d093121f
 # <list other global vars that are assumed to be defined>
3c52922f
 # - ``DEST``, ``FILES``
65c0846e
 # - ``ADMIN_PASSWORD``
 # - ``DEFAULT_IMAGE_NAME``
 # - ``S3_SERVICE_PORT``
 # - ``SERVICE_HOST``
 # - ``BASE_SQL_CONN`` ``lib/database`` declares
31c94ab5
 # - ``PUBLIC_NETWORK_NAME``
 # - ``Q_USE_NAMESPACE``
 # - ``Q_ROUTER_NAME``
1d29d8bc
 # - ``VIRT_DRIVER``
 # - ``LIBVIRT_TYPE``
97d3d202
 # - ``KEYSTONE_SERVICE_PROTOCOL``, ``KEYSTONE_SERVICE_HOST`` from lib/keystone
2aa35174
 # Optional Dependencies:
 # ALT_* (similar vars exists in keystone_data.sh)
65c0846e
 # ``LIVE_MIGRATION_AVAILABLE``
 # ``USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION``
 # ``DEFAULT_INSTANCE_TYPE``
 # ``DEFAULT_INSTANCE_USER``
d093121f
 # ``stack.sh`` calls the entry points in this order:
 #
2aa35174
 # install_tempest
 # configure_tempest
1d29d8bc
 # init_tempest
d093121f
 
 # Save trace setting
 XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
6d04fd7b
 
d093121f
 # Defaults
 # --------
 
 # Set up default directories
 TEMPEST_DIR=$DEST/tempest
2aa35174
 TEMPEST_CONF_DIR=$TEMPEST_DIR/etc
 TEMPEST_CONF=$TEMPEST_CONF_DIR/tempest.conf
 
6d04fd7b
 NOVA_SOURCE_DIR=$DEST/nova
 
2aa35174
 BUILD_INTERVAL=3
 BUILD_TIMEOUT=400
d093121f
 
6d04fd7b
 
cde655ac
 BOTO_MATERIALS_PATH="$FILES/images/s3-materials/cirros-0.3.1"
1d29d8bc
 
cc6b4435
 
 # Functions
 # ---------
d093121f
 
 # configure_tempest() - Set config files, create data dirs, etc
 function configure_tempest() {
95fb0d44
     setup_develop $TEMPEST_DIR
65c0846e
     local image_lines
     local images
     local num_images
     local image_uuid
     local image_uuid_alt
2aa35174
     local errexit
65c0846e
     local password
     local line
     local flavors
     local flavors_ref
     local flavor_lines
a5c774ea
     local public_network_id
31c94ab5
     local public_router_id
a5c774ea
     local tenant_networks_reachable
1d29d8bc
     local boto_instance_type="m1.tiny"
2aa35174
 
6d04fd7b
     # TODO(afazekas):
d093121f
     # sudo python setup.py deploy
2aa35174
 
     # This function exits on an error so that errors don't compound and you see
     # only the first error that occured.
     errexit=$(set +o | grep errexit)
     set -o errexit
 
6d04fd7b
     # Save IFS
2aa35174
     ifs=$IFS
 
     # Glance should already contain images to be used in tempest
     # testing. Here we simply look for images stored in Glance
     # and set the appropriate variables for use in the tempest config
     # We ignore ramdisk and kernel images, look for the default image
65c0846e
     # ``DEFAULT_IMAGE_NAME``. If not found, we set the ``image_uuid`` to the
     # first image returned and set ``image_uuid_alt`` to the second,
2aa35174
     # if there is more than one returned...
     # ... Also ensure we only take active images, so we don't get snapshots in process
c24e23b4
     declare -a images
 
     while read -r IMAGE_NAME IMAGE_UUID; do
         if [ "$IMAGE_NAME" = "$DEFAULT_IMAGE_NAME" ]; then
             image_uuid="$IMAGE_UUID"
             image_uuid_alt="$IMAGE_UUID"
2aa35174
         fi
c24e23b4
         images+=($IMAGE_UUID)
     done < <(glance image-list --status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }')
 
     case "${#images[*]}" in
         0)
             echo "Found no valid images to use!"
             exit 1
             ;;
         1)
             if [ -z "$image_uuid" ]; then
                 image_uuid=${images[0]}
                 image_uuid_alt=${images[0]}
             fi
             ;;
         *)
             if [ -z "$image_uuid" ]; then
                 image_uuid=${images[0]}
                 image_uuid_alt=${images[1]}
             fi
             ;;
     esac
2aa35174
 
     # Create tempest.conf from tempest.conf.sample
     # copy every time, because the image UUIDS are going to change
     cp $TEMPEST_CONF.sample $TEMPEST_CONF
 
65c0846e
     password=${ADMIN_PASSWORD:-secrete}
2aa35174
 
     # See files/keystone_data.sh where alt_demo user
     # and tenant are set up...
     ALT_USERNAME=${ALT_USERNAME:-alt_demo}
     ALT_TENANT_NAME=${ALT_TENANT_NAME:-alt_demo}
 
7bf1dd35
     # If the ``DEFAULT_INSTANCE_TYPE`` not declared, use the new behavior
     # Tempest creates instane types for himself
     if  [[ -z "$DEFAULT_INSTANCE_TYPE" ]]; then
02c0bcc3
         nova flavor-create m1.nano 42 64 0 1
7bf1dd35
         flavor_ref=42
1d29d8bc
         boto_instance_type=m1.nano
02c0bcc3
         nova flavor-create m1.micro 84 128 0 1
7bf1dd35
         flavor_ref_alt=84
     else
         # Check Nova for existing flavors and, if set, look for the
         # ``DEFAULT_INSTANCE_TYPE`` and use that.
1d29d8bc
         boto_instance_type=$DEFAULT_INSTANCE_TYPE
7bf1dd35
         flavor_lines=`nova flavor-list`
         IFS=$'\r\n'
         flavors=""
ceaa38b3
         for line in $flavor_lines; do
             f=$(echo $line | awk "/ $DEFAULT_INSTANCE_TYPE / { print \$2 }")
             flavors="$flavors $f"
         done
7bf1dd35
 
         for line in $flavor_lines; do
             flavors="$flavors `echo $line | grep -v "^\(|\s*ID\|+--\)" | cut -d' ' -f2`"
         done
 
         IFS=" "
         flavors=($flavors)
         num_flavors=${#flavors[*]}
         echo "Found $num_flavors flavors"
         if [[ $num_flavors -eq 0 ]]; then
             echo "Found no valid flavors to use!"
             exit 1
         fi
         flavor_ref=${flavors[0]}
         flavor_ref_alt=$flavor_ref
         if [[ $num_flavors -gt 1 ]]; then
             flavor_ref_alt=${flavors[1]}
         fi
2aa35174
     fi
 
a5c774ea
     if [ "$Q_USE_NAMESPACE" != "False" ]; then
         tenant_networks_reachable=false
     else
         tenant_networks_reachable=true
     fi
 
     if is_service_enabled q-l3; then
         public_network_id=$(quantum net-list | grep $PUBLIC_NETWORK_NAME | \
             awk '{print $2}')
31c94ab5
         if [ "$Q_USE_NAMESPACE" == "False" ]; then
             # If namespaces are disabled, devstack will create a single
             # public router that tempest should be configured to use.
             public_router_id=$(quantum router-list | awk "/ $Q_ROUTER_NAME / \
                { print \$2 }")
         fi
a5c774ea
     fi
 
2aa35174
     # Timeouts
     iniset $TEMPEST_CONF compute build_timeout $BUILD_TIMEOUT
     iniset $TEMPEST_CONF volume build_timeout $BUILD_TIMEOUT
     iniset $TEMPEST_CONF boto build_timeout $BUILD_TIMEOUT
     iniset $TEMPEST_CONF compute build_interval $BUILD_INTERVAL
     iniset $TEMPEST_CONF volume build_interval $BUILD_INTERVAL
     iniset $TEMPEST_CONF boto build_interval $BUILD_INTERVAL
     iniset $TEMPEST_CONF boto http_socket_timeout 5
 
97d3d202
     # Identity
     iniset $TEMPEST_CONF identity uri "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:5000/v2.0/"
     iniset $TEMPEST_CONF identity password "$password"
     iniset $TEMPEST_CONF identity alt_username $ALT_USERNAME
     iniset $TEMPEST_CONF identity alt_password "$password"
     iniset $TEMPEST_CONF identity alt_tenant_name $ALT_TENANT_NAME
     iniset $TEMPEST_CONF identity admin_password "$password"
 
     # Compute
2aa35174
     iniset $TEMPEST_CONF compute change_password_available False
06fac37d
     # Note(nati) current tempest don't create network for each tenant
     # so reuse same tenant for now
     if is_service_enabled quantum; then
         TEMPEST_ALLOW_TENANT_ISOLATION=${TEMPEST_ALLOW_TENANT_ISOLATION:-False}
     fi
     iniset $TEMPEST_CONF compute allow_tenant_isolation ${TEMPEST_ALLOW_TENANT_ISOLATION:-True}
97d3d202
     iniset $TEMPEST_CONF compute ssh_user ${DEFAULT_INSTANCE_USER:-cirros} # DEPRECATED
66afb47c
     iniset $TEMPEST_CONF compute network_for_ssh $PRIVATE_NETWORK_NAME
2aa35174
     iniset $TEMPEST_CONF compute ip_version_for_ssh 4
1d29d8bc
     iniset $TEMPEST_CONF compute ssh_timeout $BUILD_TIMEOUT
65c0846e
     iniset $TEMPEST_CONF compute image_ref $image_uuid
97d3d202
     iniset $TEMPEST_CONF compute image_ssh_user ${DEFAULT_INSTANCE_USER:-cirros}
65c0846e
     iniset $TEMPEST_CONF compute image_ref_alt $image_uuid_alt
97d3d202
     iniset $TEMPEST_CONF compute image_alt_ssh_user ${DEFAULT_INSTANCE_USER:-cirros}
65c0846e
     iniset $TEMPEST_CONF compute flavor_ref $flavor_ref
     iniset $TEMPEST_CONF compute flavor_ref_alt $flavor_ref_alt
2aa35174
     iniset $TEMPEST_CONF compute live_migration_available ${LIVE_MIGRATION_AVAILABLE:-False}
66afb47c
     iniset $TEMPEST_CONF compute use_block_migration_for_live_migration ${USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION:-False}
97d3d202
 
     # Whitebox
     iniset $TEMPEST_CONF whitebox source_dir $NOVA_SOURCE_DIR
     iniset $TEMPEST_CONF whitebox bin_dir $NOVA_BIN_DIR
2aa35174
     # TODO(jaypipes): Create the key file here... right now, no whitebox
     # tests actually use a key.
97d3d202
     iniset $TEMPEST_CONF whitebox path_to_private_key $TEMPEST_DIR/id_rsa
     iniset $TEMPEST_CONF whitebox db_uri $BASE_SQL_CONN/nova
 
2aa35174
 
     # compute admin
97d3d202
     iniset $TEMPEST_CONF "compute-admin" password "$password" # DEPRECATED
2aa35174
 
     # network
4a20f9a1
     if is_service_enabled quantum; then
         iniset $TEMPEST_CONF network quantum_available "True"
     fi
2aa35174
     iniset $TEMPEST_CONF network api_version 2.0
a5c774ea
     iniset $TEMPEST_CONF network tenant_networks_reachable "$tenant_networks_reachable"
     iniset $TEMPEST_CONF network public_network_id "$public_network_id"
31c94ab5
     iniset $TEMPEST_CONF network public_router_id "$public_router_id"
2aa35174
 
     #boto
     iniset $TEMPEST_CONF boto ec2_url "http://$SERVICE_HOST:8773/services/Cloud"
     iniset $TEMPEST_CONF boto s3_url "http://$SERVICE_HOST:${S3_SERVICE_PORT:-3333}"
1d29d8bc
     iniset $TEMPEST_CONF boto s3_materials_path "$BOTO_MATERIALS_PATH"
     iniset $TEMPEST_CONF boto instance_type "$boto_instance_type"
     iniset $TEMPEST_CONF boto http_socket_timeout 30
97d3d202
     iniset $TEMPEST_CONF boto ssh_user ${DEFAULT_INSTANCE_USER:-cirros}
2aa35174
 
     echo "Created tempest configuration file:"
     cat $TEMPEST_CONF
 
     # Restore IFS
     IFS=$ifs
     #Restore errexit
     $errexit
d093121f
 }
 
 # install_tempest() - Collect source and prepare
 function install_tempest() {
     git_clone $TEMPEST_REPO $TEMPEST_DIR $TEMPEST_BRANCH
 }
 
1d29d8bc
 # init_tempest() - Initialize ec2 images
 function init_tempest() {
cde655ac
     local base_image_name=cirros-0.3.1-x86_64
     # /opt/stack/devstack/files/images/cirros-0.3.1-x86_64-uec
3c52922f
     local image_dir="$FILES/images/${base_image_name}-uec"
1d29d8bc
     local kernel="$image_dir/${base_image_name}-vmlinuz"
     local ramdisk="$image_dir/${base_image_name}-initrd"
     local disk_image="$image_dir/${base_image_name}-blank.img"
     # if the cirros uec downloaded and the system is uec capable
     if [ -f "$kernel" -a -f "$ramdisk" -a -f "$disk_image" -a  "$VIRT_DRIVER" != "openvz" \
          -a \( "$LIBVIRT_TYPE" != "lxc" -o "$VIRT_DRIVER" != "libvirt" \) ]; then
        echo "Prepare aki/ari/ami Images"
        ( #new namespace
            # tenant:demo ; user: demo
b0b98b70
            source $TOP_DIR/accrc/demo/demo
1d29d8bc
            euca-bundle-image -i "$kernel" --kernel true -d "$BOTO_MATERIALS_PATH"
            euca-bundle-image -i "$ramdisk" --ramdisk true -d "$BOTO_MATERIALS_PATH"
            euca-bundle-image -i "$disk_image" -d "$BOTO_MATERIALS_PATH"
        ) 2>&1 </dev/null | cat
     else
         echo "Boto materials are not prepared"
     fi
 }
 
d093121f
 # Restore xtrace
 $XTRACE
584d90ec
 
 # Local variables:
 # mode: shell-script
 # End: