blob: 8cbca54fb2d0114e6973339961031a9f6b396d90 [file] [log] [blame]
John Garbuttfd1c87e2012-02-24 14:52:54 +00001#!/usr/bin/env bash
2
3# **aggregates.sh**
4
5# This script demonstrates how to use host aggregates:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01006#
7# * Create an Aggregate
8# * Updating Aggregate details
9# * Testing Aggregate metadata
10# * Testing Aggregate delete
11# * Testing General Aggregates (https://blueprints.launchpad.net/nova/+spec/general-host-aggregates)
12# * Testing add/remove hosts (with one host)
John Garbuttfd1c87e2012-02-24 14:52:54 +000013
14echo "**************************************************"
15echo "Begin DevStack Exercise: $0"
16echo "**************************************************"
17
18# This script exits on an error so that errors don't compound and you see
Joe Gordonb7ef5392012-08-01 16:13:42 -070019# only the first error that occurred.
John Garbuttfd1c87e2012-02-24 14:52:54 +000020set -o errexit
21
22# Print the commands being run so that we can see the command that triggers
igor01acdab2016-07-29 13:11:53 +020023# an error. It is also useful for following as the install occurs.
John Garbuttfd1c87e2012-02-24 14:52:54 +000024set -o xtrace
25
26
27# Settings
28# ========
29
30# Keep track of the current directory
31EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
32TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
33
Ian Wienandc0057ed2015-08-07 12:36:00 +100034# Test as the admin user
35# note this imports stackrc/functions, etc
36. $TOP_DIR/openrc admin admin
John Garbuttfd1c87e2012-02-24 14:52:54 +000037
38# Import exercise configuration
39source $TOP_DIR/exerciserc
40
Kiall Mac Innesa16c8212014-01-12 19:35:43 +000041# If nova api is not enabled we exit with exitcode 55 so that
42# the exercise is skipped
43is_service_enabled n-api || exit 55
44
Chris Behrensc62c2b92013-07-24 03:56:13 -070045# Cells does not support aggregates.
46is_service_enabled n-cell && exit 55
John Garbuttfd1c87e2012-02-24 14:52:54 +000047
48# Create an aggregate
49# ===================
50
51AGGREGATE_NAME=test_aggregate_$RANDOM
Joe Gordonb7ef5392012-08-01 16:13:42 -070052AGGREGATE2_NAME=test_aggregate_$RANDOM
John Garbuttfd1c87e2012-02-24 14:52:54 +000053AGGREGATE_A_ZONE=nova
54
Ian Wienandaee18c72014-02-21 15:35:08 +110055function exit_if_aggregate_present {
John Garbuttfd1c87e2012-02-24 14:52:54 +000056 aggregate_name=$1
57
Dean Troyerda85cda2013-02-15 11:07:14 -060058 if [ $(nova aggregate-list | grep -c " $aggregate_name ") == 0 ]; then
John Garbuttfd1c87e2012-02-24 14:52:54 +000059 echo "SUCCESS $aggregate_name not present"
60 else
Nachi Ueno07115eb2013-02-26 12:38:18 -080061 die $LINENO "found aggregate: $aggregate_name"
John Garbuttfd1c87e2012-02-24 14:52:54 +000062 exit -1
63 fi
64}
65
66exit_if_aggregate_present $AGGREGATE_NAME
67
Dean Troyerda85cda2013-02-15 11:07:14 -060068AGGREGATE_ID=$(nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -050069die_if_not_set $LINENO AGGREGATE_ID "Failure creating AGGREGATE_ID for $AGGREGATE_NAME $AGGREGATE_A_ZONE"
70
Dean Troyerda85cda2013-02-15 11:07:14 -060071AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -050072die_if_not_set $LINENO AGGREGATE2_ID "Fail creating AGGREGATE2_ID for $AGGREGATE2_NAME $AGGREGATE_A_ZONE"
John Garbuttfd1c87e2012-02-24 14:52:54 +000073
74# check aggregate created
Nachi Ueno07115eb2013-02-26 12:38:18 -080075nova aggregate-list | grep -q " $AGGREGATE_NAME " || die $LINENO "Aggregate $AGGREGATE_NAME not created"
John Garbuttfd1c87e2012-02-24 14:52:54 +000076
77
78# Ensure creating a duplicate fails
79# =================================
80
81if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080082 die $LINENO "could create duplicate aggregate"
John Garbuttfd1c87e2012-02-24 14:52:54 +000083fi
84
85
86# Test aggregate-update (and aggregate-details)
87# =============================================
88AGGREGATE_NEW_NAME=test_aggregate_$RANDOM
89
90nova aggregate-update $AGGREGATE_ID $AGGREGATE_NEW_NAME
91nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NEW_NAME
92nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
93
94nova aggregate-update $AGGREGATE_ID $AGGREGATE_NAME $AGGREGATE_A_ZONE
95nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NAME
96nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
97
98
99# Test aggregate-set-metadata
100# ===========================
101META_DATA_1_KEY=asdf
102META_DATA_2_KEY=foo
103META_DATA_3_KEY=bar
104
Joe Gordon5c1bedd2012-12-12 12:03:19 +0000105#ensure no additional metadata is set
Sahid Orentino Ferdjaoui75e851a2013-10-16 08:34:05 +0000106nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000107
108nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123
109nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
110nova aggregate-details $AGGREGATE_ID | grep 123
111
112nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_2_KEY}=456
113nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
114nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY
115
116nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_2_KEY ${META_DATA_3_KEY}=789
117nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
118nova aggregate-details $AGGREGATE_ID | grep $META_DATA_3_KEY
119
Nachi Ueno07115eb2013-02-26 12:38:18 -0800120nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die $LINENO "ERROR metadata was not cleared"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000121
122nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY
Sahid Orentino Ferdjaoui75e851a2013-10-16 08:34:05 +0000123nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000124
125
126# Test aggregate-add/remove-host
127# ==============================
128if [ "$VIRT_DRIVER" == "xenserver" ]; then
Joe Gordonb7ef5392012-08-01 16:13:42 -0700129 echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000130fi
Dean Troyerda85cda2013-02-15 11:07:14 -0600131FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1)
Joe Gordonb7ef5392012-08-01 16:13:42 -0700132# Make sure can add two aggregates to same host
Mate Lakat178b8402012-09-05 10:42:10 +0100133nova aggregate-add-host $AGGREGATE_ID $FIRST_HOST
134nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST
135if nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800136 die $LINENO "could add duplicate host to single aggregate"
Joe Gordonb7ef5392012-08-01 16:13:42 -0700137fi
Mate Lakat178b8402012-09-05 10:42:10 +0100138nova aggregate-remove-host $AGGREGATE2_ID $FIRST_HOST
139nova aggregate-remove-host $AGGREGATE_ID $FIRST_HOST
John Garbuttfd1c87e2012-02-24 14:52:54 +0000140
141# Test aggregate-delete
142# =====================
143nova aggregate-delete $AGGREGATE_ID
Joe Gordonb7ef5392012-08-01 16:13:42 -0700144nova aggregate-delete $AGGREGATE2_ID
John Garbuttfd1c87e2012-02-24 14:52:54 +0000145exit_if_aggregate_present $AGGREGATE_NAME
146
John Garbuttfd1c87e2012-02-24 14:52:54 +0000147set +o xtrace
148echo "**************************************************"
149echo "End DevStack Exercise: $0"
150echo "**************************************************"