aggregates.sh

aggregates.sh

# DIVIDER #!/usr/bin/env bash # DIVIDER echo "**************************************************" echo "Begin DevStack Exercise: $0" echo "**************************************************" # DIVIDER set -o errexit # DIVIDER set -o xtrace # DIVIDER # DIVIDER EXERCISE_DIR=$(cd $(dirname "$0") && pwd) TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) # DIVIDER . $TOP_DIR/openrc admin admin # DIVIDER source $TOP_DIR/exerciserc # DIVIDER is_service_enabled n-api || exit 55 # DIVIDER is_service_enabled n-cell && exit 55 # DIVIDER AGGREGATE_NAME=test_aggregate_$RANDOM AGGREGATE2_NAME=test_aggregate_$RANDOM AGGREGATE_A_ZONE=nova function exit_if_aggregate_present { aggregate_name=$1 if [ $(nova aggregate-list | grep -c " $aggregate_name ") == 0 ]; then echo "SUCCESS $aggregate_name not present" else die $LINENO "found aggregate: $aggregate_name" exit -1 fi } exit_if_aggregate_present $AGGREGATE_NAME AGGREGATE_ID=$(nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1) die_if_not_set $LINENO AGGREGATE_ID "Failure creating AGGREGATE_ID for $AGGREGATE_NAME $AGGREGATE_A_ZONE" AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1) die_if_not_set $LINENO AGGREGATE2_ID "Fail creating AGGREGATE2_ID for $AGGREGATE2_NAME $AGGREGATE_A_ZONE" # DIVIDER nova aggregate-list | grep -q " $AGGREGATE_NAME " || die $LINENO "Aggregate $AGGREGATE_NAME not created" # DIVIDER if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then die $LINENO "could create duplicate aggregate" fi # DIVIDER AGGREGATE_NEW_NAME=test_aggregate_$RANDOM nova aggregate-update $AGGREGATE_ID $AGGREGATE_NEW_NAME nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NEW_NAME nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE nova aggregate-update $AGGREGATE_ID $AGGREGATE_NAME $AGGREGATE_A_ZONE nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NAME nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE # DIVIDER META_DATA_1_KEY=asdf META_DATA_2_KEY=foo META_DATA_3_KEY=bar #ensure no additional metadata is set nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|" nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123 nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY nova aggregate-details $AGGREGATE_ID | grep 123 nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_2_KEY}=456 nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_2_KEY ${META_DATA_3_KEY}=789 nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY nova aggregate-details $AGGREGATE_ID | grep $META_DATA_3_KEY nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die $LINENO "ERROR metadata was not cleared" nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|" # DIVIDER if [ "$VIRT_DRIVER" == "xenserver" ]; then echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate" fi FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1) # DIVIDER nova aggregate-add-host $AGGREGATE_ID $FIRST_HOST nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST if nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST; then die $LINENO "could add duplicate host to single aggregate" fi nova aggregate-remove-host $AGGREGATE2_ID $FIRST_HOST nova aggregate-remove-host $AGGREGATE_ID $FIRST_HOST # DIVIDER nova aggregate-delete $AGGREGATE_ID nova aggregate-delete $AGGREGATE2_ID exit_if_aggregate_present $AGGREGATE_NAME set +o xtrace echo "**************************************************" echo "End DevStack Exercise: $0" echo "**************************************************" # DIVIDER

This script demonstrates how to use host aggregates:

This script exits on an error so that errors don't compound and you see only the first error that occurred.

Print the commands being run so that we can see the command that triggers an error. It is also useful for following allowing as the install occurs.

Settings

Keep track of the current directory

Test as the admin user note this imports stackrc/functions, etc

Import exercise configuration

If nova api is not enabled we exit with exitcode 55 so that the exercise is skipped

Cells does not support aggregates.

Create an aggregate

check aggregate created

Ensure creating a duplicate fails

Test aggregate-update (and aggregate-details)

Test aggregate-set-metadata

Test aggregate-add/remove-host

Make sure can add two aggregates to same host

Test aggregate-delete