Browse code

blueprint host-aggregates

add some inital tests for the host-aggregates blueprint

Change-Id: I0c07f2e7fd123bbda6d26f4ff64bea3949e57157

John Garbutt authored on 2012/02/24 23:52:54
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,141 @@
0
+#!/usr/bin/env bash
1
+
2
+# **aggregates.sh**
3
+
4
+# This script demonstrates how to use host aggregates:
5
+#  *  Create an Aggregate
6
+#  *  Updating Aggregate details
7
+#  *  Testing Aggregate metadata
8
+#  *  Testing Aggregate delete
9
+#  *  TODO(johngar) - test adding a host (idealy with two hosts)
10
+
11
+echo "**************************************************"
12
+echo "Begin DevStack Exercise: $0"
13
+echo "**************************************************"
14
+
15
+# This script exits on an error so that errors don't compound and you see
16
+# only the first error that occured.
17
+set -o errexit
18
+
19
+# Print the commands being run so that we can see the command that triggers
20
+# an error.  It is also useful for following allowing as the install occurs.
21
+set -o xtrace
22
+
23
+
24
+# Settings
25
+# ========
26
+
27
+# Keep track of the current directory
28
+EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
29
+TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
30
+
31
+# Import common functions
32
+source $TOP_DIR/functions
33
+
34
+# Import configuration
35
+source $TOP_DIR/openrc
36
+
37
+# Import exercise configuration
38
+source $TOP_DIR/exerciserc
39
+
40
+# run test as the admin user
41
+_OLD_USERNAME=$OS_USERNAME
42
+OS_USERNAME=admin
43
+
44
+
45
+# Create an aggregate
46
+# ===================
47
+
48
+AGGREGATE_NAME=test_aggregate_$RANDOM
49
+AGGREGATE_A_ZONE=nova
50
+
51
+exit_if_aggregate_present() {
52
+    aggregate_name=$1
53
+
54
+    if [ `nova aggregate-list | grep -c " $aggregate_name "` == 0 ]; then
55
+        echo "SUCCESS $aggregate_name not present"
56
+    else
57
+        echo "ERROR found aggregate: $aggregate_name"
58
+        exit -1
59
+    fi
60
+}
61
+
62
+exit_if_aggregate_present $AGGREGATE_NAME
63
+
64
+AGGREGATE_ID=`nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1`
65
+
66
+# check aggregate created
67
+nova aggregate-list | grep -q " $AGGREGATE_NAME " || die "Aggregate $AGGREGATE_NAME not created"
68
+
69
+
70
+# Ensure creating a duplicate fails
71
+# =================================
72
+
73
+if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then
74
+    echo "ERROR could create duplicate aggregate"
75
+    exit -1
76
+fi
77
+
78
+
79
+# Test aggregate-update (and aggregate-details)
80
+# =============================================
81
+AGGREGATE_NEW_NAME=test_aggregate_$RANDOM
82
+
83
+nova aggregate-update $AGGREGATE_ID $AGGREGATE_NEW_NAME
84
+nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NEW_NAME
85
+nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
86
+
87
+nova aggregate-update $AGGREGATE_ID $AGGREGATE_NAME $AGGREGATE_A_ZONE
88
+nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NAME
89
+nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
90
+
91
+
92
+# Test aggregate-set-metadata
93
+# ===========================
94
+META_DATA_1_KEY=asdf
95
+META_DATA_2_KEY=foo
96
+META_DATA_3_KEY=bar
97
+
98
+#ensure no metadata is set
99
+nova aggregate-details $AGGREGATE_ID | grep {}
100
+
101
+nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123
102
+nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
103
+nova aggregate-details $AGGREGATE_ID | grep 123
104
+
105
+nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_2_KEY}=456
106
+nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
107
+nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY
108
+
109
+nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_2_KEY ${META_DATA_3_KEY}=789
110
+nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
111
+nova aggregate-details $AGGREGATE_ID | grep $META_DATA_3_KEY
112
+
113
+nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die "ERROR metadata was not cleared"
114
+
115
+nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY
116
+nova aggregate-details $AGGREGATE_ID | grep {}
117
+
118
+
119
+# Test aggregate-add/remove-host
120
+# ==============================
121
+if [ "$VIRT_DRIVER" == "xenserver" ]; then
122
+    echo "TODO(johngarbutt) add tests for add/remove host from aggregate"
123
+fi
124
+
125
+
126
+# Test aggregate-delete
127
+# =====================
128
+nova aggregate-delete $AGGREGATE_ID
129
+exit_if_aggregate_present $AGGREGATE_NAME
130
+
131
+
132
+# Test complete
133
+# =============
134
+OS_USERNAME=$_OLD_USERNAME
135
+echo "AGGREGATE TEST PASSED"
136
+
137
+set +o xtrace
138
+echo "**************************************************"
139
+echo "End DevStack Exercise: $0"
140
+echo "**************************************************"