blob: 96241f9b34960e3b69af72b01ccede5eb499c48f [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
23# an error. It is also useful for following allowing as the install occurs.
24set -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
34# Import common functions
35source $TOP_DIR/functions
36
37# Import configuration
38source $TOP_DIR/openrc
39
40# Import exercise configuration
41source $TOP_DIR/exerciserc
42
Dean Troyerda85cda2013-02-15 11:07:14 -060043# Test as the admin user
Mate Lakatc497a052013-02-21 15:25:51 +000044. $TOP_DIR/openrc admin admin
John Garbuttfd1c87e2012-02-24 14:52:54 +000045
Chris Behrensc62c2b92013-07-24 03:56:13 -070046# Cells does not support aggregates.
47is_service_enabled n-cell && exit 55
John Garbuttfd1c87e2012-02-24 14:52:54 +000048
49# Create an aggregate
50# ===================
51
52AGGREGATE_NAME=test_aggregate_$RANDOM
Joe Gordonb7ef5392012-08-01 16:13:42 -070053AGGREGATE2_NAME=test_aggregate_$RANDOM
John Garbuttfd1c87e2012-02-24 14:52:54 +000054AGGREGATE_A_ZONE=nova
55
56exit_if_aggregate_present() {
57 aggregate_name=$1
58
Dean Troyerda85cda2013-02-15 11:07:14 -060059 if [ $(nova aggregate-list | grep -c " $aggregate_name ") == 0 ]; then
John Garbuttfd1c87e2012-02-24 14:52:54 +000060 echo "SUCCESS $aggregate_name not present"
61 else
Nachi Ueno07115eb2013-02-26 12:38:18 -080062 die $LINENO "found aggregate: $aggregate_name"
John Garbuttfd1c87e2012-02-24 14:52:54 +000063 exit -1
64 fi
65}
66
67exit_if_aggregate_present $AGGREGATE_NAME
68
Dean Troyerda85cda2013-02-15 11:07:14 -060069AGGREGATE_ID=$(nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1)
70AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1)
John Garbuttfd1c87e2012-02-24 14:52:54 +000071
72# check aggregate created
Nachi Ueno07115eb2013-02-26 12:38:18 -080073nova aggregate-list | grep -q " $AGGREGATE_NAME " || die $LINENO "Aggregate $AGGREGATE_NAME not created"
John Garbuttfd1c87e2012-02-24 14:52:54 +000074
75
76# Ensure creating a duplicate fails
77# =================================
78
79if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080080 die $LINENO "could create duplicate aggregate"
John Garbuttfd1c87e2012-02-24 14:52:54 +000081fi
82
83
84# Test aggregate-update (and aggregate-details)
85# =============================================
86AGGREGATE_NEW_NAME=test_aggregate_$RANDOM
87
88nova aggregate-update $AGGREGATE_ID $AGGREGATE_NEW_NAME
89nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NEW_NAME
90nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
91
92nova aggregate-update $AGGREGATE_ID $AGGREGATE_NAME $AGGREGATE_A_ZONE
93nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NAME
94nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
95
96
97# Test aggregate-set-metadata
98# ===========================
99META_DATA_1_KEY=asdf
100META_DATA_2_KEY=foo
101META_DATA_3_KEY=bar
102
Joe Gordon5c1bedd2012-12-12 12:03:19 +0000103#ensure no additional metadata is set
Sahid Orentino Ferdjaoui75e851a2013-10-16 08:34:05 +0000104nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000105
106nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123
107nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
108nova aggregate-details $AGGREGATE_ID | grep 123
109
110nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_2_KEY}=456
111nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
112nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY
113
114nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_2_KEY ${META_DATA_3_KEY}=789
115nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
116nova aggregate-details $AGGREGATE_ID | grep $META_DATA_3_KEY
117
Nachi Ueno07115eb2013-02-26 12:38:18 -0800118nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die $LINENO "ERROR metadata was not cleared"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000119
120nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY
Sahid Orentino Ferdjaoui75e851a2013-10-16 08:34:05 +0000121nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000122
123
124# Test aggregate-add/remove-host
125# ==============================
126if [ "$VIRT_DRIVER" == "xenserver" ]; then
Joe Gordonb7ef5392012-08-01 16:13:42 -0700127 echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate"
John Garbuttfd1c87e2012-02-24 14:52:54 +0000128fi
Dean Troyerda85cda2013-02-15 11:07:14 -0600129FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1)
Joe Gordonb7ef5392012-08-01 16:13:42 -0700130# Make sure can add two aggregates to same host
Mate Lakat178b8402012-09-05 10:42:10 +0100131nova aggregate-add-host $AGGREGATE_ID $FIRST_HOST
132nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST
133if nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800134 die $LINENO "could add duplicate host to single aggregate"
Joe Gordonb7ef5392012-08-01 16:13:42 -0700135fi
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
John Garbuttfd1c87e2012-02-24 14:52:54 +0000145set +o xtrace
146echo "**************************************************"
147echo "End DevStack Exercise: $0"
148echo "**************************************************"