| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 1 | #!/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 Gordon | b7ef539 | 2012-08-01 16:13:42 -0700 | [diff] [blame] | 10 | #  *  Testing General Aggregates (https://blueprints.launchpad.net/nova/+spec/general-host-aggregates) | 
|  | 11 | #  *  Testing add/remove hosts (with one host) | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 12 |  | 
|  | 13 | echo "**************************************************" | 
|  | 14 | echo "Begin DevStack Exercise: $0" | 
|  | 15 | echo "**************************************************" | 
|  | 16 |  | 
|  | 17 | # This script exits on an error so that errors don't compound and you see | 
| Joe Gordon | b7ef539 | 2012-08-01 16:13:42 -0700 | [diff] [blame] | 18 | # only the first error that occurred. | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 19 | set -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. | 
|  | 23 | set -o xtrace | 
|  | 24 |  | 
|  | 25 |  | 
|  | 26 | # Settings | 
|  | 27 | # ======== | 
|  | 28 |  | 
|  | 29 | # Keep track of the current directory | 
|  | 30 | EXERCISE_DIR=$(cd $(dirname "$0") && pwd) | 
|  | 31 | TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) | 
|  | 32 |  | 
|  | 33 | # Import common functions | 
|  | 34 | source $TOP_DIR/functions | 
|  | 35 |  | 
|  | 36 | # Import configuration | 
|  | 37 | source $TOP_DIR/openrc | 
|  | 38 |  | 
|  | 39 | # Import exercise configuration | 
|  | 40 | source $TOP_DIR/exerciserc | 
|  | 41 |  | 
| Dean Troyer | da85cda | 2013-02-15 11:07:14 -0600 | [diff] [blame] | 42 | # Test as the admin user | 
| Mate Lakat | c497a05 | 2013-02-21 15:25:51 +0000 | [diff] [blame] | 43 | . $TOP_DIR/openrc admin admin | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 44 |  | 
|  | 45 |  | 
|  | 46 | # Create an aggregate | 
|  | 47 | # =================== | 
|  | 48 |  | 
|  | 49 | AGGREGATE_NAME=test_aggregate_$RANDOM | 
| Joe Gordon | b7ef539 | 2012-08-01 16:13:42 -0700 | [diff] [blame] | 50 | AGGREGATE2_NAME=test_aggregate_$RANDOM | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 51 | AGGREGATE_A_ZONE=nova | 
|  | 52 |  | 
|  | 53 | exit_if_aggregate_present() { | 
|  | 54 | aggregate_name=$1 | 
|  | 55 |  | 
| Dean Troyer | da85cda | 2013-02-15 11:07:14 -0600 | [diff] [blame] | 56 | if [ $(nova aggregate-list | grep -c " $aggregate_name ") == 0 ]; then | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 57 | echo "SUCCESS $aggregate_name not present" | 
|  | 58 | else | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 59 | die $LINENO "found aggregate: $aggregate_name" | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 60 | exit -1 | 
|  | 61 | fi | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | exit_if_aggregate_present $AGGREGATE_NAME | 
|  | 65 |  | 
| Dean Troyer | da85cda | 2013-02-15 11:07:14 -0600 | [diff] [blame] | 66 | AGGREGATE_ID=$(nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1) | 
|  | 67 | AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1) | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 68 |  | 
|  | 69 | # check aggregate created | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 70 | nova aggregate-list | grep -q " $AGGREGATE_NAME " || die $LINENO "Aggregate $AGGREGATE_NAME not created" | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 71 |  | 
|  | 72 |  | 
|  | 73 | # Ensure creating a duplicate fails | 
|  | 74 | # ================================= | 
|  | 75 |  | 
|  | 76 | if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 77 | die $LINENO "could create duplicate aggregate" | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 78 | fi | 
|  | 79 |  | 
|  | 80 |  | 
|  | 81 | # Test aggregate-update (and aggregate-details) | 
|  | 82 | # ============================================= | 
|  | 83 | AGGREGATE_NEW_NAME=test_aggregate_$RANDOM | 
|  | 84 |  | 
|  | 85 | nova aggregate-update $AGGREGATE_ID $AGGREGATE_NEW_NAME | 
|  | 86 | nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NEW_NAME | 
|  | 87 | nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE | 
|  | 88 |  | 
|  | 89 | nova aggregate-update $AGGREGATE_ID $AGGREGATE_NAME $AGGREGATE_A_ZONE | 
|  | 90 | nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NAME | 
|  | 91 | nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE | 
|  | 92 |  | 
|  | 93 |  | 
|  | 94 | # Test aggregate-set-metadata | 
|  | 95 | # =========================== | 
|  | 96 | META_DATA_1_KEY=asdf | 
|  | 97 | META_DATA_2_KEY=foo | 
|  | 98 | META_DATA_3_KEY=bar | 
|  | 99 |  | 
| Joe Gordon | 5c1bedd | 2012-12-12 12:03:19 +0000 | [diff] [blame] | 100 | #ensure no additional metadata is set | 
|  | 101 | nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGATE_A_ZONE'}|{}" | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 102 |  | 
|  | 103 | nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123 | 
|  | 104 | nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY | 
|  | 105 | nova aggregate-details $AGGREGATE_ID | grep 123 | 
|  | 106 |  | 
|  | 107 | nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_2_KEY}=456 | 
|  | 108 | nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY | 
|  | 109 | nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY | 
|  | 110 |  | 
|  | 111 | nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_2_KEY ${META_DATA_3_KEY}=789 | 
|  | 112 | nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY | 
|  | 113 | nova aggregate-details $AGGREGATE_ID | grep $META_DATA_3_KEY | 
|  | 114 |  | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 115 | nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die $LINENO "ERROR metadata was not cleared" | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 116 |  | 
|  | 117 | nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY | 
| Joe Gordon | 5c1bedd | 2012-12-12 12:03:19 +0000 | [diff] [blame] | 118 | nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGATE_A_ZONE'}|{}" | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 119 |  | 
|  | 120 |  | 
|  | 121 | # Test aggregate-add/remove-host | 
|  | 122 | # ============================== | 
|  | 123 | if [ "$VIRT_DRIVER" == "xenserver" ]; then | 
| Joe Gordon | b7ef539 | 2012-08-01 16:13:42 -0700 | [diff] [blame] | 124 | echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate" | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 125 | fi | 
| Dean Troyer | da85cda | 2013-02-15 11:07:14 -0600 | [diff] [blame] | 126 | FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1) | 
| Joe Gordon | b7ef539 | 2012-08-01 16:13:42 -0700 | [diff] [blame] | 127 | # Make sure can add two aggregates to same host | 
| Mate Lakat | 178b840 | 2012-09-05 10:42:10 +0100 | [diff] [blame] | 128 | nova aggregate-add-host $AGGREGATE_ID $FIRST_HOST | 
|  | 129 | nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST | 
|  | 130 | if nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST; then | 
| Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 131 | die $LINENO "could add duplicate host to single aggregate" | 
| Joe Gordon | b7ef539 | 2012-08-01 16:13:42 -0700 | [diff] [blame] | 132 | fi | 
| Mate Lakat | 178b840 | 2012-09-05 10:42:10 +0100 | [diff] [blame] | 133 | nova aggregate-remove-host $AGGREGATE2_ID $FIRST_HOST | 
|  | 134 | nova aggregate-remove-host $AGGREGATE_ID $FIRST_HOST | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 135 |  | 
|  | 136 | # Test aggregate-delete | 
|  | 137 | # ===================== | 
|  | 138 | nova aggregate-delete $AGGREGATE_ID | 
| Joe Gordon | b7ef539 | 2012-08-01 16:13:42 -0700 | [diff] [blame] | 139 | nova aggregate-delete $AGGREGATE2_ID | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 140 | exit_if_aggregate_present $AGGREGATE_NAME | 
|  | 141 |  | 
| John Garbutt | fd1c87e | 2012-02-24 14:52:54 +0000 | [diff] [blame] | 142 | set +o xtrace | 
|  | 143 | echo "**************************************************" | 
|  | 144 | echo "End DevStack Exercise: $0" | 
|  | 145 | echo "**************************************************" |