fd1c87e8 |
#!/usr/bin/env bash
# **aggregates.sh**
# This script demonstrates how to use host aggregates: |
6a5aa7c6 |
#
# * Create an Aggregate
# * Updating Aggregate details
# * Testing Aggregate metadata
# * Testing Aggregate delete
# * Testing General Aggregates (https://blueprints.launchpad.net/nova/+spec/general-host-aggregates)
# * Testing add/remove hosts (with one host) |
fd1c87e8 |
echo "**************************************************"
echo "Begin DevStack Exercise: $0"
echo "**************************************************"
# This script exits on an error so that errors don't compound and you see |
b7ef539b |
# only the first error that occurred. |
fd1c87e8 |
set -o errexit
# Print the commands being run so that we can see the command that triggers |
01acdabb |
# an error. It is also useful for following as the install occurs. |
fd1c87e8 |
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
|
c0057ed5 |
# Test as the admin user
# note this imports stackrc/functions, etc
. $TOP_DIR/openrc admin admin |
fd1c87e8 |
# Import exercise configuration
source $TOP_DIR/exerciserc
|
a16c8210 |
# If nova api is not enabled we exit with exitcode 55 so that
# the exercise is skipped
is_service_enabled n-api || exit 55
|
c62c2b9b |
# Cells does not support aggregates.
is_service_enabled n-cell && exit 55 |
fd1c87e8 |
# Create an aggregate
# ===================
AGGREGATE_NAME=test_aggregate_$RANDOM |
b7ef539b |
AGGREGATE2_NAME=test_aggregate_$RANDOM |
fd1c87e8 |
AGGREGATE_A_ZONE=nova
|
aee18c74 |
function exit_if_aggregate_present { |
fd1c87e8 |
aggregate_name=$1
|
da85cdad |
if [ $(nova aggregate-list | grep -c " $aggregate_name ") == 0 ]; then |
fd1c87e8 |
echo "SUCCESS $aggregate_name not present"
else |
07115eb5 |
die $LINENO "found aggregate: $aggregate_name" |
fd1c87e8 |
exit -1
fi
}
exit_if_aggregate_present $AGGREGATE_NAME
|
da85cdad |
AGGREGATE_ID=$(nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1) |
23178a99 |
die_if_not_set $LINENO AGGREGATE_ID "Failure creating AGGREGATE_ID for $AGGREGATE_NAME $AGGREGATE_A_ZONE"
|
da85cdad |
AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1) |
23178a99 |
die_if_not_set $LINENO AGGREGATE2_ID "Fail creating AGGREGATE2_ID for $AGGREGATE2_NAME $AGGREGATE_A_ZONE" |
fd1c87e8 |
# check aggregate created |
07115eb5 |
nova aggregate-list | grep -q " $AGGREGATE_NAME " || die $LINENO "Aggregate $AGGREGATE_NAME not created" |
fd1c87e8 |
# Ensure creating a duplicate fails
# =================================
if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then |
07115eb5 |
die $LINENO "could create duplicate aggregate" |
fd1c87e8 |
fi
# Test aggregate-update (and aggregate-details)
# =============================================
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
# Test aggregate-set-metadata
# ===========================
META_DATA_1_KEY=asdf
META_DATA_2_KEY=foo
META_DATA_3_KEY=bar
|
5c1bedd1 |
#ensure no additional metadata is set |
75e851a6 |
nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|" |
fd1c87e8 |
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
|
07115eb5 |
nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die $LINENO "ERROR metadata was not cleared" |
fd1c87e8 |
nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY |
75e851a6 |
nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|" |
fd1c87e8 |
# Test aggregate-add/remove-host
# ==============================
if [ "$VIRT_DRIVER" == "xenserver" ]; then |
b7ef539b |
echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate" |
fd1c87e8 |
fi |
da85cdad |
FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1) |
b7ef539b |
# Make sure can add two aggregates to same host |
178b8402 |
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 |
07115eb5 |
die $LINENO "could add duplicate host to single aggregate" |
b7ef539b |
fi |
178b8402 |
nova aggregate-remove-host $AGGREGATE2_ID $FIRST_HOST
nova aggregate-remove-host $AGGREGATE_ID $FIRST_HOST |
fd1c87e8 |
# Test aggregate-delete
# =====================
nova aggregate-delete $AGGREGATE_ID |
b7ef539b |
nova aggregate-delete $AGGREGATE2_ID |
fd1c87e8 |
exit_if_aggregate_present $AGGREGATE_NAME
set +o xtrace
echo "**************************************************"
echo "End DevStack Exercise: $0"
echo "**************************************************" |