blob: e2baecdb11539dc09edf4663689438565d75cf5c [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:
6# * Create an Aggregate
7# * Updating Aggregate details
8# * Testing Aggregate metadata
9# * Testing Aggregate delete
Joe Gordonb7ef5392012-08-01 16:13:42 -070010# * Testing General Aggregates (https://blueprints.launchpad.net/nova/+spec/general-host-aggregates)
11# * Testing add/remove hosts (with one host)
John Garbuttfd1c87e2012-02-24 14:52:54 +000012
13echo "**************************************************"
14echo "Begin DevStack Exercise: $0"
15echo "**************************************************"
16
17# This script exits on an error so that errors don't compound and you see
Joe Gordonb7ef5392012-08-01 16:13:42 -070018# only the first error that occurred.
John Garbuttfd1c87e2012-02-24 14:52:54 +000019set -o errexit
20
21# Print the commands being run so that we can see the command that triggers
22# an error. It is also useful for following allowing as the install occurs.
23set -o xtrace
24
25
26# Settings
27# ========
28
29# Keep track of the current directory
30EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
31TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
32
33# Import common functions
34source $TOP_DIR/functions
35
36# Import configuration
37source $TOP_DIR/openrc
38
39# Import exercise configuration
40source $TOP_DIR/exerciserc
41
Dean Troyerda85cda2013-02-15 11:07:14 -060042# Test as the admin user
Mate Lakatc497a052013-02-21 15:25:51 +000043. $TOP_DIR/openrc admin admin
John Garbuttfd1c87e2012-02-24 14:52:54 +000044
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
55exit_if_aggregate_present() {
56 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)
69AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1)
John Garbuttfd1c87e2012-02-24 14:52:54 +000070
71# check aggregate created
Nachi Ueno07115eb2013-02-26 12:38:18 -080072nova aggregate-list | grep -q " $AGGREGATE_NAME " || die $LINENO "Aggregate $AGGREGATE_NAME not created"
John Garbuttfd1c87e2012-02-24 14:52:54 +000073
74
75# Ensure creating a duplicate fails
76# =================================
77
78if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080079 die $LINENO "could create duplicate aggregate"
John Garbuttfd1c87e2012-02-24 14:52:54 +000080fi
81
82
83# Test aggregate-update (and aggregate-details)
84# =============================================
85AGGREGATE_NEW_NAME=test_aggregate_$RANDOM
86
87nova aggregate-update $AGGREGATE_ID $AGGREGATE_NEW_NAME
88nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NEW_NAME
89nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
90
91nova aggregate-update $AGGREGATE_ID $AGGREGATE_NAME $AGGREGATE_A_ZONE
92nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NAME
93nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
94
95
96# Test aggregate-set-metadata
97# ===========================
98META_DATA_1_KEY=asdf
99META_DATA_2_KEY=foo
100META_DATA_3_KEY=bar
101
Joe Gordon5c1bedd2012-12-12 12:03:19 +0000102#ensure no additional metadata is set
103nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGATE_A_ZONE'}|{}"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000104
105nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123
106nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
107nova aggregate-details $AGGREGATE_ID | grep 123
108
109nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_2_KEY}=456
110nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
111nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY
112
113nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_2_KEY ${META_DATA_3_KEY}=789
114nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
115nova aggregate-details $AGGREGATE_ID | grep $META_DATA_3_KEY
116
Nachi Ueno07115eb2013-02-26 12:38:18 -0800117nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die $LINENO "ERROR metadata was not cleared"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000118
119nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY
Joe Gordon5c1bedd2012-12-12 12:03:19 +0000120nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGATE_A_ZONE'}|{}"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000121
122
123# Test aggregate-add/remove-host
124# ==============================
125if [ "$VIRT_DRIVER" == "xenserver" ]; then
Joe Gordonb7ef5392012-08-01 16:13:42 -0700126 echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000127fi
Dean Troyerda85cda2013-02-15 11:07:14 -0600128FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1)
Joe Gordonb7ef5392012-08-01 16:13:42 -0700129# Make sure can add two aggregates to same host
Mate Lakat178b8402012-09-05 10:42:10 +0100130nova aggregate-add-host $AGGREGATE_ID $FIRST_HOST
131nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST
132if nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800133 die $LINENO "could add duplicate host to single aggregate"
Joe Gordonb7ef5392012-08-01 16:13:42 -0700134fi
Mate Lakat178b8402012-09-05 10:42:10 +0100135nova aggregate-remove-host $AGGREGATE2_ID $FIRST_HOST
136nova aggregate-remove-host $AGGREGATE_ID $FIRST_HOST
John Garbuttfd1c87e2012-02-24 14:52:54 +0000137
138# Test aggregate-delete
139# =====================
140nova aggregate-delete $AGGREGATE_ID
Joe Gordonb7ef5392012-08-01 16:13:42 -0700141nova aggregate-delete $AGGREGATE2_ID
John Garbuttfd1c87e2012-02-24 14:52:54 +0000142exit_if_aggregate_present $AGGREGATE_NAME
143
John Garbuttfd1c87e2012-02-24 14:52:54 +0000144set +o xtrace
145echo "**************************************************"
146echo "End DevStack Exercise: $0"
147echo "**************************************************"