Browse code

Exercise cleanup

* Make common steps consistent
* Make comments consistent

aggregates.sh
boot_from_volume.sh
client-args.sh
client-env.sh
euca.sh
floating_ips.sh
sec_groups.sh
swift.sh
volumes.sh

Change-Id: Ib93dcdfdead93c259e3cd184fbc5ccc0a4a87c9a

Dean Troyer authored on 2013/02/16 02:07:14
Showing 9 changed files
... ...
@@ -39,9 +39,8 @@ source $TOP_DIR/openrc
39 39
 # Import exercise configuration
40 40
 source $TOP_DIR/exerciserc
41 41
 
42
-# run test as the admin user
43
-_OLD_USERNAME=$OS_USERNAME
44
-OS_USERNAME=admin
42
+# Test as the admin user
43
+. openrc admin admin
45 44
 
46 45
 
47 46
 # Create an aggregate
... ...
@@ -54,7 +53,7 @@ AGGREGATE_A_ZONE=nova
54 54
 exit_if_aggregate_present() {
55 55
     aggregate_name=$1
56 56
 
57
-    if [ `nova aggregate-list | grep -c " $aggregate_name "` == 0 ]; then
57
+    if [ $(nova aggregate-list | grep -c " $aggregate_name ") == 0 ]; then
58 58
         echo "SUCCESS $aggregate_name not present"
59 59
     else
60 60
         echo "ERROR found aggregate: $aggregate_name"
... ...
@@ -64,8 +63,8 @@ exit_if_aggregate_present() {
64 64
 
65 65
 exit_if_aggregate_present $AGGREGATE_NAME
66 66
 
67
-AGGREGATE_ID=`nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1`
68
-AGGREGATE2_ID=`nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1`
67
+AGGREGATE_ID=$(nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1)
68
+AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1)
69 69
 
70 70
 # check aggregate created
71 71
 nova aggregate-list | grep -q " $AGGREGATE_NAME " || die "Aggregate $AGGREGATE_NAME not created"
... ...
@@ -125,7 +124,7 @@ nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGAT
125 125
 if [ "$VIRT_DRIVER" == "xenserver" ]; then
126 126
     echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate"
127 127
 fi
128
-FIRST_HOST=`nova host-list | grep compute | get_field 1 | head -1`
128
+FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1)
129 129
 # Make sure can add two aggregates to same host
130 130
 nova aggregate-add-host $AGGREGATE_ID $FIRST_HOST
131 131
 nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST
... ...
@@ -142,12 +141,6 @@ nova aggregate-delete $AGGREGATE_ID
142 142
 nova aggregate-delete $AGGREGATE2_ID
143 143
 exit_if_aggregate_present $AGGREGATE_NAME
144 144
 
145
-
146
-# Test complete
147
-# =============
148
-OS_USERNAME=$_OLD_USERNAME
149
-echo "AGGREGATE TEST PASSED"
150
-
151 145
 set +o xtrace
152 146
 echo "**************************************************"
153 147
 echo "End DevStack Exercise: $0"
... ...
@@ -44,52 +44,80 @@ source $TOP_DIR/exerciserc
44 44
 # the exercise is skipped
45 45
 is_service_enabled cinder || exit 55
46 46
 
47
+# Instance type to create
48
+DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
49
+
47 50
 # Boot this image, use first AMI image if unset
48 51
 DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
49 52
 
50
-# Instance type
51
-DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
53
+# Security group name
54
+SECGROUP=${SECGROUP:-boot_secgroup}
52 55
 
53
-# Default floating IP pool name
54
-DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
56
+# Instance and volume names
57
+VM_NAME=${VM_NAME:-ex-bfv-inst}
58
+VOL_NAME=${VOL_NAME:-ex-vol-bfv}
55 59
 
56
-# Default user
57
-DEFAULT_INSTANCE_USER=${DEFAULT_INSTANCE_USER:-cirros}
58 60
 
59
-# Security group name
60
-SECGROUP=${SECGROUP:-boot_secgroup}
61
+# Launching a server
62
+# ==================
63
+
64
+# List servers for tenant:
65
+nova list
61 66
 
67
+# Images
68
+# ------
62 69
 
63
-# Launching servers
64
-# =================
70
+# List the images available
71
+glance image-list
65 72
 
66 73
 # Grab the id of the image to launch
67
-IMAGE=`glance image-list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1`
68
-die_if_not_set IMAGE "Failure getting image"
74
+IMAGE=$(glance image-list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
75
+die_if_not_set IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
76
+
77
+# Security Groups
78
+# ---------------
79
+
80
+# List security groups
81
+nova secgroup-list
82
+
83
+# Create a secgroup
84
+if ! nova secgroup-list | grep -q $SECGROUP; then
85
+    nova secgroup-create $SECGROUP "$SECGROUP description"
86
+    if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list | grep -q $SECGROUP; do sleep 1; done"; then
87
+        echo "Security group not created"
88
+        exit 1
89
+    fi
90
+fi
69 91
 
70
-# Instance and volume names
71
-VOL_INSTANCE_NAME=${VOL_INSTANCE_NAME:-test_vol_instance}
72
-VOL_NAME=${VOL_NAME:-test_volume}
92
+# Configure Security Group Rules
93
+if ! nova secgroup-list-rules $SECGROUP | grep -q icmp; then
94
+    nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
95
+fi
96
+if ! nova secgroup-list-rules $SECGROUP | grep -q " tcp .* 22 "; then
97
+    nova secgroup-add-rule $SECGROUP tcp 22 22 0.0.0.0/0
98
+fi
73 99
 
74
-# Clean-up from previous runs
75
-nova delete $VOL_INSTANCE_NAME || true
100
+# List secgroup rules
101
+nova secgroup-list-rules $SECGROUP
76 102
 
77
-if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $VOL_INSTANCE_NAME; do sleep 1; done"; then
78
-    echo "server didn't terminate!"
79
-    exit 1
80
-fi
103
+# Set up instance
104
+# ---------------
81 105
 
82
-# Configure Security Groups
83
-nova secgroup-delete $SECGROUP || true
84
-nova secgroup-create $SECGROUP "$SECGROUP description"
85
-nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
86
-nova secgroup-add-rule $SECGROUP tcp 22 22 0.0.0.0/0
106
+# List flavors
107
+nova flavor-list
87 108
 
88
-# Determinine instance type
89
-INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | cut -d"|" -f2`
109
+# Select a flavor
110
+INSTANCE_TYPE=$(nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1)
90 111
 if [[ -z "$INSTANCE_TYPE" ]]; then
91 112
     # grab the first flavor in the list to launch if default doesn't exist
92
-   INSTANCE_TYPE=`nova flavor-list | head -n 4 | tail -n 1 | cut -d"|" -f2`
113
+   INSTANCE_TYPE=$(nova flavor-list | head -n 4 | tail -n 1 | get_field 1)
114
+fi
115
+
116
+# Clean-up from previous runs
117
+nova delete $VM_NAME || true
118
+if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $VM_NAME; do sleep 1; done"; then
119
+    echo "server didn't terminate!"
120
+    exit 1
93 121
 fi
94 122
 
95 123
 # Setup Keypair
... ...
@@ -99,78 +127,80 @@ nova keypair-delete $KEY_NAME || true
99 99
 nova keypair-add $KEY_NAME > $KEY_FILE
100 100
 chmod 600 $KEY_FILE
101 101
 
102
-# Delete the old volume
103
-cinder delete $VOL_NAME || true
102
+# Set up volume
103
+# -------------
104 104
 
105
-# Free every floating ips - setting FREE_ALL_FLOATING_IPS=True in localrc will make life easier for testers
106
-if [ "$FREE_ALL_FLOATING_IPS" = "True" ]; then
107
-    nova floating-ip-list | grep nova | cut -d "|" -f2 | tr -d " " | xargs -n1 nova floating-ip-delete || true
108
-fi
109
-
110
-# Allocate floating ip
111
-FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | get_field 1`
112
-
113
-# Make sure the ip gets allocated
114
-if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $FLOATING_IP; do sleep 1; done"; then
115
-    echo "Floating IP not allocated"
105
+# Delete any old volume
106
+cinder delete $VOL_NAME || true
107
+if ! timeout $ACTIVE_TIMEOUT sh -c "while cinder list | grep $VOL_NAME; do sleep 1; done"; then
108
+    echo "Volume $VOL_NAME not deleted"
116 109
     exit 1
117 110
 fi
118 111
 
119 112
 # Create the bootable volume
120
-cinder create --display_name=$VOL_NAME --image-id $IMAGE $DEFAULT_VOLUME_SIZE
121
-
122
-# Wait for volume to activate
113
+start_time=$(date +%s)
114
+cinder create --image-id $IMAGE --display_name=$VOL_NAME --display_description "test bootable volume: $VOL_NAME" $DEFAULT_VOLUME_SIZE || \
115
+    die "Failure creating volume $VOL_NAME"
123 116
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
124 117
     echo "Volume $VOL_NAME not created"
125 118
     exit 1
126 119
 fi
120
+end_time=$(date +%s)
121
+echo "Completed cinder create in $((end_time - start_time)) seconds"
122
+
123
+# Get volume ID
124
+VOL_ID=$(cinder list | grep $VOL_NAME  | get_field 1)
125
+die_if_not_set VOL_ID "Failure retrieving volume ID for $VOL_NAME"
127 126
 
128
-VOLUME_ID=`cinder list | grep $VOL_NAME  | get_field 1`
127
+# Boot instance
128
+# -------------
129 129
 
130
-# Boot instance from volume!  This is done with the --block_device_mapping param.
131
-# The format of mapping is:
130
+# Boot using the --block_device_mapping param. The format of mapping is:
132 131
 # <dev_name>=<id>:<type>:<size(GB)>:<delete_on_terminate>
133 132
 # Leaving the middle two fields blank appears to do-the-right-thing
134
-VOL_VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --block_device_mapping vda=$VOLUME_ID:::0 --security_groups=$SECGROUP --key_name $KEY_NAME $VOL_INSTANCE_NAME | grep ' id ' | get_field 2`
135
-die_if_not_set VOL_VM_UUID "Failure launching $VOL_INSTANCE_NAME"
133
+VM_UUID=$(nova boot --flavor $INSTANCE_TYPE --image $IMAGE --block-device-mapping vda=$VOL_ID --security_groups=$SECGROUP --key_name $KEY_NAME $VM_NAME | grep ' id ' | get_field 2)
134
+die_if_not_set VM_UUID "Failure launching $VM_NAME"
136 135
 
137 136
 # Check that the status is active within ACTIVE_TIMEOUT seconds
138
-if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VOL_VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
137
+if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
139 138
     echo "server didn't become active!"
140 139
     exit 1
141 140
 fi
142 141
 
143
-# Add floating ip to our server
144
-nova add-floating-ip $VOL_VM_UUID $FLOATING_IP
145
-
146
-# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
147
-ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
142
+# Get the instance IP
143
+IP=$(nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2)
144
+die_if_not_set IP "Failure retrieving IP address"
148 145
 
149
-# Make sure our volume-backed instance launched
150
-ssh_check "$PUBLIC_NETWORK_NAME" $KEY_FILE $FLOATING_IP $DEFAULT_INSTANCE_USER $ACTIVE_TIMEOUT
146
+# Private IPs can be pinged in single node deployments
147
+ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
151 148
 
152
-# Remove floating ip from volume-backed instance
153
-nova remove-floating-ip $VOL_VM_UUID $FLOATING_IP
149
+# Clean up
150
+# --------
154 151
 
155 152
 # Delete volume backed instance
156
-nova delete $VOL_INSTANCE_NAME || \
157
-    die "Failure deleting instance volume $VOL_INSTANCE_NAME"
153
+nova delete $VM_UUID || die "Failure deleting instance $VM_NAME"
154
+if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q $VM_UUID; do sleep 1; done"; then
155
+    echo "Server $VM_NAME not deleted"
156
+    exit 1
157
+fi
158 158
 
159
-# Wait till our volume is no longer in-use
159
+# Wait for volume to be released
160 160
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
161
-    echo "Volume $VOL_NAME not created"
161
+    echo "Volume $VOL_NAME not released"
162 162
     exit 1
163 163
 fi
164 164
 
165
-# Delete the volume
166
-cinder delete $VOL_NAME || \
167
-    die "Failure deleting volume $VOLUME_NAME"
168
-
169
-# De-allocate the floating ip
170
-nova floating-ip-delete $FLOATING_IP || \
171
-    die "Failure deleting floating IP $FLOATING_IP"
165
+# Delete volume
166
+start_time=$(date +%s)
167
+cinder delete $VOL_ID || die "Failure deleting volume $VOLUME_NAME"
168
+if ! timeout $ACTIVE_TIMEOUT sh -c "while cinder list | grep $VOL_NAME; do sleep 1; done"; then
169
+    echo "Volume $VOL_NAME not deleted"
170
+    exit 1
171
+fi
172
+end_time=$(date +%s)
173
+echo "Completed cinder delete in $((end_time - start_time)) seconds"
172 174
 
173
-# Delete a secgroup
175
+# Delete secgroup
174 176
 nova secgroup-delete $SECGROUP || die "Failure deleting security group $SECGROUP"
175 177
 
176 178
 set +o xtrace
... ...
@@ -8,6 +8,14 @@ echo "*********************************************************************"
8 8
 echo "Begin DevStack Exercise: $0"
9 9
 echo "*********************************************************************"
10 10
 
11
+# This script exits on an error so that errors don't compound and you see
12
+# only the first error that occured.
13
+set -o errexit
14
+
15
+# Print the commands being run so that we can see the command that triggers
16
+# an error.  It is also useful for following allowing as the install occurs.
17
+set -o xtrace
18
+
11 19
 
12 20
 # Settings
13 21
 # ========
... ...
@@ -63,7 +71,7 @@ if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
63 63
         STATUS_KEYSTONE="Skipped"
64 64
     else
65 65
         echo -e "\nTest Keystone"
66
-        if keystone $TENANT_ARG $ARGS catalog --service identity; then
66
+        if keystone $TENANT_ARG_DASH $ARGS_DASH catalog --service identity; then
67 67
             STATUS_KEYSTONE="Succeeded"
68 68
         else
69 69
             STATUS_KEYSTONE="Failed"
... ...
@@ -82,7 +90,7 @@ if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
82 82
     else
83 83
         # Test OSAPI
84 84
         echo -e "\nTest Nova"
85
-        if nova $TENANT_ARG $ARGS flavor-list; then
85
+        if nova $TENANT_ARG_DASH $ARGS_DASH flavor-list; then
86 86
             STATUS_NOVA="Succeeded"
87 87
         else
88 88
             STATUS_NOVA="Failed"
... ...
@@ -91,6 +99,23 @@ if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
91 91
     fi
92 92
 fi
93 93
 
94
+# Cinder client
95
+# -------------
96
+
97
+if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
98
+    if [[ "$SKIP_EXERCISES" =~ "c-api" ]] ; then
99
+        STATUS_CINDER="Skipped"
100
+    else
101
+        echo -e "\nTest Cinder"
102
+        if cinder $TENANT_ARG_DASH $ARGS_DASH list; then
103
+            STATUS_CINDER="Succeeded"
104
+        else
105
+            STATUS_CINDER="Failed"
106
+            RETURN=1
107
+        fi
108
+    fi
109
+fi
110
+
94 111
 # Glance client
95 112
 # -------------
96 113
 
... ...
@@ -116,7 +141,7 @@ if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
116 116
         STATUS_SWIFT="Skipped"
117 117
     else
118 118
         echo -e "\nTest Swift"
119
-        if swift $TENANT_ARG $ARGS stat; then
119
+        if swift $TENANT_ARG_DASH $ARGS_DASH stat; then
120 120
             STATUS_SWIFT="Succeeded"
121 121
         else
122 122
             STATUS_SWIFT="Failed"
... ...
@@ -125,6 +150,8 @@ if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
125 125
     fi
126 126
 fi
127 127
 
128
+set +o xtrace
129
+
128 130
 # Results
129 131
 # -------
130 132
 
... ...
@@ -137,6 +164,7 @@ function report() {
137 137
 echo -e "\n"
138 138
 report "Keystone" $STATUS_KEYSTONE
139 139
 report "Nova" $STATUS_NOVA
140
+report "Cinder" $STATUS_CINDER
140 141
 report "Glance" $STATUS_GLANCE
141 142
 report "Swift" $STATUS_SWIFT
142 143
 
... ...
@@ -8,6 +8,14 @@ echo "*********************************************************************"
8 8
 echo "Begin DevStack Exercise: $0"
9 9
 echo "*********************************************************************"
10 10
 
11
+# This script exits on an error so that errors don't compound and you see
12
+# only the first error that occured.
13
+set -o errexit
14
+
15
+# Print the commands being run so that we can see the command that triggers
16
+# an error.  It is also useful for following allowing as the install occurs.
17
+set -o xtrace
18
+
11 19
 
12 20
 # Settings
13 21
 # ========
... ...
@@ -99,6 +107,23 @@ if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
99 99
     fi
100 100
 fi
101 101
 
102
+# Cinder client
103
+# -------------
104
+
105
+if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
106
+    if [[ "$SKIP_EXERCISES" =~ "c-api" ]] ; then
107
+        STATUS_CINDER="Skipped"
108
+    else
109
+        echo -e "\nTest Cinder"
110
+        if cinder list; then
111
+            STATUS_CINDER="Succeeded"
112
+        else
113
+            STATUS_CINDER="Failed"
114
+            RETURN=1
115
+        fi
116
+    fi
117
+fi
118
+
102 119
 # Glance client
103 120
 # -------------
104 121
 
... ...
@@ -133,6 +158,8 @@ if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
133 133
     fi
134 134
 fi
135 135
 
136
+set +o xtrace
137
+
136 138
 # Results
137 139
 # -------
138 140
 
... ...
@@ -146,6 +173,7 @@ echo -e "\n"
146 146
 report "Keystone" $STATUS_KEYSTONE
147 147
 report "Nova" $STATUS_NOVA
148 148
 report "EC2" $STATUS_EC2
149
+report "Cinder" $STATUS_CINDER
149 150
 report "Glance" $STATUS_GLANCE
150 151
 report "Swift" $STATUS_SWIFT
151 152
 
... ...
@@ -44,7 +44,7 @@ source $TOP_DIR/exerciserc
44 44
 # Instance type to create
45 45
 DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
46 46
 
47
-# Boot this image, use first AMI-format image if unset
47
+# Boot this image, use first AMI image if unset
48 48
 DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
49 49
 
50 50
 # Security group name
... ...
@@ -56,6 +56,7 @@ SECGROUP=${SECGROUP:-euca_secgroup}
56 56
 
57 57
 # Find a machine image to boot
58 58
 IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
59
+die_if_not_set IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
59 60
 
60 61
 # Add a secgroup
61 62
 if ! euca-describe-groups | grep -q $SECGROUP; then
... ...
@@ -174,7 +175,7 @@ if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE |
174 174
     exit 1
175 175
 fi
176 176
 
177
-# Delete group
177
+# Delete secgroup
178 178
 euca-delete-group $SECGROUP || die "Failure deleting security group $SECGROUP"
179 179
 
180 180
 set +o xtrace
... ...
@@ -2,8 +2,7 @@
2 2
 
3 3
 # **floating_ips.sh** - using the cloud can be fun
4 4
 
5
-# we will use the ``nova`` cli tool provided by the ``python-novaclient``
6
-# package to work out the instance connectivity
5
+# Test instance connectivity with the ``nova`` command from ``python-novaclient``
7 6
 
8 7
 echo "*********************************************************************"
9 8
 echo "Begin DevStack Exercise: $0"
... ...
@@ -42,7 +41,7 @@ source $TOP_DIR/exerciserc
42 42
 # Instance type to create
43 43
 DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
44 44
 
45
-# Boot this image, use first AMi image if unset
45
+# Boot this image, use first AMI image if unset
46 46
 DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
47 47
 
48 48
 # Security group name
... ...
@@ -54,6 +53,9 @@ DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
54 54
 # Additional floating IP pool and range
55 55
 TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
56 56
 
57
+# Instance name
58
+VM_NAME="ex-float"
59
+
57 60
 
58 61
 # Launching a server
59 62
 # ==================
... ...
@@ -64,19 +66,17 @@ nova list
64 64
 # Images
65 65
 # ------
66 66
 
67
-# Nova has a **deprecated** way of listing images.
68
-nova image-list
69
-
70
-# But we recommend using glance directly
67
+# List the images available
71 68
 glance image-list
72 69
 
73 70
 # Grab the id of the image to launch
74 71
 IMAGE=$(glance image-list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
72
+die_if_not_set IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
75 73
 
76 74
 # Security Groups
77 75
 # ---------------
78 76
 
79
-# List of secgroups:
77
+# List security groups
80 78
 nova secgroup-list
81 79
 
82 80
 # Create a secgroup
... ...
@@ -88,81 +88,79 @@ if ! nova secgroup-list | grep -q $SECGROUP; then
88 88
     fi
89 89
 fi
90 90
 
91
-# Determinine instance type
92
-# -------------------------
91
+# Configure Security Group Rules
92
+if ! nova secgroup-list-rules $SECGROUP | grep -q icmp; then
93
+    nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
94
+fi
95
+if ! nova secgroup-list-rules $SECGROUP | grep -q " tcp .* 22 "; then
96
+    nova secgroup-add-rule $SECGROUP tcp 22 22 0.0.0.0/0
97
+fi
93 98
 
94
-# List of instance types:
99
+# List secgroup rules
100
+nova secgroup-list-rules $SECGROUP
101
+
102
+# Set up instance
103
+# ---------------
104
+
105
+# List flavors
95 106
 nova flavor-list
96 107
 
97
-INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1`
108
+# Select a flavor
109
+INSTANCE_TYPE=$(nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1)
98 110
 if [[ -z "$INSTANCE_TYPE" ]]; then
99 111
     # grab the first flavor in the list to launch if default doesn't exist
100
-   INSTANCE_TYPE=`nova flavor-list | head -n 4 | tail -n 1 | get_field 1`
112
+   INSTANCE_TYPE=$(nova flavor-list | head -n 4 | tail -n 1 | get_field 1)
101 113
 fi
102 114
 
103
-NAME="ex-float"
104
-
105
-VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_groups=$SECGROUP | grep ' id ' | get_field 2`
106
-die_if_not_set VM_UUID "Failure launching $NAME"
107
-
108
-
109
-# Testing
110
-# =======
115
+# Clean-up from previous runs
116
+nova delete $VM_NAME || true
117
+if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $VM_NAME; do sleep 1; done"; then
118
+    echo "server didn't terminate!"
119
+    exit 1
120
+fi
111 121
 
112
-# First check if it spins up (becomes active and responds to ping on
113
-# internal ip).  If you run this script from a nova node, you should
114
-# bypass security groups and have direct access to the server.
122
+# Boot instance
123
+# -------------
115 124
 
116
-# Waiting for boot
117
-# ----------------
125
+VM_UUID=$(nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security_groups=$SECGROUP $VM_NAME | grep ' id ' | get_field 2)
126
+die_if_not_set VM_UUID "Failure launching $VM_NAME"
118 127
 
119
-# check that the status is active within ACTIVE_TIMEOUT seconds
128
+# Check that the status is active within ACTIVE_TIMEOUT seconds
120 129
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
121 130
     echo "server didn't become active!"
122 131
     exit 1
123 132
 fi
124 133
 
125
-# get the IP of the server
126
-IP=`nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2`
134
+# Get the instance IP
135
+IP=$(nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2)
127 136
 die_if_not_set IP "Failure retrieving IP address"
128 137
 
138
+# Private IPs can be pinged in single node deployments
129 139
 ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
130 140
 
131
-# Security Groups & Floating IPs
132
-# ------------------------------
133
-
134
-if ! nova secgroup-list-rules $SECGROUP | grep -q icmp; then
135
-    # allow icmp traffic (ping)
136
-    nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
137
-    if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list-rules $SECGROUP | grep -q icmp; do sleep 1; done"; then
138
-        echo "Security group rule not created"
139
-        exit 1
140
-    fi
141
-fi
142
-
143
-# List rules for a secgroup
144
-nova secgroup-list-rules $SECGROUP
141
+# Floating IPs
142
+# ------------
145 143
 
146
-# allocate a floating ip from default pool
147
-FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | get_field 1`
148
-die_if_not_set FLOATING_IP "Failure creating floating IP"
144
+# Allocate a floating IP from the default pool
145
+FLOATING_IP=$(nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | get_field 1)
146
+die_if_not_set FLOATING_IP "Failure creating floating IP from pool $DEFAULT_FLOATING_POOL"
149 147
 
150
-# list floating addresses
148
+# List floating addresses
151 149
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $FLOATING_IP; do sleep 1; done"; then
152 150
     echo "Floating IP not allocated"
153 151
     exit 1
154 152
 fi
155 153
 
156
-# add floating ip to our server
154
+# Add floating IP to our server
157 155
 nova add-floating-ip $VM_UUID $FLOATING_IP || \
158
-    die "Failure adding floating IP $FLOATING_IP to $NAME"
156
+    die "Failure adding floating IP $FLOATING_IP to $VM_NAME"
159 157
 
160
-# test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
158
+# Test we can ping our floating IP within ASSOCIATE_TIMEOUT seconds
161 159
 ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
162 160
 
163 161
 if ! is_service_enabled quantum; then
164 162
     # Allocate an IP from second floating pool
165
-    TEST_FLOATING_IP=`nova floating-ip-create $TEST_FLOATING_POOL | grep $TEST_FLOATING_POOL | get_field 1`
163
+    TEST_FLOATING_IP=$(nova floating-ip-create $TEST_FLOATING_POOL | grep $TEST_FLOATING_POOL | get_field 1)
166 164
     die_if_not_set TEST_FLOATING_IP "Failure creating floating IP in $TEST_FLOATING_POOL"
167 165
 
168 166
     # list floating addresses
... ...
@@ -172,34 +170,40 @@ if ! is_service_enabled quantum; then
172 172
      fi
173 173
 fi
174 174
 
175
-# dis-allow icmp traffic (ping)
176
-nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 || die "Failure deleting security group rule from $SECGROUP"
175
+# Dis-allow icmp traffic (ping)
176
+nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 || \
177
+    die "Failure deleting security group rule from $SECGROUP"
177 178
 
178 179
 # FIXME (anthony): make xs support security groups
179 180
 if [ "$VIRT_DRIVER" != "xenserver" -a "$VIRT_DRIVER" != "openvz" ]; then
180
-    # test we can aren't able to ping our floating ip within ASSOCIATE_TIMEOUT seconds
181
+    # Test we can aren't able to ping our floating ip within ASSOCIATE_TIMEOUT seconds
181 182
     ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT Fail
182 183
 fi
183 184
 
185
+# Clean up
186
+# --------
187
+
184 188
 if ! is_service_enabled quantum; then
185 189
     # Delete second floating IP
186
-    nova floating-ip-delete $TEST_FLOATING_IP || die "Failure deleting floating IP $TEST_FLOATING_IP"
190
+    nova floating-ip-delete $TEST_FLOATING_IP || \
191
+        die "Failure deleting floating IP $TEST_FLOATING_IP"
187 192
 fi
188 193
 
189
-# de-allocate the floating ip
190
-nova floating-ip-delete $FLOATING_IP || die "Failure deleting floating IP $FLOATING_IP"
191
-
192
-# Shutdown the server
193
-nova delete $VM_UUID || die "Failure deleting instance $NAME"
194
+# Delete the floating ip
195
+nova floating-ip-delete $FLOATING_IP || \
196
+    die "Failure deleting floating IP $FLOATING_IP"
194 197
 
198
+# Delete instance
199
+nova delete $VM_UUID || die "Failure deleting instance $VM_NAME"
195 200
 # Wait for termination
196 201
 if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q $VM_UUID; do sleep 1; done"; then
197
-    echo "Server $NAME not deleted"
202
+    echo "Server $VM_NAME not deleted"
198 203
     exit 1
199 204
 fi
200 205
 
201
-# Delete a secgroup
202
-nova secgroup-delete $SECGROUP || die "Failure deleting security group $SECGROUP"
206
+# Delete secgroup
207
+nova secgroup-delete $SECGROUP || \
208
+    die "Failure deleting security group $SECGROUP"
203 209
 
204 210
 set +o xtrace
205 211
 echo "*********************************************************************"
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 # **sec_groups.sh**
4 4
 
5
-# Test security groups via the command line tools that ship with it.
5
+# Test security groups via the command line
6 6
 
7 7
 echo "*********************************************************************"
8 8
 echo "Begin DevStack Exercise: $0"
... ...
@@ -41,7 +41,7 @@ source $TOP_DIR/exerciserc
41 41
 nova secgroup-list
42 42
 
43 43
 # Create random name for new sec group and create secgroup of said name
44
-SEC_GROUP_NAME="sec-group-$(openssl rand -hex 4)"
44
+SEC_GROUP_NAME="ex-secgroup-$(openssl rand -hex 4)"
45 45
 nova secgroup-create $SEC_GROUP_NAME 'a test security group'
46 46
 
47 47
 # Add some rules to the secgroup
... ...
@@ -65,8 +65,10 @@ done
65 65
 for RULE in "${RULES_TO_ADD[@]}"; do
66 66
     nova secgroup-delete-rule $SEC_GROUP_NAME tcp $RULE $RULE 0.0.0.0/0
67 67
 done
68
-nova secgroup-delete $SEC_GROUP_NAME
69 68
 
69
+# Delete secgroup
70
+nova secgroup-delete $SEC_GROUP_NAME || \
71
+    die "Failure deleting security group $SEC_GROUP_NAME"
70 72
 
71 73
 set +o xtrace
72 74
 echo "*********************************************************************"
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 # **swift.sh**
4 4
 
5
-# Test swift via the command line tools that ship with it.
5
+# Test swift via the ``swift`` command line from ``python-swiftclient`
6 6
 
7 7
 echo "*********************************************************************"
8 8
 echo "Begin DevStack Exercise: $0"
... ...
@@ -33,13 +33,13 @@ source $TOP_DIR/openrc
33 33
 # Import exercise configuration
34 34
 source $TOP_DIR/exerciserc
35 35
 
36
-# Container name
37
-CONTAINER=ex-swift
38
-
39 36
 # If swift is not enabled we exit with exitcode 55 which mean
40 37
 # exercise is skipped.
41 38
 is_service_enabled swift || exit 55
42 39
 
40
+# Container name
41
+CONTAINER=ex-swift
42
+
43 43
 
44 44
 # Testing Swift
45 45
 # =============
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 # **volumes.sh**
4 4
 
5
-# Test cinder volumes with the cinder command from python-cinderclient
5
+# Test cinder volumes with the ``cinder`` command from ``python-cinderclient``
6 6
 
7 7
 echo "*********************************************************************"
8 8
 echo "Begin DevStack Exercise: $0"
... ...
@@ -45,12 +45,16 @@ is_service_enabled cinder || exit 55
45 45
 # Instance type to create
46 46
 DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
47 47
 
48
-# Boot this image, use first AMi image if unset
48
+# Boot this image, use first AMI image if unset
49 49
 DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
50 50
 
51 51
 # Security group name
52 52
 SECGROUP=${SECGROUP:-vol_secgroup}
53 53
 
54
+# Instance and volume names
55
+VM_NAME=${VM_NAME:-ex-vol-inst}
56
+VOL_NAME="ex-vol-$(openssl rand -hex 4)"
57
+
54 58
 
55 59
 # Launching a server
56 60
 # ==================
... ...
@@ -61,19 +65,17 @@ nova list
61 61
 # Images
62 62
 # ------
63 63
 
64
-# Nova has a **deprecated** way of listing images.
65
-nova image-list
66
-
67
-# But we recommend using glance directly
64
+# List the images available
68 65
 glance image-list
69 66
 
70 67
 # Grab the id of the image to launch
71 68
 IMAGE=$(glance image-list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
69
+die_if_not_set IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
72 70
 
73 71
 # Security Groups
74 72
 # ---------------
75 73
 
76
-# List of secgroups:
74
+# List security groups
77 75
 nova secgroup-list
78 76
 
79 77
 # Create a secgroup
... ...
@@ -93,126 +95,122 @@ if ! nova secgroup-list-rules $SECGROUP | grep -q " tcp .* 22 "; then
93 93
     nova secgroup-add-rule $SECGROUP tcp 22 22 0.0.0.0/0
94 94
 fi
95 95
 
96
-# determinine instance type
97
-# -------------------------
96
+# List secgroup rules
97
+nova secgroup-list-rules $SECGROUP
98
+
99
+# Set up instance
100
+# ---------------
98 101
 
99
-# List of instance types:
102
+# List flavors
100 103
 nova flavor-list
101 104
 
102
-INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1`
105
+# Select a flavor
106
+INSTANCE_TYPE=$(nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1)
103 107
 if [[ -z "$INSTANCE_TYPE" ]]; then
104 108
     # grab the first flavor in the list to launch if default doesn't exist
105
-   INSTANCE_TYPE=`nova flavor-list | head -n 4 | tail -n 1 | get_field 1`
109
+   INSTANCE_TYPE=$(nova flavor-list | head -n 4 | tail -n 1 | get_field 1)
106 110
 fi
107 111
 
108
-NAME="ex-vol"
109
-
110
-VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_groups=$SECGROUP | grep ' id ' | get_field 2`
111
-die_if_not_set VM_UUID "Failure launching $NAME"
112
-
113
-
114
-# Testing
115
-# =======
112
+# Clean-up from previous runs
113
+nova delete $VM_NAME || true
114
+if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $VM_NAME; do sleep 1; done"; then
115
+    echo "server didn't terminate!"
116
+    exit 1
117
+fi
116 118
 
117
-# First check if it spins up (becomes active and responds to ping on
118
-# internal ip).  If you run this script from a nova node, you should
119
-# bypass security groups and have direct access to the server.
119
+# Boot instance
120
+# -------------
120 121
 
121
-# Waiting for boot
122
-# ----------------
122
+VM_UUID=$(nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security_groups=$SECGROUP $VM_NAME | grep ' id ' | get_field 2)
123
+die_if_not_set VM_UUID "Failure launching $VM_NAME"
123 124
 
124
-# check that the status is active within ACTIVE_TIMEOUT seconds
125
+# Check that the status is active within ACTIVE_TIMEOUT seconds
125 126
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
126 127
     echo "server didn't become active!"
127 128
     exit 1
128 129
 fi
129 130
 
130
-# get the IP of the server
131
-IP=`nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2`
131
+# Get the instance IP
132
+IP=$(nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2)
132 133
 die_if_not_set IP "Failure retrieving IP address"
133 134
 
134
-# for single node deployments, we can ping private ips
135
+# Private IPs can be pinged in single node deployments
135 136
 ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
136 137
 
137 138
 # Volumes
138 139
 # -------
139 140
 
140
-VOL_NAME="myvol-$(openssl rand -hex 4)"
141
-
142 141
 # Verify it doesn't exist
143
-if [[ -n "`cinder list | grep $VOL_NAME | head -1 | get_field 2`" ]]; then
142
+if [[ -n $(cinder list | grep $VOL_NAME | head -1 | get_field 2) ]]; then
144 143
     echo "Volume $VOL_NAME already exists"
145 144
     exit 1
146 145
 fi
147 146
 
148 147
 # Create a new volume
149
-cinder create --display_name $VOL_NAME --display_description "test volume: $VOL_NAME" $DEFAULT_VOLUME_SIZE
150
-if [[ $? != 0 ]]; then
151
-    echo "Failure creating volume $VOL_NAME"
152
-    exit 1
153
-fi
154
-
155
-start_time=`date +%s`
148
+start_time=$(date +%s)
149
+cinder create --display_name $VOL_NAME --display_description "test volume: $VOL_NAME" $DEFAULT_VOLUME_SIZE || \
150
+    die "Failure creating volume $VOL_NAME"
156 151
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
157 152
     echo "Volume $VOL_NAME not created"
158 153
     exit 1
159 154
 fi
160
-end_time=`date +%s`
155
+end_time=$(date +%s)
161 156
 echo "Completed cinder create in $((end_time - start_time)) seconds"
162 157
 
163 158
 # Get volume ID
164
-VOL_ID=`cinder list | grep $VOL_NAME | head -1 | get_field 1`
159
+VOL_ID=$(cinder list | grep $VOL_NAME | head -1 | get_field 1)
165 160
 die_if_not_set VOL_ID "Failure retrieving volume ID for $VOL_NAME"
166 161
 
167 162
 # Attach to server
168 163
 DEVICE=/dev/vdb
169
-start_time=`date +%s`
164
+start_time=$(date +%s)
170 165
 nova volume-attach $VM_UUID $VOL_ID $DEVICE || \
171
-    die "Failure attaching volume $VOL_NAME to $NAME"
166
+    die "Failure attaching volume $VOL_NAME to $VM_NAME"
172 167
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep in-use; do sleep 1; done"; then
173
-    echo "Volume $VOL_NAME not attached to $NAME"
168
+    echo "Volume $VOL_NAME not attached to $VM_NAME"
174 169
     exit 1
175 170
 fi
176
-end_time=`date +%s`
171
+end_time=$(date +%s)
177 172
 echo "Completed volume-attach in $((end_time - start_time)) seconds"
178 173
 
179
-VOL_ATTACH=`cinder list | grep $VOL_NAME | head -1 | get_field -1`
174
+VOL_ATTACH=$(cinder list | grep $VOL_NAME | head -1 | get_field -1)
180 175
 die_if_not_set VOL_ATTACH "Failure retrieving $VOL_NAME status"
181 176
 if [[ "$VOL_ATTACH" != $VM_UUID ]]; then
182 177
     echo "Volume not attached to correct instance"
183 178
     exit 1
184 179
 fi
185 180
 
181
+# Clean up
182
+# --------
183
+
186 184
 # Detach volume
187
-start_time=`date +%s`
188
-nova volume-detach $VM_UUID $VOL_ID || die "Failure detaching volume $VOL_NAME from $NAME"
185
+start_time=$(date +%s)
186
+nova volume-detach $VM_UUID $VOL_ID || die "Failure detaching volume $VOL_NAME from $VM_NAME"
189 187
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
190
-    echo "Volume $VOL_NAME not detached from $NAME"
188
+    echo "Volume $VOL_NAME not detached from $VM_NAME"
191 189
     exit 1
192 190
 fi
193
-end_time=`date +%s`
191
+end_time=$(date +%s)
194 192
 echo "Completed volume-detach in $((end_time - start_time)) seconds"
195 193
 
196 194
 # Delete volume
197
-start_time=`date +%s`
195
+start_time=$(date +%s)
198 196
 cinder delete $VOL_ID || die "Failure deleting volume $VOL_NAME"
199 197
 if ! timeout $ACTIVE_TIMEOUT sh -c "while cinder list | grep $VOL_NAME; do sleep 1; done"; then
200 198
     echo "Volume $VOL_NAME not deleted"
201 199
     exit 1
202 200
 fi
203
-end_time=`date +%s`
201
+end_time=$(date +%s)
204 202
 echo "Completed cinder delete in $((end_time - start_time)) seconds"
205 203
 
206
-# Shutdown the server
207
-nova delete $VM_UUID || die "Failure deleting instance $NAME"
208
-
209
-# Wait for termination
204
+# Delete instance
205
+nova delete $VM_UUID || die "Failure deleting instance $VM_NAME"
210 206
 if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q $VM_UUID; do sleep 1; done"; then
211
-    echo "Server $NAME not deleted"
207
+    echo "Server $VM_NAME not deleted"
212 208
     exit 1
213 209
 fi
214 210
 
215
-# Delete a secgroup
211
+# Delete secgroup
216 212
 nova secgroup-delete $SECGROUP || die "Failure deleting security group $SECGROUP"
217 213
 
218 214
 set +o xtrace