Browse code

Clean up local variable usage - Ironic

Change-Id: I7a455299c6aa079de02b75d4d53df43074880ff7

Dean Troyer authored on 2014/07/26 03:04:13
Showing 1 changed files
... ...
@@ -174,15 +174,15 @@ function configure_ironic_api {
174 174
 function configure_ironic_conductor {
175 175
     cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
176 176
     cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR
177
-    IRONIC_ROOTWRAP=$(get_rootwrap_location ironic)
178
-    ROOTWRAP_ISUDOER_CMD="$IRONIC_ROOTWRAP $IRONIC_CONF_DIR/rootwrap.conf *"
177
+    local ironic_rootwrap=$(get_rootwrap_location ironic)
178
+    local rootwrap_isudoer_cmd="$ironic_rootwrap $IRONIC_CONF_DIR/rootwrap.conf *"
179 179
 
180 180
     # Set up the rootwrap sudoers for ironic
181
-    TEMPFILE=`mktemp`
182
-    echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_ISUDOER_CMD" >$TEMPFILE
183
-    chmod 0440 $TEMPFILE
184
-    sudo chown root:root $TEMPFILE
185
-    sudo mv $TEMPFILE /etc/sudoers.d/ironic-rootwrap
181
+    local tempfile=`mktemp`
182
+    echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_isudoer_cmd" >$tempfile
183
+    chmod 0440 $tempfile
184
+    sudo chown root:root $tempfile
185
+    sudo mv $tempfile /etc/sudoers.d/ironic-rootwrap
186 186
 
187 187
     iniset $IRONIC_CONF_FILE DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
188 188
     iniset $IRONIC_CONF_FILE DEFAULT enabled_drivers $IRONIC_ENABLED_DRIVERS
... ...
@@ -213,22 +213,22 @@ function create_ironic_cache_dir {
213 213
 # service              ironic     admin        # if enabled
214 214
 function create_ironic_accounts {
215 215
 
216
-    SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
217
-    ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
216
+    local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
217
+    local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
218 218
 
219 219
     # Ironic
220 220
     if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
221 221
         # Get ironic user if exists
222 222
 
223
-        IRONIC_USER=$(get_or_create_user "ironic" \
224
-            "$SERVICE_PASSWORD" $SERVICE_TENANT)
225
-        get_or_add_user_role $ADMIN_ROLE $IRONIC_USER $SERVICE_TENANT
223
+        local ironic_user=$(get_or_create_user "ironic" \
224
+            "$SERVICE_PASSWORD" $service_tenant)
225
+        get_or_add_user_role $admin_role $ironic_user $service_tenant
226 226
 
227 227
         if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
228 228
 
229
-            IRONIC_SERVICE=$(get_or_create_service "ironic" \
229
+            local ironic_service=$(get_or_create_service "ironic" \
230 230
                 "baremetal" "Ironic baremetal provisioning service")
231
-            get_or_create_endpoint $IRONIC_SERVICE \
231
+            get_or_create_endpoint $ironic_service \
232 232
                 "$REGION_NAME" \
233 233
                 "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
234 234
                 "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
... ...
@@ -300,15 +300,15 @@ function configure_ironic_dirs {
300 300
     sudo chown -R $STACK_USER $IRONIC_DATA_DIR $IRONIC_STATE_PATH
301 301
     sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_TFTPBOOT_DIR
302 302
     if is_ubuntu; then
303
-        PXEBIN=/usr/lib/syslinux/pxelinux.0
303
+        local pxebin=/usr/lib/syslinux/pxelinux.0
304 304
     elif is_fedora; then
305
-        PXEBIN=/usr/share/syslinux/pxelinux.0
305
+        local pxebin=/usr/share/syslinux/pxelinux.0
306 306
     fi
307
-    if [ ! -f $PXEBIN ]; then
307
+    if [ ! -f $pxebin ]; then
308 308
         die $LINENO "pxelinux.0 (from SYSLINUX) not found."
309 309
     fi
310 310
 
311
-    cp $PXEBIN $IRONIC_TFTPBOOT_DIR
311
+    cp $pxebin $IRONIC_TFTPBOOT_DIR
312 312
     mkdir -p $IRONIC_TFTPBOOT_DIR/pxelinux.cfg
313 313
 }
314 314
 
... ...
@@ -316,20 +316,20 @@ function create_bridge_and_vms {
316 316
     # Call libvirt setup scripts in a new shell to ensure any new group membership
317 317
     sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/setup-network"
318 318
     if [[ "$IRONIC_VM_LOG_CONSOLE" == "True" ]] ; then
319
-        LOG_ARG="$IRONIC_VM_LOG_DIR"
319
+        local log_arg="$IRONIC_VM_LOG_DIR"
320 320
     else
321
-        LOG_ARG=""
321
+        local log_arg=""
322 322
     fi
323 323
     sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-nodes \
324 324
         $IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \
325 325
         amd64 $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR \
326
-        $LOG_ARG" >> $IRONIC_VM_MACS_CSV_FILE
326
+        $log_arg" >> $IRONIC_VM_MACS_CSV_FILE
327 327
 }
328 328
 
329 329
 function enroll_vms {
330 330
 
331
-    CHASSIS_ID=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2)
332
-    IRONIC_NET_ID=$(neutron net-list | grep private | get_field 1)
331
+    local chassis_id=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2)
332
+    local ironic_net_id=$(neutron net-list | grep private | get_field 1)
333 333
     local idx=0
334 334
 
335 335
     # work around; need to know what netns neutron uses for private network.
... ...
@@ -338,11 +338,11 @@ function enroll_vms {
338 338
     # the instances operation. If we don't do this, the first port creation
339 339
     # only happens in the middle of fake baremetal instance's spawning by nova,
340 340
     # so we'll end up with unbootable fake baremetal VM due to broken PXE.
341
-    PORT_ID=$(neutron port-create private | grep " id " | get_field 2)
341
+    local port_id=$(neutron port-create private | grep " id " | get_field 2)
342 342
 
343 343
     while read MAC; do
344 344
 
345
-        NODE_ID=$(ironic node-create --chassis_uuid $CHASSIS_ID --driver pxe_ssh \
345
+        local node_id=$(ironic node-create --chassis_uuid $chassis_id --driver pxe_ssh \
346 346
             -i pxe_deploy_kernel=$IRONIC_DEPLOY_KERNEL_ID \
347 347
             -i pxe_deploy_ramdisk=$IRONIC_DEPLOY_RAMDISK_ID \
348 348
             -i ssh_virt_type=$IRONIC_SSH_VIRT_TYPE \
... ...
@@ -356,14 +356,14 @@ function enroll_vms {
356 356
             -p cpu_arch=x86_64 \
357 357
             | grep " uuid " | get_field 2)
358 358
 
359
-        ironic port-create --address $MAC --node_uuid $NODE_ID
359
+        ironic port-create --address $MAC --node_uuid $node_id
360 360
 
361 361
         idx=$((idx+1))
362 362
 
363 363
     done < $IRONIC_VM_MACS_CSV_FILE
364 364
 
365 365
     # create the nova flavor
366
-    adjusted_disk=$(($IRONIC_VM_SPECS_DISK - $IRONIC_VM_EPHEMERAL_DISK))
366
+    local adjusted_disk=$(($IRONIC_VM_SPECS_DISK - $IRONIC_VM_EPHEMERAL_DISK))
367 367
     nova flavor-create --ephemeral $IRONIC_VM_EPHEMERAL_DISK baremetal auto $IRONIC_VM_SPECS_RAM $adjusted_disk $IRONIC_VM_SPECS_CPU
368 368
     # TODO(lucasagomes): Remove the 'baremetal:deploy_kernel_id'
369 369
     # and 'baremetal:deploy_ramdisk_id' parameters
... ...
@@ -373,8 +373,8 @@ function enroll_vms {
373 373
 
374 374
     # intentional sleep to make sure the tag has been set to port
375 375
     sleep 10
376
-    TAPDEV=$(sudo ip netns exec qdhcp-${IRONIC_NET_ID} ip link list | grep tap | cut -d':' -f2 | cut -b2-)
377
-    TAG_ID=$(sudo ovs-vsctl show |grep ${TAPDEV} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-)
376
+    local tapdev=$(sudo ip netns exec qdhcp-${ironic_net_id} ip link list | grep tap | cut -d':' -f2 | cut -b2-)
377
+    local tag_id=$(sudo ovs-vsctl show |grep ${tapdev} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-)
378 378
 
379 379
     # make sure veth pair is not existing, otherwise delete its links
380 380
     sudo ip link show ovs-tap1 && sudo ip link delete ovs-tap1
... ...
@@ -384,12 +384,12 @@ function enroll_vms {
384 384
     sudo ip link set dev brbm-tap1 up
385 385
     sudo ip link set dev ovs-tap1 up
386 386
 
387
-    sudo ovs-vsctl -- --if-exists del-port ovs-tap1 -- add-port br-int ovs-tap1 tag=$TAG_ID
387
+    sudo ovs-vsctl -- --if-exists del-port ovs-tap1 -- add-port br-int ovs-tap1 tag=$tag_id
388 388
     sudo ovs-vsctl -- --if-exists del-port brbm-tap1 -- add-port $IRONIC_VM_NETWORK_BRIDGE brbm-tap1
389 389
 
390 390
     # Remove the port needed only for workaround. For additional info read the
391 391
     # comment at the beginning of this function
392
-    neutron port-delete $PORT_ID
392
+    neutron port-delete $port_id
393 393
 }
394 394
 
395 395
 function configure_iptables {
... ...
@@ -403,11 +403,11 @@ function configure_iptables {
403 403
 
404 404
 function configure_tftpd {
405 405
     if is_ubuntu; then
406
-        PXEBIN=/usr/lib/syslinux/pxelinux.0
406
+        local pxebin=/usr/lib/syslinux/pxelinux.0
407 407
     elif is_fedora; then
408
-        PXEBIN=/usr/share/syslinux/pxelinux.0
408
+        local pxebin=/usr/share/syslinux/pxelinux.0
409 409
     fi
410
-    if [ ! -f $PXEBIN ]; then
410
+    if [ ! -f $pxebin ]; then
411 411
         die $LINENO "pxelinux.0 (from SYSLINUX) not found."
412 412
     fi
413 413
 
... ...
@@ -440,12 +440,12 @@ function configure_ironic_ssh_keypair {
440 440
 }
441 441
 
442 442
 function ironic_ssh_check {
443
-    local KEY_FILE=$1
444
-    local FLOATING_IP=$2
445
-    local PORT=$3
446
-    local DEFAULT_INSTANCE_USER=$4
447
-    local ACTIVE_TIMEOUT=$5
448
-    if ! timeout $ACTIVE_TIMEOUT sh -c "while ! ssh -p $PORT -o StrictHostKeyChecking=no -i $KEY_FILE ${DEFAULT_INSTANCE_USER}@$FLOATING_IP echo success; do sleep 1; done"; then
443
+    local key_file=$1
444
+    local floating_ip=$2
445
+    local port=$3
446
+    local default_instance_user=$4
447
+    local active_timeout=$5
448
+    if ! timeout $active_timeout sh -c "while ! ssh -p $port -o StrictHostKeyChecking=no -i $key_file ${default_instance_user}@$floating_ip echo success; do sleep 1; done"; then
449 449
         die $LINENO "server didn't become ssh-able!"
450 450
     fi
451 451
 }
... ...
@@ -457,16 +457,17 @@ function configure_ironic_auxiliary {
457 457
 }
458 458
 
459 459
 # build deploy kernel+ramdisk, then upload them to glance
460
-# this function sets IRONIC_DEPLOY_KERNEL_ID and IRONIC_DEPLOY_RAMDISK_ID
460
+# this function sets ``IRONIC_DEPLOY_KERNEL_ID``, ``IRONIC_DEPLOY_RAMDISK_ID``
461 461
 function upload_baremetal_ironic_deploy {
462
-    token=$1
462
+    local token=$1
463
+    declare -g IRONIC_DEPLOY_KERNEL_ID IRONIC_DEPLOY_RAMDISK_ID
463 464
 
464 465
     if [ -z "$IRONIC_DEPLOY_KERNEL" -o -z "$IRONIC_DEPLOY_RAMDISK" ]; then
465
-        IRONIC_DEPLOY_KERNEL_PATH=$TOP_DIR/files/ir-deploy.kernel
466
-        IRONIC_DEPLOY_RAMDISK_PATH=$TOP_DIR/files/ir-deploy.initramfs
466
+        local IRONIC_DEPLOY_KERNEL_PATH=$TOP_DIR/files/ir-deploy.kernel
467
+        local IRONIC_DEPLOY_RAMDISK_PATH=$TOP_DIR/files/ir-deploy.initramfs
467 468
     else
468
-        IRONIC_DEPLOY_KERNEL_PATH=$IRONIC_DEPLOY_KERNEL
469
-        IRONIC_DEPLOY_RAMDISK_PATH=$IRONIC_DEPLOY_RAMDISK
469
+        local IRONIC_DEPLOY_KERNEL_PATH=$IRONIC_DEPLOY_KERNEL
470
+        local IRONIC_DEPLOY_RAMDISK_PATH=$IRONIC_DEPLOY_RAMDISK
470 471
     fi
471 472
 
472 473
     if [ ! -e "$IRONIC_DEPLOY_RAMDISK_PATH" -o ! -e "$IRONIC_DEPLOY_KERNEL_PATH" ]; then
... ...
@@ -507,19 +508,20 @@ function prepare_baremetal_basic_ops {
507 507
     git_clone $DIB_REPO $DIB_DIR $DIB_BRANCH
508 508
 
509 509
     # make sure all needed service were enabled
510
+    local srv
510 511
     for srv in nova glance key neutron; do
511 512
         if ! is_service_enabled "$srv"; then
512 513
             die $LINENO "$srv should be enabled for ironic tests"
513 514
         fi
514 515
     done
515 516
 
516
-    TOKEN=$(keystone token-get | grep ' id ' | get_field 2)
517
-    die_if_not_set $LINENO TOKEN "Keystone fail to get token"
517
+    local token=$(keystone token-get | grep ' id ' | get_field 2)
518
+    die_if_not_set $LINENO token "Keystone fail to get token"
518 519
 
519 520
     echo_summary "Creating and uploading baremetal images for ironic"
520 521
 
521 522
     # build and upload separate deploy kernel & ramdisk
522
-    upload_baremetal_ironic_deploy $TOKEN
523
+    upload_baremetal_ironic_deploy $token
523 524
 
524 525
     create_bridge_and_vms
525 526
     enroll_vms
... ...
@@ -535,9 +537,9 @@ function prepare_baremetal_basic_ops {
535 535
 function cleanup_baremetal_basic_ops {
536 536
     rm -f $IRONIC_VM_MACS_CSV_FILE
537 537
     if [ -f $IRONIC_KEY_FILE ]; then
538
-        KEY=`cat $IRONIC_KEY_FILE.pub`
538
+        local key=$(cat $IRONIC_KEY_FILE.pub)
539 539
         # remove public key from authorized_keys
540
-        grep -v "$KEY" $IRONIC_AUTHORIZED_KEYS_FILE > temp && mv temp $IRONIC_AUTHORIZED_KEYS_FILE
540
+        grep -v "$key" $IRONIC_AUTHORIZED_KEYS_FILE > temp && mv temp $IRONIC_AUTHORIZED_KEYS_FILE
541 541
         chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE
542 542
     fi
543 543
     sudo rm -rf $IRONIC_DATA_DIR $IRONIC_STATE_PATH