blob: adc3393bb65fc78572e17c7a6652c108a760d5b7 [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
42# run test as the admin user
43_OLD_USERNAME=$OS_USERNAME
44OS_USERNAME=admin
45
46
47# Create an aggregate
48# ===================
49
50AGGREGATE_NAME=test_aggregate_$RANDOM
Joe Gordonb7ef5392012-08-01 16:13:42 -070051AGGREGATE2_NAME=test_aggregate_$RANDOM
John Garbuttfd1c87e2012-02-24 14:52:54 +000052AGGREGATE_A_ZONE=nova
53
54exit_if_aggregate_present() {
55 aggregate_name=$1
56
57 if [ `nova aggregate-list | grep -c " $aggregate_name "` == 0 ]; then
58 echo "SUCCESS $aggregate_name not present"
59 else
60 echo "ERROR found aggregate: $aggregate_name"
61 exit -1
62 fi
63}
64
65exit_if_aggregate_present $AGGREGATE_NAME
66
67AGGREGATE_ID=`nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1`
Joe Gordonb7ef5392012-08-01 16:13:42 -070068AGGREGATE2_ID=`nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1`
John Garbuttfd1c87e2012-02-24 14:52:54 +000069
70# check aggregate created
71nova aggregate-list | grep -q " $AGGREGATE_NAME " || die "Aggregate $AGGREGATE_NAME not created"
72
73
74# Ensure creating a duplicate fails
75# =================================
76
77if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then
78 echo "ERROR could create duplicate aggregate"
79 exit -1
80fi
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
102#ensure no metadata is set
103nova aggregate-details $AGGREGATE_ID | grep {}
104
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
117nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die "ERROR metadata was not cleared"
118
119nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY
120nova aggregate-details $AGGREGATE_ID | grep {}
121
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
Mate Lakat178b8402012-09-05 10:42:10 +0100128FIRST_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
Joe Gordonb7ef5392012-08-01 16:13:42 -0700133 echo "ERROR could add duplicate host to single aggregate"
134 exit -1
135fi
Mate Lakat178b8402012-09-05 10:42:10 +0100136nova aggregate-remove-host $AGGREGATE2_ID $FIRST_HOST
137nova aggregate-remove-host $AGGREGATE_ID $FIRST_HOST
John Garbuttfd1c87e2012-02-24 14:52:54 +0000138
139# Test aggregate-delete
140# =====================
141nova aggregate-delete $AGGREGATE_ID
Joe Gordonb7ef5392012-08-01 16:13:42 -0700142nova aggregate-delete $AGGREGATE2_ID
John Garbuttfd1c87e2012-02-24 14:52:54 +0000143exit_if_aggregate_present $AGGREGATE_NAME
144
145
146# Test complete
147# =============
148OS_USERNAME=$_OLD_USERNAME
149echo "AGGREGATE TEST PASSED"
150
151set +o xtrace
152echo "**************************************************"
153echo "End DevStack Exercise: $0"
154echo "**************************************************"