Browse code

Clean up local variable usage - cinder

Change-Id: Iedeafa15def1fa26d4ddcbc5f670129f66e38b9d

Dean Troyer authored on 2014/07/26 02:37:41
Showing 2 changed files
... ...
@@ -96,10 +96,10 @@ TEMPEST_SERVICES+=,cinder
96 96
 # Source the enabled backends
97 97
 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
98 98
     for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
99
-        BE_TYPE=${be%%:*}
100
-        BE_NAME=${be##*:}
101
-        if [[ -r $CINDER_BACKENDS/${BE_TYPE} ]]; then
102
-            source $CINDER_BACKENDS/${BE_TYPE}
99
+        be_type=${be%%:*}
100
+        be_name=${be##*:}
101
+        if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
102
+            source $CINDER_BACKENDS/${be_type}
103 103
         fi
104 104
     done
105 105
 fi
... ...
@@ -120,7 +120,7 @@ function is_cinder_enabled {
120 120
 function cleanup_cinder {
121 121
     # ensure the volume group is cleared up because fails might
122 122
     # leave dead volumes in the group
123
-    TARGETS=$(sudo tgtadm --op show --mode target)
123
+    local targets=$(sudo tgtadm --op show --mode target)
124 124
     if [ $? -ne 0 ]; then
125 125
         # If tgt driver isn't running this won't work obviously
126 126
         # So check the response and restart if need be
... ...
@@ -130,11 +130,11 @@ function cleanup_cinder {
130 130
         else
131 131
             restart_service tgtd
132 132
         fi
133
-        TARGETS=$(sudo tgtadm --op show --mode target)
133
+        targets=$(sudo tgtadm --op show --mode target)
134 134
     fi
135 135
 
136
-    if [[ -n "$TARGETS" ]]; then
137
-        iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
136
+    if [[ -n "$targets" ]]; then
137
+        local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
138 138
         for i in "${iqn_list[@]}"; do
139 139
             echo removing iSCSI target: $i
140 140
             sudo tgt-admin --delete $i
... ...
@@ -148,11 +148,12 @@ function cleanup_cinder {
148 148
     fi
149 149
 
150 150
     if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
151
+        local be be_name be_type
151 152
         for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
152
-            BE_TYPE=${be%%:*}
153
-            BE_NAME=${be##*:}
154
-            if type cleanup_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then
155
-                cleanup_cinder_backend_${BE_TYPE} ${BE_NAME}
153
+            be_type=${be%%:*}
154
+            be_name=${be##*:}
155
+            if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
156
+                cleanup_cinder_backend_${be_type} ${be_name}
156 157
             fi
157 158
         done
158 159
     fi
... ...
@@ -161,7 +162,7 @@ function cleanup_cinder {
161 161
 # configure_cinder_rootwrap() - configure Cinder's rootwrap
162 162
 function configure_cinder_rootwrap {
163 163
     # Set the paths of certain binaries
164
-    CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
164
+    local cinder_rootwrap=$(get_rootwrap_location cinder)
165 165
 
166 166
     # Deploy new rootwrap filters files (owned by root).
167 167
     # Wipe any existing rootwrap.d files first
... ...
@@ -179,14 +180,14 @@ function configure_cinder_rootwrap {
179 179
     sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
180 180
     sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
181 181
     # Specify rootwrap.conf as first parameter to rootwrap
182
-    ROOTWRAP_CSUDOER_CMD="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf *"
182
+    ROOTWRAP_CSUDOER_CMD="$cinder_rootwrap $CINDER_CONF_DIR/rootwrap.conf *"
183 183
 
184 184
     # Set up the rootwrap sudoers for cinder
185
-    TEMPFILE=`mktemp`
186
-    echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CSUDOER_CMD" >$TEMPFILE
187
-    chmod 0440 $TEMPFILE
188
-    sudo chown root:root $TEMPFILE
189
-    sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
185
+    local tempfile=`mktemp`
186
+    echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CSUDOER_CMD" >$tempfile
187
+    chmod 0440 $tempfile
188
+    sudo chown root:root $tempfile
189
+    sudo mv $tempfile /etc/sudoers.d/cinder-rootwrap
190 190
 }
191 191
 
192 192
 # configure_cinder() - Set config files, create data dirs, etc
... ...
@@ -237,18 +238,19 @@ function configure_cinder {
237 237
     iniset $CINDER_CONF DEFAULT enable_v1_api true
238 238
 
239 239
     if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
240
-        enabled_backends=""
241
-        default_name=""
240
+        local enabled_backends=""
241
+        local default_name=""
242
+        local be be_name be_type
242 243
         for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
243
-            BE_TYPE=${be%%:*}
244
-            BE_NAME=${be##*:}
245
-            if type configure_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then
246
-                configure_cinder_backend_${BE_TYPE} ${BE_NAME}
244
+            be_type=${be%%:*}
245
+            be_name=${be##*:}
246
+            if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
247
+                configure_cinder_backend_${be_type} ${be_name}
247 248
             fi
248
-            if [[ -z "$default_name" ]]; then
249
-                default_name=$BE_NAME
249
+            if [[ -z "$default_type" ]]; then
250
+                default_name=$be_type
250 251
             fi
251
-            enabled_backends+=$BE_NAME,
252
+            enabled_backends+=$be_name,
252 253
         done
253 254
         iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
254 255
         if [[ -n "$default_name" ]]; then
... ...
@@ -316,28 +318,28 @@ function configure_cinder {
316 316
 # Migrated from keystone_data.sh
317 317
 function create_cinder_accounts {
318 318
 
319
-    SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
320
-    ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
319
+    local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
320
+    local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
321 321
 
322 322
     # Cinder
323 323
     if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
324 324
 
325
-        CINDER_USER=$(get_or_create_user "cinder" \
326
-            "$SERVICE_PASSWORD" $SERVICE_TENANT)
327
-        get_or_add_user_role $ADMIN_ROLE $CINDER_USER $SERVICE_TENANT
325
+        local cinder_user=$(get_or_create_user "cinder" \
326
+            "$SERVICE_PASSWORD" $service_tenant)
327
+        get_or_add_user_role $admin_role $cinder_user $service_tenant
328 328
 
329 329
         if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
330 330
 
331
-            CINDER_SERVICE=$(get_or_create_service "cinder" \
331
+            local cinder_service=$(get_or_create_service "cinder" \
332 332
                 "volume" "Cinder Volume Service")
333
-            get_or_create_endpoint $CINDER_SERVICE "$REGION_NAME" \
333
+            get_or_create_endpoint $cinder_service "$REGION_NAME" \
334 334
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
335 335
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
336 336
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
337 337
 
338
-            CINDER_V2_SERVICE=$(get_or_create_service "cinderv2" \
338
+            local cinder_v2_service=$(get_or_create_service "cinderv2" \
339 339
                 "volumev2" "Cinder Volume Service V2")
340
-            get_or_create_endpoint $CINDER_V2_SERVICE "$REGION_NAME" \
340
+            get_or_create_endpoint $cinder_v2_service "$REGION_NAME" \
341 341
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
342 342
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
343 343
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s"
... ...
@@ -354,6 +356,7 @@ function create_cinder_cache_dir {
354 354
 }
355 355
 
356 356
 # init_cinder() - Initialize database and volume group
357
+# Uses global ``NOVA_ENABLED_APIS``
357 358
 function init_cinder {
358 359
     # Force nova volumes off
359 360
     NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
... ...
@@ -367,11 +370,12 @@ function init_cinder {
367 367
     fi
368 368
 
369 369
     if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
370
+        local be be_name be_type
370 371
         for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
371
-            BE_TYPE=${be%%:*}
372
-            BE_NAME=${be##*:}
373
-            if type init_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then
374
-                init_cinder_backend_${BE_TYPE} ${BE_NAME}
372
+            be_type=${be%%:*}
373
+            be_name=${be##*:}
374
+            if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
375
+                init_cinder_backend_${be_type} ${be_name}
375 376
             fi
376 377
         done
377 378
     fi
... ...
@@ -450,6 +454,7 @@ function start_cinder {
450 450
 # stop_cinder() - Stop running processes
451 451
 function stop_cinder {
452 452
     # Kill the cinder screen windows
453
+    local serv
453 454
     for serv in c-api c-bak c-sch c-vol; do
454 455
         screen_stop $serv
455 456
     done
... ...
@@ -467,12 +472,13 @@ function stop_cinder {
467 467
 function create_volume_types {
468 468
     # Create volume types
469 469
     if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
470
+        local be be_name be_type
470 471
         for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
471
-            BE_TYPE=${be%%:*}
472
-            BE_NAME=${be##*:}
473
-            # openstack volume type create --property volume_backend_name="${BE_TYPE}" ${BE_NAME}
474
-            cinder type-create ${BE_NAME} && \
475
-                cinder type-key ${BE_NAME} set volume_backend_name="${BE_NAME}"
472
+            be_type=${be%%:*}
473
+            be_name=${be##*:}
474
+            # openstack volume type create --property volume_backend_name="${be_type}" ${be_name}
475
+            cinder type-create ${be_name} && \
476
+                cinder type-key ${be_name} set volume_backend_name="${be_name}"
476 477
         done
477 478
     fi
478 479
 }
... ...
@@ -112,6 +112,7 @@ function _clean_lvm_lv {
112 112
     local lv_prefix=$2
113 113
 
114 114
     # Clean out existing volumes
115
+    local lv
115 116
     for lv in $(sudo lvs --noheadings -o lv_name $vg 2>/dev/null); do
116 117
         # lv_prefix prefixes the LVs we want
117 118
         if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
... ...
@@ -132,9 +133,9 @@ function _clean_lvm_backing_file {
132 132
     # of the backing file
133 133
     if [[ -z "$(sudo lvs --noheadings -o lv_name $vg 2>/dev/null)" ]]; then
134 134
         # if the backing physical device is a loop device, it was probably setup by devstack
135
-        VG_DEV=$(sudo losetup -j $backing_file | awk -F':' '/backing-file/ { print $1}')
136
-        if [[ -n "$VG_DEV" ]] && [[ -e "$VG_DEV" ]]; then
137
-            sudo losetup -d $VG_DEV
135
+        local vg_dev=$(sudo losetup -j $backing_file | awk -F':' '/backing-file/ { print $1}')
136
+        if [[ -n "$vg_dev" ]] && [[ -e "$vg_dev" ]]; then
137
+            sudo losetup -d $vg_dev
138 138
             rm -f $backing_file
139 139
         fi
140 140
     fi
... ...
@@ -159,11 +160,11 @@ function _create_cinder_volume_group {
159 159
         if [ -z "$VOLUME_BACKING_DEVICE" ]; then
160 160
             # Only create if the file doesn't already exists
161 161
             [[ -f $backing_file ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $backing_file
162
-            DEV=`sudo losetup -f --show $backing_file`
162
+            local vg_dev=`sudo losetup -f --show $backing_file`
163 163
 
164 164
             # Only create if the loopback device doesn't contain $VOLUME_GROUP
165 165
             if ! sudo vgs $vg_name; then
166
-                sudo vgcreate $vg_name $DEV
166
+                sudo vgcreate $vg_name $vg_dev
167 167
             fi
168 168
         else
169 169
             sudo vgcreate $vg_name $VOLUME_BACKING_DEVICE