blob: 3c8372549116a6e467de3f04c26ee4fcc0d79e36 [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
45
46# Create an aggregate
47# ===================
48
49AGGREGATE_NAME=test_aggregate_$RANDOM
Joe Gordonb7ef5392012-08-01 16:13:42 -070050AGGREGATE2_NAME=test_aggregate_$RANDOM
John Garbuttfd1c87e2012-02-24 14:52:54 +000051AGGREGATE_A_ZONE=nova
52
53exit_if_aggregate_present() {
54 aggregate_name=$1
55
Dean Troyerda85cda2013-02-15 11:07:14 -060056 if [ $(nova aggregate-list | grep -c " $aggregate_name ") == 0 ]; then
John Garbuttfd1c87e2012-02-24 14:52:54 +000057 echo "SUCCESS $aggregate_name not present"
58 else
Nachi Ueno07115eb2013-02-26 12:38:18 -080059 die $LINENO "found aggregate: $aggregate_name"
John Garbuttfd1c87e2012-02-24 14:52:54 +000060 exit -1
61 fi
62}
63
64exit_if_aggregate_present $AGGREGATE_NAME
65
Dean Troyerda85cda2013-02-15 11:07:14 -060066AGGREGATE_ID=$(nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1)
67AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1)
John Garbuttfd1c87e2012-02-24 14:52:54 +000068
69# check aggregate created
Nachi Ueno07115eb2013-02-26 12:38:18 -080070nova aggregate-list | grep -q " $AGGREGATE_NAME " || die $LINENO "Aggregate $AGGREGATE_NAME not created"
John Garbuttfd1c87e2012-02-24 14:52:54 +000071
72
73# Ensure creating a duplicate fails
74# =================================
75
76if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080077 die $LINENO "could create duplicate aggregate"
John Garbuttfd1c87e2012-02-24 14:52:54 +000078fi
79
80
81# Test aggregate-update (and aggregate-details)
82# =============================================
83AGGREGATE_NEW_NAME=test_aggregate_$RANDOM
84
85nova aggregate-update $AGGREGATE_ID $AGGREGATE_NEW_NAME
86nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NEW_NAME
87nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
88
89nova aggregate-update $AGGREGATE_ID $AGGREGATE_NAME $AGGREGATE_A_ZONE
90nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NAME
91nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
92
93
94# Test aggregate-set-metadata
95# ===========================
96META_DATA_1_KEY=asdf
97META_DATA_2_KEY=foo
98META_DATA_3_KEY=bar
99
Joe Gordon5c1bedd2012-12-12 12:03:19 +0000100#ensure no additional metadata is set
101nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGATE_A_ZONE'}|{}"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000102
103nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123
104nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
105nova aggregate-details $AGGREGATE_ID | grep 123
106
107nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_2_KEY}=456
108nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
109nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY
110
111nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_2_KEY ${META_DATA_3_KEY}=789
112nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
113nova aggregate-details $AGGREGATE_ID | grep $META_DATA_3_KEY
114
Nachi Ueno07115eb2013-02-26 12:38:18 -0800115nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die $LINENO "ERROR metadata was not cleared"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000116
117nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY
Joe Gordon5c1bedd2012-12-12 12:03:19 +0000118nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGATE_A_ZONE'}|{}"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000119
120
121# Test aggregate-add/remove-host
122# ==============================
123if [ "$VIRT_DRIVER" == "xenserver" ]; then
Joe Gordonb7ef5392012-08-01 16:13:42 -0700124 echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000125fi
Dean Troyerda85cda2013-02-15 11:07:14 -0600126FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1)
Joe Gordonb7ef5392012-08-01 16:13:42 -0700127# Make sure can add two aggregates to same host
Mate Lakat178b8402012-09-05 10:42:10 +0100128nova aggregate-add-host $AGGREGATE_ID $FIRST_HOST
129nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST
130if nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800131 die $LINENO "could add duplicate host to single aggregate"
Joe Gordonb7ef5392012-08-01 16:13:42 -0700132fi
Mate Lakat178b8402012-09-05 10:42:10 +0100133nova aggregate-remove-host $AGGREGATE2_ID $FIRST_HOST
134nova aggregate-remove-host $AGGREGATE_ID $FIRST_HOST
John Garbuttfd1c87e2012-02-24 14:52:54 +0000135
136# Test aggregate-delete
137# =====================
138nova aggregate-delete $AGGREGATE_ID
Joe Gordonb7ef5392012-08-01 16:13:42 -0700139nova aggregate-delete $AGGREGATE2_ID
John Garbuttfd1c87e2012-02-24 14:52:54 +0000140exit_if_aggregate_present $AGGREGATE_NAME
141
John Garbuttfd1c87e2012-02-24 14:52:54 +0000142set +o xtrace
143echo "**************************************************"
144echo "End DevStack Exercise: $0"
145echo "**************************************************"