Browse code

Don't mix declaration and set of locals

Ia0957b47187c3dcadd46154b17022c4213781112 proposes to have bashate
find instances of setting a local value. The issue is that "local"
always returns 0, thus hiding any failure in the commands running to
set the variable.

This is an automated replacement of such instances

Depends-On: I676c805e8f0401f75cc5367eee83b3d880cdef81
Change-Id: I9c8912a8fd596535589b207d7fc553b9d951d3fe

Ian Wienand authored on 2015/10/07 12:06:26
Showing 30 changed files
... ...
@@ -122,41 +122,47 @@ function foreach_tenant_net {
122 122
 }
123 123
 
124 124
 function get_image_id {
125
-    local IMAGE_ID=$(openstack image list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
125
+    local IMAGE_ID
126
+    IMAGE_ID=$(openstack image list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
126 127
     die_if_not_set $LINENO IMAGE_ID "Failure retrieving IMAGE_ID"
127 128
     echo "$IMAGE_ID"
128 129
 }
129 130
 
130 131
 function get_tenant_id {
131 132
     local TENANT_NAME=$1
132
-    local TENANT_ID=`openstack project list | grep " $TENANT_NAME " | head -n 1 | get_field 1`
133
+    local TENANT_ID
134
+    TENANT_ID=`openstack project list | grep " $TENANT_NAME " | head -n 1 | get_field 1`
133 135
     die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for $TENANT_NAME"
134 136
     echo "$TENANT_ID"
135 137
 }
136 138
 
137 139
 function get_user_id {
138 140
     local USER_NAME=$1
139
-    local USER_ID=`openstack user list | grep $USER_NAME | awk '{print $2}'`
141
+    local USER_ID
142
+    USER_ID=`openstack user list | grep $USER_NAME | awk '{print $2}'`
140 143
     die_if_not_set $LINENO USER_ID "Failure retrieving USER_ID for $USER_NAME"
141 144
     echo "$USER_ID"
142 145
 }
143 146
 
144 147
 function get_role_id {
145 148
     local ROLE_NAME=$1
146
-    local ROLE_ID=`openstack role list | grep $ROLE_NAME | awk '{print $2}'`
149
+    local ROLE_ID
150
+    ROLE_ID=`openstack role list | grep $ROLE_NAME | awk '{print $2}'`
147 151
     die_if_not_set $LINENO ROLE_ID "Failure retrieving ROLE_ID for $ROLE_NAME"
148 152
     echo "$ROLE_ID"
149 153
 }
150 154
 
151 155
 function get_network_id {
152 156
     local NETWORK_NAME="$1"
153
-    local NETWORK_ID=`neutron net-list -F id  -- --name=$NETWORK_NAME | awk "NR==4" | awk '{print $2}'`
157
+    local NETWORK_ID
158
+    NETWORK_ID=`neutron net-list -F id  -- --name=$NETWORK_NAME | awk "NR==4" | awk '{print $2}'`
154 159
     echo $NETWORK_ID
155 160
 }
156 161
 
157 162
 function get_flavor_id {
158 163
     local INSTANCE_TYPE=$1
159
-    local FLAVOR_ID=`nova flavor-list | grep $INSTANCE_TYPE | awk '{print $2}'`
164
+    local FLAVOR_ID
165
+    FLAVOR_ID=`nova flavor-list | grep $INSTANCE_TYPE | awk '{print $2}'`
160 166
     die_if_not_set $LINENO FLAVOR_ID "Failure retrieving FLAVOR_ID for $INSTANCE_TYPE"
161 167
     echo "$FLAVOR_ID"
162 168
 }
... ...
@@ -185,13 +191,15 @@ function add_tenant {
185 185
 
186 186
 function remove_tenant {
187 187
     local TENANT=$1
188
-    local TENANT_ID=$(get_tenant_id $TENANT)
188
+    local TENANT_ID
189
+    TENANT_ID=$(get_tenant_id $TENANT)
189 190
     openstack project delete $TENANT_ID
190 191
 }
191 192
 
192 193
 function remove_user {
193 194
     local USER=$1
194
-    local USER_ID=$(get_user_id $USER)
195
+    local USER_ID
196
+    USER_ID=$(get_user_id $USER)
195 197
     openstack user delete $USER_ID
196 198
 }
197 199
 
... ...
@@ -221,9 +229,11 @@ function create_network {
221 221
     local NET_NAME="${TENANT}-net$NUM"
222 222
     local ROUTER_NAME="${TENANT}-router${NUM}"
223 223
     source $TOP_DIR/openrc admin admin
224
-    local TENANT_ID=$(get_tenant_id $TENANT)
224
+    local TENANT_ID
225
+    TENANT_ID=$(get_tenant_id $TENANT)
225 226
     source $TOP_DIR/openrc $TENANT $TENANT
226
-    local NET_ID=$(neutron net-create --tenant-id $TENANT_ID $NET_NAME $EXTRA| grep ' id ' | awk '{print $4}' )
227
+    local NET_ID
228
+    NET_ID=$(neutron net-create --tenant-id $TENANT_ID $NET_NAME $EXTRA| grep ' id ' | awk '{print $4}' )
227 229
     die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $TENANT_ID $NET_NAME $EXTRA"
228 230
     neutron subnet-create --ip-version 4 --tenant-id $TENANT_ID --gateway $GATEWAY $NET_ID $CIDR
229 231
     neutron_debug_admin probe-create --device-owner compute $NET_ID
... ...
@@ -251,7 +261,8 @@ function create_vm {
251 251
     done
252 252
     #TODO (nati) Add multi-nic test
253 253
     #TODO (nati) Add public-net test
254
-    local VM_UUID=`nova boot --flavor $(get_flavor_id m1.tiny) \
254
+    local VM_UUID
255
+    VM_UUID=`nova boot --flavor $(get_flavor_id m1.tiny) \
255 256
         --image $(get_image_id) \
256 257
         $NIC \
257 258
         $TENANT-server$NUM | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
... ...
@@ -309,7 +320,8 @@ function delete_network {
309 309
     local NUM=$2
310 310
     local NET_NAME="${TENANT}-net$NUM"
311 311
     source $TOP_DIR/openrc admin admin
312
-    local TENANT_ID=$(get_tenant_id $TENANT)
312
+    local TENANT_ID
313
+    TENANT_ID=$(get_tenant_id $TENANT)
313 314
     #TODO(nati) comment out until l3-agent merged
314 315
     #for res in port subnet net router;do
315 316
     for net_id in `neutron net-list -c id -c name | grep $NET_NAME | awk '{print $2}'`;do
... ...
@@ -264,7 +264,8 @@ function upload_image {
264 264
             ;;
265 265
         *.img)
266 266
             image_name=$(basename "$image" ".img")
267
-            local format=$(qemu-img info ${image} | awk '/^file format/ { print $3; exit }')
267
+            local format
268
+            format=$(qemu-img info ${image} | awk '/^file format/ { print $3; exit }')
268 269
             if [[ ",qcow2,raw,vdi,vmdk,vpc," =~ ",$format," ]]; then
269 270
                 disk_format=$format
270 271
             else
... ...
@@ -405,7 +406,8 @@ function get_instance_ip {
405 405
     local vm_id=$1
406 406
     local network_name=$2
407 407
     local nova_result="$(nova show $vm_id)"
408
-    local ip=$(echo "$nova_result" | grep "$network_name" | get_field 2)
408
+    local ip
409
+    ip=$(echo "$nova_result" | grep "$network_name" | get_field 2)
409 410
     if [[ $ip = "" ]];then
410 411
         echo "$nova_result"
411 412
         die $LINENO "[Fail] Coudn't get ipaddress of VM"
... ...
@@ -455,7 +457,8 @@ function check_path_perm_sanity {
455 455
     # homedir permissions on RHEL and common practice of making DEST in
456 456
     # the stack user's homedir.
457 457
 
458
-    local real_path=$(readlink -f $1)
458
+    local real_path
459
+    real_path=$(readlink -f $1)
459 460
     local rebuilt_path=""
460 461
     for i in $(echo ${real_path} | tr "/" " "); do
461 462
         rebuilt_path=$rebuilt_path"/"$i
... ...
@@ -140,7 +140,8 @@ function isset {
140 140
 # backtrace level
141 141
 function backtrace {
142 142
     local level=$1
143
-    local deep=$((${#BASH_SOURCE[@]} - 1))
143
+    local deep
144
+    deep=$((${#BASH_SOURCE[@]} - 1))
144 145
     echo "[Call Trace]"
145 146
     while [ $level -le $deep ]; do
146 147
         echo "${BASH_SOURCE[$deep]}:${BASH_LINENO[$deep-1]}:${FUNCNAME[$deep-1]}"
... ...
@@ -477,7 +478,8 @@ function git_clone {
477 477
     local git_remote=$1
478 478
     local git_dest=$2
479 479
     local git_ref=$3
480
-    local orig_dir=$(pwd)
480
+    local orig_dir
481
+    orig_dir=$(pwd)
481 482
     local git_clone_flags=""
482 483
 
483 484
     RECLONE=$(trueorfalse False RECLONE)
... ...
@@ -641,7 +643,8 @@ function get_default_host_ip {
641 641
         host_ip=""
642 642
         # Find the interface used for the default route
643 643
         host_ip_iface=${host_ip_iface:-$(ip -f $af route | awk '/default/ {print $5}' | head -1)}
644
-        local host_ips=$(LC_ALL=C ip -f $af addr show ${host_ip_iface} | sed /temporary/d |awk /$af'/ {split($2,parts,"/");  print parts[1]}')
644
+        local host_ips
645
+        host_ips=$(LC_ALL=C ip -f $af addr show ${host_ip_iface} | sed /temporary/d |awk /$af'/ {split($2,parts,"/");  print parts[1]}')
645 646
         local ip
646 647
         for ip in $host_ips; do
647 648
             # Attempt to filter out IP addresses that are part of the fixed and
... ...
@@ -690,7 +693,8 @@ function get_field {
690 690
 # copy over a default policy.json and policy.d for projects
691 691
 function install_default_policy {
692 692
     local project=$1
693
-    local project_uc=$(echo $1|tr a-z A-Z)
693
+    local project_uc
694
+    project_uc=$(echo $1|tr a-z A-Z)
694 695
     local conf_dir="${project_uc}_CONF_DIR"
695 696
     # eval conf dir to get the variable
696 697
     conf_dir="${!conf_dir}"
... ...
@@ -723,7 +727,8 @@ function policy_add {
723 723
 
724 724
     # Add a terminating comma to policy lines without one
725 725
     # Remove the closing '}' and all lines following to the end-of-file
726
-    local tmpfile=$(mktemp)
726
+    local tmpfile
727
+    tmpfile=$(mktemp)
727 728
     uniq ${policy_file} | sed -e '
728 729
         s/]$/],/
729 730
         /^[}]/,$d
... ...
@@ -945,7 +950,8 @@ function get_or_create_endpoint {
945 945
     # scenarios currently that use the returned id. Ideally this behaviour
946 946
     # should be pushed out to the service setups and let them create the
947 947
     # endpoints they need.
948
-    local public_id=$(_get_or_create_endpoint_with_interface $1 public $3 $2)
948
+    local public_id
949
+    public_id=$(_get_or_create_endpoint_with_interface $1 public $3 $2)
949 950
     _get_or_create_endpoint_with_interface $1 admin $4 $2
950 951
     _get_or_create_endpoint_with_interface $1 internal $5 $2
951 952
 
... ...
@@ -1065,7 +1071,8 @@ function get_packages {
1065 1065
     xtrace=$(set +o | grep xtrace)
1066 1066
     set +o xtrace
1067 1067
     local services=$@
1068
-    local package_dir=$(_get_package_dir)
1068
+    local package_dir
1069
+    package_dir=$(_get_package_dir)
1069 1070
     local file_to_parse=""
1070 1071
     local service=""
1071 1072
 
... ...
@@ -1980,8 +1987,10 @@ function address_in_net {
1980 1980
     local ip=$1
1981 1981
     local range=$2
1982 1982
     local masklen=${range#*/}
1983
-    local network=$(maskip ${range%/*} $(cidr2netmask $masklen))
1984
-    local subnet=$(maskip $ip $(cidr2netmask $masklen))
1983
+    local network
1984
+    network=$(maskip ${range%/*} $(cidr2netmask $masklen))
1985
+    local subnet
1986
+    subnet=$(maskip $ip $(cidr2netmask $masklen))
1985 1987
     [[ $network == $subnet ]]
1986 1988
 }
1987 1989
 
... ...
@@ -2033,7 +2042,8 @@ function export_proxy_variables {
2033 2033
 
2034 2034
 # Returns true if the directory is on a filesystem mounted via NFS.
2035 2035
 function is_nfs_directory {
2036
-    local mount_type=`stat -f -L -c %T $1`
2036
+    local mount_type
2037
+    mount_type=`stat -f -L -c %T $1`
2037 2038
     test "$mount_type" == "nfs"
2038 2039
 }
2039 2040
 
... ...
@@ -2044,13 +2054,15 @@ function maskip {
2044 2044
     local ip=$1
2045 2045
     local mask=$2
2046 2046
     local l="${ip%.*}"; local r="${ip#*.}"; local n="${mask%.*}"; local m="${mask#*.}"
2047
-    local subnet=$((${ip%%.*}&${mask%%.*})).$((${r%%.*}&${m%%.*})).$((${l##*.}&${n##*.})).$((${ip##*.}&${mask##*.}))
2047
+    local subnet
2048
+    subnet=$((${ip%%.*}&${mask%%.*})).$((${r%%.*}&${m%%.*})).$((${l##*.}&${n##*.})).$((${ip##*.}&${mask##*.}))
2048 2049
     echo $subnet
2049 2050
 }
2050 2051
 
2051 2052
 # Return the current python as "python<major>.<minor>"
2052 2053
 function python_version {
2053
-    local python_version=$(python -c 'import sys; print("%s.%s" % sys.version_info[0:2])')
2054
+    local python_version
2055
+    python_version=$(python -c 'import sys; print("%s.%s" % sys.version_info[0:2])')
2054 2056
     echo "python${python_version}"
2055 2057
 }
2056 2058
 
... ...
@@ -196,7 +196,8 @@ function iniset {
196 196
 $option = $value
197 197
 " "$file"
198 198
     else
199
-        local sep=$(echo -ne "\x01")
199
+        local sep
200
+        sep=$(echo -ne "\x01")
200 201
         # Replace it
201 202
         $sudo sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('${option}'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file"
202 203
     fi
... ...
@@ -89,7 +89,8 @@ function merge_config_file {
89 89
     # note, configfile might be a variable (note the iniset, etc
90 90
     # created in the mega-awk below is "eval"ed too, so we just leave
91 91
     # it alone.
92
-    local real_configfile=$(eval echo $configfile)
92
+    local real_configfile
93
+    real_configfile=$(eval echo $configfile)
93 94
     if [ ! -f $real_configfile ]; then
94 95
         touch $real_configfile
95 96
     fi
... ...
@@ -61,7 +61,8 @@ function get_python_exec_prefix {
61 61
 # pip_install_gr packagename
62 62
 function pip_install_gr {
63 63
     local name=$1
64
-    local clean_name=$(get_from_global_requirements $name)
64
+    local clean_name
65
+    clean_name=$(get_from_global_requirements $name)
65 66
     pip_install $clean_name
66 67
 }
67 68
 
... ...
@@ -100,7 +101,8 @@ function pip_install {
100 100
             local cmd_pip=$PIP_VIRTUAL_ENV/bin/pip
101 101
             local sudo_pip="env"
102 102
         else
103
-            local cmd_pip=$(get_pip_command)
103
+            local cmd_pip
104
+            cmd_pip=$(get_pip_command)
104 105
             local sudo_pip="sudo -H"
105 106
         fi
106 107
     fi
... ...
@@ -109,7 +111,8 @@ function pip_install {
109 109
     # Always apply constraints
110 110
     cmd_pip="$cmd_pip -c $REQUIREMENTS_DIR/upper-constraints.txt"
111 111
 
112
-    local pip_version=$(python -c "import pip; \
112
+    local pip_version
113
+    pip_version=$(python -c "import pip; \
113 114
                         print(pip.__version__.strip('.')[0])")
114 115
     if (( pip_version<6 )); then
115 116
         die $LINENO "Currently installed pip version ${pip_version} does not" \
... ...
@@ -143,7 +146,8 @@ function pip_install {
143 143
 # get_from_global_requirements <package>
144 144
 function get_from_global_requirements {
145 145
     local package=$1
146
-    local required_pkg=$(grep -i -h ^${package} $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
146
+    local required_pkg
147
+    required_pkg=$(grep -i -h ^${package} $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
147 148
     if [[ $required_pkg == ""  ]]; then
148 149
         die $LINENO "Can't find package $package in requirements"
149 150
     fi
... ...
@@ -222,7 +226,8 @@ function setup_develop {
222 222
 # practical ways.
223 223
 function is_in_projects_txt {
224 224
     local project_dir=$1
225
-    local project_name=$(basename $project_dir)
225
+    local project_name
226
+    project_name=$(basename $project_dir)
226 227
     grep -q "/$project_name\$" $REQUIREMENTS_DIR/projects.txt
227 228
 }
228 229
 
... ...
@@ -241,7 +246,8 @@ function setup_package_with_constraints_edit {
241 241
 
242 242
     if [ -n "$REQUIREMENTS_DIR" ]; then
243 243
         # Constrain this package to this project directory from here on out.
244
-        local name=$(awk '/^name.*=/ {print $3}' $project_dir/setup.cfg)
244
+        local name
245
+        name=$(awk '/^name.*=/ {print $3}' $project_dir/setup.cfg)
245 246
         $REQUIREMENTS_DIR/.venv/bin/edit-constraints \
246 247
             $REQUIREMENTS_DIR/upper-constraints.txt -- $name \
247 248
             "$flags file://$project_dir#egg=$name"
... ...
@@ -41,7 +41,8 @@ function add_sudo_secure_path {
41 41
 # configure_rootwrap project
42 42
 function configure_rootwrap {
43 43
     local project=$1
44
-    local project_uc=$(echo $1|tr a-z A-Z)
44
+    local project_uc
45
+    project_uc=$(echo $1|tr a-z A-Z)
45 46
     local bin_dir="${project_uc}_BIN_DIR"
46 47
     bin_dir="${!bin_dir}"
47 48
     local project_dir="${project_uc}_DIR"
... ...
@@ -60,7 +61,8 @@ function configure_rootwrap {
60 60
     sudo sed -e "s:^filters_path=.*$:filters_path=/etc/${project}/rootwrap.d:" -i /etc/${project}/rootwrap.conf
61 61
 
62 62
     # Set up the rootwrap sudoers
63
-    local tempfile=$(mktemp)
63
+    local tempfile
64
+    tempfile=$(mktemp)
64 65
     # Specify rootwrap.conf as first parameter to rootwrap
65 66
     rootwrap_sudo_cmd="${rootwrap_bin} /etc/${project}/rootwrap.conf *"
66 67
     echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_sudo_cmd" >$tempfile
... ...
@@ -72,11 +72,14 @@ function install_apache_wsgi {
72 72
 # various differences between Apache 2.2 and 2.4 that warrant special handling.
73 73
 function get_apache_version {
74 74
     if is_ubuntu; then
75
-        local version_str=$(sudo /usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/)
75
+        local version_str
76
+        version_str=$(sudo /usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/)
76 77
     elif is_fedora; then
77
-        local version_str=$(rpm -qa --queryformat '%{VERSION}' httpd)
78
+        local version_str
79
+        version_str=$(rpm -qa --queryformat '%{VERSION}' httpd)
78 80
     elif is_suse; then
79
-        local version_str=$(rpm -qa --queryformat '%{VERSION}' apache2)
81
+        local version_str
82
+        version_str=$(rpm -qa --queryformat '%{VERSION}' apache2)
80 83
     else
81 84
         exit_distro_not_supported "cannot determine apache version"
82 85
     fi
... ...
@@ -115,7 +118,8 @@ function get_apache_version {
115 115
 function apache_site_config_for {
116 116
     local site=$@
117 117
     if is_ubuntu; then
118
-        local apache_version=$(get_apache_version)
118
+        local apache_version
119
+        apache_version=$(get_apache_version)
119 120
         if [[ "$apache_version" == "2.2" ]]; then
120 121
             # Ubuntu 12.04 - Apache 2.2
121 122
             echo $APACHE_CONF_DIR/${site}
... ...
@@ -83,7 +83,8 @@ ATTACH_ENCRYPTED_VOLUME_AVAILABLE=False
83 83
 # ------------
84 84
 
85 85
 function get_ceph_version {
86
-    local ceph_version_str=$(sudo ceph daemon mon.$(hostname) version | cut -d '"' -f 4 | cut -f 1,2 -d '.')
86
+    local ceph_version_str
87
+    ceph_version_str=$(sudo ceph daemon mon.$(hostname) version | cut -d '"' -f 4 | cut -f 1,2 -d '.')
87 88
     echo $ceph_version_str
88 89
 }
89 90
 
... ...
@@ -106,7 +107,8 @@ EOF
106 106
 # undefine_virsh_secret() - Undefine Cinder key secret from libvirt
107 107
 function undefine_virsh_secret {
108 108
     if is_service_enabled cinder || is_service_enabled nova; then
109
-        local virsh_uuid=$(sudo virsh secret-list | awk '/^ ?[0-9a-z]/ { print $1 }')
109
+        local virsh_uuid
110
+        virsh_uuid=$(sudo virsh secret-list | awk '/^ ?[0-9a-z]/ { print $1 }')
110 111
         sudo virsh secret-undefine ${virsh_uuid} >/dev/null 2>&1
111 112
     fi
112 113
 }
... ...
@@ -219,7 +221,8 @@ EOF
219 219
     done
220 220
 
221 221
     # pools data and metadata were removed in the Giant release so depending on the version we apply different commands
222
-    local ceph_version=$(get_ceph_version)
222
+    local ceph_version
223
+    ceph_version=$(get_ceph_version)
223 224
     # change pool replica size according to the CEPH_REPLICAS set by the user
224 225
     if [[ ${ceph_version%%.*} -eq 0 ]] && [[ ${ceph_version##*.} -lt 87 ]]; then
225 226
         sudo ceph -c ${CEPH_CONF_FILE} osd pool set rbd size ${CEPH_REPLICAS}
... ...
@@ -150,7 +150,8 @@ function cleanup_cinder {
150 150
     # ensure the volume group is cleared up because fails might
151 151
     # leave dead volumes in the group
152 152
     if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
153
-        local targets=$(sudo tgtadm --op show --mode target)
153
+        local targets
154
+        targets=$(sudo tgtadm --op show --mode target)
154 155
         if [ $? -ne 0 ]; then
155 156
             # If tgt driver isn't running this won't work obviously
156 157
             # So check the response and restart if need be
... ...
@@ -198,7 +199,8 @@ function cleanup_cinder {
198 198
 
199 199
 # _cinder_config_apache_wsgi() - Set WSGI config files
200 200
 function _cinder_config_apache_wsgi {
201
-    local cinder_apache_conf=$(apache_site_config_for osapi-volume)
201
+    local cinder_apache_conf
202
+    cinder_apache_conf=$(apache_site_config_for osapi-volume)
202 203
     local cinder_ssl=""
203 204
     local cinder_certfile=""
204 205
     local cinder_keyfile=""
... ...
@@ -106,7 +106,8 @@ function configure_glance {
106 106
     iniset $GLANCE_REGISTRY_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
107 107
     iniset $GLANCE_REGISTRY_CONF DEFAULT bind_host $GLANCE_SERVICE_LISTEN_ADDRESS
108 108
     inicomment $GLANCE_REGISTRY_CONF DEFAULT log_file
109
-    local dburl=`database_connection_url glance`
109
+    local dburl
110
+    dburl=`database_connection_url glance`
110 111
     iniset $GLANCE_REGISTRY_CONF database connection $dburl
111 112
     iniset $GLANCE_REGISTRY_CONF DEFAULT use_syslog $SYSLOG
112 113
     iniset $GLANCE_REGISTRY_CONF DEFAULT workers "$API_WORKERS"
... ...
@@ -265,7 +266,8 @@ function create_glance_accounts {
265 265
         # required for swift access
266 266
         if is_service_enabled s-proxy; then
267 267
 
268
-            local glance_swift_user=$(get_or_create_user "glance-swift" \
268
+            local glance_swift_user
269
+            glance_swift_user=$(get_or_create_user "glance-swift" \
269 270
                 "$SERVICE_PASSWORD" "default" "glance-swift@example.com")
270 271
             get_or_add_user_project_role "ResellerAdmin" $glance_swift_user $SERVICE_TENANT_NAME
271 272
         fi
... ...
@@ -321,7 +321,8 @@ function build_heat_pip_mirror {
321 321
 
322 322
     echo "</body></html>" >> $HEAT_PIP_REPO/index.html
323 323
 
324
-    local heat_pip_repo_apache_conf=$(apache_site_config_for heat_pip_repo)
324
+    local heat_pip_repo_apache_conf
325
+    heat_pip_repo_apache_conf=$(apache_site_config_for heat_pip_repo)
325 326
 
326 327
     sudo cp $FILES/apache-heat-pip-repo.template $heat_pip_repo_apache_conf
327 328
     sudo sed -e "
... ...
@@ -49,7 +49,8 @@ function _horizon_config_set {
49 49
         sed -e "/^$option/d" -i $local_settings
50 50
         echo -e "\n$option=$value" >> $file
51 51
     elif grep -q "^$section" $file; then
52
-        local line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
52
+        local line
53
+        line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
53 54
         if [ -n "$line" ]; then
54 55
             sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
55 56
         else
... ...
@@ -68,7 +69,8 @@ function _horizon_config_set {
68 68
 # cleanup_horizon() - Remove residual data files, anything left over from previous
69 69
 # runs that a clean run would need to clean up
70 70
 function cleanup_horizon {
71
-    local horizon_conf=$(apache_site_config_for horizon)
71
+    local horizon_conf
72
+    horizon_conf=$(apache_site_config_for horizon)
72 73
     sudo rm -f $horizon_conf
73 74
 }
74 75
 
... ...
@@ -112,7 +114,8 @@ function init_horizon {
112 112
     # Create an empty directory that apache uses as docroot
113 113
     sudo mkdir -p $HORIZON_DIR/.blackhole
114 114
 
115
-    local horizon_conf=$(apache_site_config_for horizon)
115
+    local horizon_conf
116
+    horizon_conf=$(apache_site_config_for horizon)
116 117
 
117 118
     # Configure apache to run horizon
118 119
     sudo sh -c "sed -e \"
... ...
@@ -225,7 +225,8 @@ function _cleanup_ironic_apache_wsgi {
225 225
 
226 226
 # _config_ironic_apache_wsgi() - Set WSGI config files of Ironic
227 227
 function _config_ironic_apache_wsgi {
228
-    local ironic_apache_conf=$(apache_site_config_for ironic)
228
+    local ironic_apache_conf
229
+    ironic_apache_conf=$(apache_site_config_for ironic)
229 230
     sudo cp $FILES/apache-ironic.template $ironic_apache_conf
230 231
     sudo sed -e "
231 232
         s|%PUBLICPORT%|$IRONIC_HTTP_PORT|g;
... ...
@@ -325,11 +326,13 @@ function configure_ironic_api {
325 325
 function configure_ironic_conductor {
326 326
     cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
327 327
     cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR
328
-    local ironic_rootwrap=$(get_rootwrap_location ironic)
328
+    local ironic_rootwrap
329
+    ironic_rootwrap=$(get_rootwrap_location ironic)
329 330
     local rootwrap_isudoer_cmd="$ironic_rootwrap $IRONIC_CONF_DIR/rootwrap.conf *"
330 331
 
331 332
     # Set up the rootwrap sudoers for ironic
332
-    local tempfile=`mktemp`
333
+    local tempfile
334
+    tempfile=`mktemp`
333 335
     echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_isudoer_cmd" >$tempfile
334 336
     chmod 0440 $tempfile
335 337
     sudo chown root:root $tempfile
... ...
@@ -370,7 +373,8 @@ function configure_ironic_conductor {
370 370
         fi
371 371
         iniset $IRONIC_CONF_FILE glance swift_endpoint_url http://${HOST_IP}:${SWIFT_DEFAULT_BIND_PORT:-8080}
372 372
         iniset $IRONIC_CONF_FILE glance swift_api_version v1
373
-        local tenant_id=$(get_or_create_project $SERVICE_TENANT_NAME default)
373
+        local tenant_id
374
+        tenant_id=$(get_or_create_project $SERVICE_TENANT_NAME default)
374 375
         iniset $IRONIC_CONF_FILE glance swift_account AUTH_${tenant_id}
375 376
         iniset $IRONIC_CONF_FILE glance swift_container glance
376 377
         iniset $IRONIC_CONF_FILE glance swift_temp_url_duration 3600
... ...
@@ -379,7 +383,8 @@ function configure_ironic_conductor {
379 379
     fi
380 380
 
381 381
     if [[ "$IRONIC_IPXE_ENABLED" == "True" ]] ; then
382
-        local pxebin=`basename $IRONIC_PXE_BOOT_IMAGE`
382
+        local pxebin
383
+        pxebin=`basename $IRONIC_PXE_BOOT_IMAGE`
383 384
         iniset $IRONIC_CONF_FILE pxe ipxe_enabled True
384 385
         iniset $IRONIC_CONF_FILE pxe pxe_config_template '\$pybasedir/drivers/modules/ipxe_config.template'
385 386
         iniset $IRONIC_CONF_FILE pxe pxe_bootfile_name $pxebin
... ...
@@ -445,7 +450,8 @@ function init_ironic {
445 445
 # _ironic_bm_vm_names() - Generates list of names for baremetal VMs.
446 446
 function _ironic_bm_vm_names {
447 447
     local idx
448
-    local num_vms=$(($IRONIC_VM_COUNT - 1))
448
+    local num_vms
449
+    num_vms=$(($IRONIC_VM_COUNT - 1))
449 450
     for idx in $(seq 0 $num_vms); do
450 451
         echo "baremetal${IRONIC_VM_NETWORK_BRIDGE}_${idx}"
451 452
     done
... ...
@@ -498,22 +504,27 @@ function stop_ironic {
498 498
 }
499 499
 
500 500
 function create_ovs_taps {
501
-    local ironic_net_id=$(neutron net-list | grep private | get_field 1)
501
+    local ironic_net_id
502
+    ironic_net_id=$(neutron net-list | grep private | get_field 1)
502 503
 
503 504
     # Work around: No netns exists on host until a Neutron port is created.  We
504 505
     # need to create one in Neutron to know what netns to tap into prior to the
505 506
     # first node booting.
506
-    local port_id=$(neutron port-create private | grep " id " | get_field 2)
507
+    local port_id
508
+    port_id=$(neutron port-create private | grep " id " | get_field 2)
507 509
 
508 510
     # intentional sleep to make sure the tag has been set to port
509 511
     sleep 10
510 512
 
511 513
     if  [[ "$Q_USE_NAMESPACE" = "True" ]]; then
512
-        local tapdev=$(sudo ip netns exec qdhcp-${ironic_net_id} ip link list | grep " tap" | cut -d':' -f2 | cut -d'@' -f1 | cut -b2-)
514
+        local tapdev
515
+        tapdev=$(sudo ip netns exec qdhcp-${ironic_net_id} ip link list | grep " tap" | cut -d':' -f2 | cut -d'@' -f1 | cut -b2-)
513 516
     else
514
-        local tapdev=$(sudo ip link list | grep " tap" | cut -d':' -f2 | cut -d'@' -f1 | cut -b2-)
517
+        local tapdev
518
+        tapdev=$(sudo ip link list | grep " tap" | cut -d':' -f2 | cut -d'@' -f1 | cut -b2-)
515 519
     fi
516
-    local tag_id=$(sudo ovs-vsctl show |grep ${tapdev} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-)
520
+    local tag_id
521
+    tag_id=$(sudo ovs-vsctl show |grep ${tapdev} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-)
517 522
 
518 523
     # make sure veth pair is not existing, otherwise delete its links
519 524
     sudo ip link show ovs-tap1 && sudo ip link delete ovs-tap1
... ...
@@ -570,7 +581,8 @@ function wait_for_nova_resources {
570 570
 }
571 571
 
572 572
 function enroll_nodes {
573
-    local chassis_id=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2)
573
+    local chassis_id
574
+    chassis_id=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2)
574 575
 
575 576
     if ! is_ironic_hardware; then
576 577
         local ironic_node_cpu=$IRONIC_VM_SPECS_CPU
... ...
@@ -602,10 +614,14 @@ function enroll_nodes {
602 602
         if ! is_ironic_hardware; then
603 603
             local mac_address=$hardware_info
604 604
         elif [[ -z "${IRONIC_DEPLOY_DRIVER##*_ipmitool}" ]]; then
605
-            local ipmi_address=$(echo $hardware_info |awk  '{print $1}')
606
-            local mac_address=$(echo $hardware_info |awk '{print $2}')
607
-            local ironic_ipmi_username=$(echo $hardware_info |awk '{print $3}')
608
-            local ironic_ipmi_passwd=$(echo $hardware_info |awk '{print $4}')
605
+            local ipmi_address
606
+            ipmi_address=$(echo $hardware_info |awk  '{print $1}')
607
+            local mac_address
608
+            mac_address=$(echo $hardware_info |awk '{print $2}')
609
+            local ironic_ipmi_username
610
+            ironic_ipmi_username=$(echo $hardware_info |awk '{print $3}')
611
+            local ironic_ipmi_passwd
612
+            ironic_ipmi_passwd=$(echo $hardware_info |awk '{print $4}')
609 613
             # Currently we require all hardware platform have same CPU/RAM/DISK info
610 614
             # in future, this can be enhanced to support different type, and then
611 615
             # we create the bare metal flavor with minimum value
... ...
@@ -617,9 +633,11 @@ function enroll_nodes {
617 617
 
618 618
         # First node created will be used for testing in ironic w/o glance
619 619
         # scenario, so we need to know its UUID.
620
-        local standalone_node_uuid=$([ $total_nodes -eq 0 ] && echo "--uuid $IRONIC_NODE_UUID")
620
+        local standalone_node_uuid
621
+        standalone_node_uuid=$([ $total_nodes -eq 0 ] && echo "--uuid $IRONIC_NODE_UUID")
621 622
 
622
-        local node_id=$(ironic node-create $standalone_node_uuid\
623
+        local node_id
624
+        node_id=$(ironic node-create $standalone_node_uuid\
623 625
             --chassis_uuid $chassis_id \
624 626
             --driver $IRONIC_DEPLOY_DRIVER \
625 627
             --name node-$total_nodes \
... ...
@@ -640,7 +658,8 @@ function enroll_nodes {
640 640
     # NOTE(adam_g): Attempting to use an autogenerated UUID for flavor id here uncovered
641 641
     # bug (LP: #1333852) in Trove.  This can be changed to use an auto flavor id when the
642 642
     # bug is fixed in Juno.
643
-    local adjusted_disk=$(($ironic_node_disk - $ironic_ephemeral_disk))
643
+    local adjusted_disk
644
+    adjusted_disk=$(($ironic_node_disk - $ironic_ephemeral_disk))
644 645
     nova flavor-create --ephemeral $ironic_ephemeral_disk baremetal 551 $ironic_node_ram $adjusted_disk $ironic_node_cpu
645 646
 
646 647
     nova flavor-key baremetal set "cpu_arch"="x86_64"
... ...
@@ -771,7 +790,8 @@ function upload_baremetal_ironic_deploy {
771 771
         fi
772 772
     fi
773 773
 
774
-    local token=$(openstack token issue -c id -f value)
774
+    local token
775
+    token=$(openstack token issue -c id -f value)
775 776
     die_if_not_set $LINENO token "Keystone fail to get token"
776 777
 
777 778
     # load them into glance
... ...
@@ -809,7 +829,8 @@ function prepare_baremetal_basic_ops {
809 809
 function cleanup_baremetal_basic_ops {
810 810
     rm -f $IRONIC_VM_MACS_CSV_FILE
811 811
     if [ -f $IRONIC_KEY_FILE ]; then
812
-        local key=$(cat $IRONIC_KEY_FILE.pub)
812
+        local key
813
+        key=$(cat $IRONIC_KEY_FILE.pub)
813 814
         # remove public key from authorized_keys
814 815
         grep -v "$key" $IRONIC_AUTHORIZED_KEYS_FILE > temp && mv temp $IRONIC_AUTHORIZED_KEYS_FILE
815 816
         chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE
... ...
@@ -132,7 +132,8 @@ function _cleanup_keystone_apache_wsgi {
132 132
 
133 133
 # _config_keystone_apache_wsgi() - Set WSGI config files of Keystone
134 134
 function _config_keystone_apache_wsgi {
135
-    local keystone_apache_conf=$(apache_site_config_for keystone)
135
+    local keystone_apache_conf
136
+    keystone_apache_conf=$(apache_site_config_for keystone)
136 137
     local keystone_ssl=""
137 138
     local keystone_certfile=""
138 139
     local keystone_keyfile=""
... ...
@@ -347,9 +348,12 @@ function configure_keystone_extensions {
347 347
 function create_keystone_accounts {
348 348
 
349 349
     # admin
350
-    local admin_tenant=$(get_or_create_project "admin" default)
351
-    local admin_user=$(get_or_create_user "admin" "$ADMIN_PASSWORD" default)
352
-    local admin_role=$(get_or_create_role "admin")
350
+    local admin_tenant
351
+    admin_tenant=$(get_or_create_project "admin" default)
352
+    local admin_user
353
+    admin_user=$(get_or_create_user "admin" "$ADMIN_PASSWORD" default)
354
+    local admin_role
355
+    admin_role=$(get_or_create_role "admin")
353 356
     get_or_add_user_project_role $admin_role $admin_user $admin_tenant
354 357
 
355 358
     # Create service project/role
... ...
@@ -365,18 +369,23 @@ function create_keystone_accounts {
365 365
     get_or_create_role ResellerAdmin
366 366
 
367 367
     # The Member role is used by Horizon and Swift so we need to keep it:
368
-    local member_role=$(get_or_create_role "Member")
368
+    local member_role
369
+    member_role=$(get_or_create_role "Member")
369 370
 
370 371
     # another_role demonstrates that an arbitrary role may be created and used
371 372
     # TODO(sleepsonthefloor): show how this can be used for rbac in the future!
372
-    local another_role=$(get_or_create_role "anotherrole")
373
+    local another_role
374
+    another_role=$(get_or_create_role "anotherrole")
373 375
 
374 376
     # invisible tenant - admin can't see this one
375
-    local invis_tenant=$(get_or_create_project "invisible_to_admin" default)
377
+    local invis_tenant
378
+    invis_tenant=$(get_or_create_project "invisible_to_admin" default)
376 379
 
377 380
     # demo
378
-    local demo_tenant=$(get_or_create_project "demo" default)
379
-    local demo_user=$(get_or_create_user "demo" \
381
+    local demo_tenant
382
+    demo_tenant=$(get_or_create_project "demo" default)
383
+    local demo_user
384
+    demo_user=$(get_or_create_user "demo" \
380 385
         "$ADMIN_PASSWORD" "default" "demo@example.com")
381 386
 
382 387
     get_or_add_user_project_role $member_role $demo_user $demo_tenant
... ...
@@ -384,9 +393,11 @@ function create_keystone_accounts {
384 384
     get_or_add_user_project_role $another_role $demo_user $demo_tenant
385 385
     get_or_add_user_project_role $member_role $demo_user $invis_tenant
386 386
 
387
-    local admin_group=$(get_or_create_group "admins" \
387
+    local admin_group
388
+    admin_group=$(get_or_create_group "admins" \
388 389
         "default" "openstack admin group")
389
-    local non_admin_group=$(get_or_create_group "nonadmins" \
390
+    local non_admin_group
391
+    non_admin_group=$(get_or_create_group "nonadmins" \
390 392
         "default" "non-admin group")
391 393
 
392 394
     get_or_add_group_project_role $member_role $non_admin_group $demo_tenant
... ...
@@ -415,7 +426,8 @@ function create_keystone_accounts {
415 415
 function create_service_user {
416 416
     local role=${2:-service}
417 417
 
418
-    local user=$(get_or_create_user "$1" "$SERVICE_PASSWORD" default)
418
+    local user
419
+    user=$(get_or_create_user "$1" "$SERVICE_PASSWORD" default)
419 420
     get_or_add_user_project_role "$role" "$user" "$SERVICE_TENANT_NAME"
420 421
 }
421 422
 
... ...
@@ -82,7 +82,8 @@ function cleanup_ldap {
82 82
 function init_ldap {
83 83
     local keystone_ldif
84 84
 
85
-    local tmp_ldap_dir=$(mktemp -d -t ldap.$$.XXXXXXXXXX)
85
+    local tmp_ldap_dir
86
+    tmp_ldap_dir=$(mktemp -d -t ldap.$$.XXXXXXXXXX)
86 87
 
87 88
     # Remove data but not schemas
88 89
     clear_ldap_state
... ...
@@ -113,7 +114,8 @@ function install_ldap {
113 113
     echo "Installing LDAP inside function"
114 114
     echo "os_VENDOR is $os_VENDOR"
115 115
 
116
-    local tmp_ldap_dir=$(mktemp -d -t ldap.$$.XXXXXXXXXX)
116
+    local tmp_ldap_dir
117
+    tmp_ldap_dir=$(mktemp -d -t ldap.$$.XXXXXXXXXX)
117 118
 
118 119
     printf "installing OpenLDAP"
119 120
     if is_ubuntu; then
... ...
@@ -129,7 +131,8 @@ function install_ldap {
129 129
     fi
130 130
 
131 131
     echo "LDAP_PASSWORD is $LDAP_PASSWORD"
132
-    local slappass=$(slappasswd -s $LDAP_PASSWORD)
132
+    local slappass
133
+    slappass=$(slappasswd -s $LDAP_PASSWORD)
133 134
     printf "LDAP secret is $slappass\n"
134 135
 
135 136
     # Create manager.ldif and add to olcdb
... ...
@@ -56,7 +56,8 @@ function _clean_lvm_backing_file {
56 56
 
57 57
     # If the backing physical device is a loop device, it was probably setup by DevStack
58 58
     if [[ -n "$backing_file" ]] && [[ -e "$backing_file" ]]; then
59
-        local vg_dev=$(sudo losetup -j $backing_file | awk -F':' '/'$BACKING_FILE_SUFFIX'/ { print $1}')
59
+        local vg_dev
60
+        vg_dev=$(sudo losetup -j $backing_file | awk -F':' '/'$BACKING_FILE_SUFFIX'/ { print $1}')
60 61
         sudo losetup -d $vg_dev
61 62
         rm -f $backing_file
62 63
     fi
... ...
@@ -89,7 +90,8 @@ function _create_lvm_volume_group {
89 89
     if ! sudo vgs $vg; then
90 90
         # Only create if the file doesn't already exists
91 91
         [[ -f $backing_file ]] || truncate -s $size $backing_file
92
-        local vg_dev=`sudo losetup -f --show $backing_file`
92
+        local vg_dev
93
+        vg_dev=`sudo losetup -f --show $backing_file`
93 94
 
94 95
         # Only create volume group if it doesn't already exist
95 96
         if ! sudo vgs $vg; then
... ...
@@ -806,7 +806,8 @@ function _move_neutron_addresses_route {
806 806
 
807 807
         local IP_ADD=""
808 808
         local IP_DEL=""
809
-        local DEFAULT_ROUTE_GW=$(ip r | awk "/default.+$from_intf/ { print \$3; exit }")
809
+        local DEFAULT_ROUTE_GW
810
+        DEFAULT_ROUTE_GW=$(ip r | awk "/default.+$from_intf/ { print \$3; exit }")
810 811
         local ADD_OVS_PORT=""
811 812
 
812 813
         if [[ $af == "inet" ]]; then
... ...
@@ -1244,7 +1245,8 @@ function _neutron_create_private_subnet_v4 {
1244 1244
     subnet_params+="--gateway $NETWORK_GATEWAY "
1245 1245
     subnet_params+="--name $PRIVATE_SUBNET_NAME "
1246 1246
     subnet_params+="$NET_ID $FIXED_RANGE"
1247
-    local subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
1247
+    local subnet_id
1248
+    subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
1248 1249
     die_if_not_set $LINENO subnet_id "Failure creating private IPv4 subnet for $TENANT_ID"
1249 1250
     echo $subnet_id
1250 1251
 }
... ...
@@ -1259,7 +1261,8 @@ function _neutron_create_private_subnet_v6 {
1259 1259
     subnet_params+="--gateway $IPV6_PRIVATE_NETWORK_GATEWAY "
1260 1260
     subnet_params+="--name $IPV6_PRIVATE_SUBNET_NAME "
1261 1261
     subnet_params+="$NET_ID $FIXED_RANGE_V6 $ipv6_modes"
1262
-    local ipv6_subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
1262
+    local ipv6_subnet_id
1263
+    ipv6_subnet_id=$(neutron subnet-create $subnet_params | grep ' id ' | get_field 2)
1263 1264
     die_if_not_set $LINENO ipv6_subnet_id "Failure creating private IPv6 subnet for $TENANT_ID"
1264 1265
     echo $ipv6_subnet_id
1265 1266
 }
... ...
@@ -1272,7 +1275,8 @@ function _neutron_create_public_subnet_v4 {
1272 1272
     subnet_params+="--name $PUBLIC_SUBNET_NAME "
1273 1273
     subnet_params+="$EXT_NET_ID $FLOATING_RANGE "
1274 1274
     subnet_params+="-- --enable_dhcp=False"
1275
-    local id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
1275
+    local id_and_ext_gw_ip
1276
+    id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
1276 1277
     die_if_not_set $LINENO id_and_ext_gw_ip "Failure creating public IPv4 subnet"
1277 1278
     echo $id_and_ext_gw_ip
1278 1279
 }
... ...
@@ -1284,7 +1288,8 @@ function _neutron_create_public_subnet_v6 {
1284 1284
     subnet_params+="--name $IPV6_PUBLIC_SUBNET_NAME "
1285 1285
     subnet_params+="$EXT_NET_ID $IPV6_PUBLIC_RANGE "
1286 1286
     subnet_params+="-- --enable_dhcp=False"
1287
-    local ipv6_id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
1287
+    local ipv6_id_and_ext_gw_ip
1288
+    ipv6_id_and_ext_gw_ip=$(neutron subnet-create $subnet_params | grep -e 'gateway_ip' -e ' id ')
1288 1289
     die_if_not_set $LINENO ipv6_id_and_ext_gw_ip "Failure creating an IPv6 public subnet"
1289 1290
     echo $ipv6_id_and_ext_gw_ip
1290 1291
 }
... ...
@@ -1293,8 +1298,10 @@ function _neutron_create_public_subnet_v6 {
1293 1293
 function _neutron_configure_router_v4 {
1294 1294
     neutron router-interface-add $ROUTER_ID $SUBNET_ID
1295 1295
     # Create a public subnet on the external network
1296
-    local id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID)
1297
-    local ext_gw_ip=$(echo $id_and_ext_gw_ip  | get_field 2)
1296
+    local id_and_ext_gw_ip
1297
+    id_and_ext_gw_ip=$(_neutron_create_public_subnet_v4 $EXT_NET_ID)
1298
+    local ext_gw_ip
1299
+    ext_gw_ip=$(echo $id_and_ext_gw_ip  | get_field 2)
1298 1300
     PUB_SUBNET_ID=$(echo $id_and_ext_gw_ip | get_field 5)
1299 1301
     # Configure the external network as the default router gateway
1300 1302
     neutron router-gateway-set $ROUTER_ID $EXT_NET_ID
... ...
@@ -1331,9 +1338,12 @@ function _neutron_configure_router_v4 {
1331 1331
 function _neutron_configure_router_v6 {
1332 1332
     neutron router-interface-add $ROUTER_ID $IPV6_SUBNET_ID
1333 1333
     # Create a public subnet on the external network
1334
-    local ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID)
1335
-    local ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2)
1336
-    local ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5)
1334
+    local ipv6_id_and_ext_gw_ip
1335
+    ipv6_id_and_ext_gw_ip=$(_neutron_create_public_subnet_v6 $EXT_NET_ID)
1336
+    local ipv6_ext_gw_ip
1337
+    ipv6_ext_gw_ip=$(echo $ipv6_id_and_ext_gw_ip | get_field 2)
1338
+    local ipv6_pub_subnet_id
1339
+    ipv6_pub_subnet_id=$(echo $ipv6_id_and_ext_gw_ip | get_field 5)
1337 1340
 
1338 1341
     # If the external network has not already been set as the default router
1339 1342
     # gateway when configuring an IPv4 public subnet, do so now
... ...
@@ -1351,7 +1361,8 @@ function _neutron_configure_router_v6 {
1351 1351
         die_if_not_set $LINENO IPV6_ROUTER_GW_IP "Failure retrieving IPV6_ROUTER_GW_IP"
1352 1352
 
1353 1353
         if is_neutron_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
1354
-            local ext_gw_interface=$(_neutron_get_ext_gw_interface)
1354
+            local ext_gw_interface
1355
+            ext_gw_interface=$(_neutron_get_ext_gw_interface)
1355 1356
             local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/}
1356 1357
 
1357 1358
             # Configure interface for public bridge
... ...
@@ -10,7 +10,8 @@ set +o xtrace
10 10
 source $TOP_DIR/lib/neutron_plugins/openvswitch
11 11
 
12 12
 function save_function {
13
-    local ORIG_FUNC=$(declare -f $1)
13
+    local ORIG_FUNC
14
+    ORIG_FUNC=$(declare -f $1)
14 15
     local NEW_FUNC="$2${ORIG_FUNC#$1}"
15 16
     eval "$NEW_FUNC"
16 17
 }
... ...
@@ -49,8 +49,10 @@ function neutron_ovs_base_cleanup {
49 49
 
50 50
 function _neutron_ovs_base_install_ubuntu_dkms {
51 51
     # install Dynamic Kernel Module Support packages if needed
52
-    local kernel_version=$(uname -r)
53
-    local kernel_major_minor=`echo $kernel_version | cut -d. -f1-2`
52
+    local kernel_version
53
+    kernel_version=$(uname -r)
54
+    local kernel_major_minor
55
+    kernel_major_minor=`echo $kernel_version | cut -d. -f1-2`
54 56
     # From kernel 3.13 on, openvswitch-datapath-dkms is not needed
55 57
     if [ `vercmp_numbers "$kernel_major_minor" "3.13"` -lt "0" ]; then
56 58
         install_package "dkms openvswitch-datapath-dkms linux-headers-$kernel_version"
... ...
@@ -202,14 +202,16 @@ function cleanup_nova {
202 202
         clean_iptables
203 203
 
204 204
         # Destroy old instances
205
-        local instances=`sudo virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"`
205
+        local instances
206
+        instances=`sudo virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"`
206 207
         if [ ! "$instances" = "" ]; then
207 208
             echo $instances | xargs -n1 sudo virsh destroy || true
208 209
             echo $instances | xargs -n1 sudo virsh undefine --managed-save || true
209 210
         fi
210 211
 
211 212
         # Logout and delete iscsi sessions
212
-        local tgts=$(sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d ' ' -f2)
213
+        local tgts
214
+        tgts=$(sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d ' ' -f2)
213 215
         local target
214 216
         for target in $tgts; do
215 217
             sudo iscsiadm --mode node -T $target --logout || true
... ...
@@ -245,8 +247,10 @@ function _cleanup_nova_apache_wsgi {
245 245
 function _config_nova_apache_wsgi {
246 246
     sudo mkdir -p $NOVA_WSGI_DIR
247 247
 
248
-    local nova_apache_conf=$(apache_site_config_for nova-api)
249
-    local nova_ec2_apache_conf=$(apache_site_config_for nova-ec2-api)
248
+    local nova_apache_conf
249
+    nova_apache_conf=$(apache_site_config_for nova-api)
250
+    local nova_ec2_apache_conf
251
+    nova_ec2_apache_conf=$(apache_site_config_for nova-ec2-api)
250 252
     local nova_ssl=""
251 253
     local nova_certfile=""
252 254
     local nova_keyfile=""
... ...
@@ -784,7 +788,8 @@ function start_nova_api {
784 784
     export PATH=$NOVA_BIN_DIR:$PATH
785 785
 
786 786
     # If the site is not enabled then we are in a grenade scenario
787
-    local enabled_site_file=$(apache_site_config_for nova-api)
787
+    local enabled_site_file
788
+    enabled_site_file=$(apache_site_config_for nova-api)
788 789
     if [ -f ${enabled_site_file} ] && [ "$NOVA_USE_MOD_WSGI" == "True" ]; then
789 790
         enable_apache_site nova-api
790 791
         enable_apache_site nova-ec2-api
... ...
@@ -205,9 +205,12 @@ function _config_swift_apache_wsgi {
205 205
     # copy apache vhost file and set name and port
206 206
     local node_number
207 207
     for node_number in ${SWIFT_REPLICAS_SEQ}; do
208
-        local object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))
209
-        local container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))
210
-        local account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))
208
+        local object_port
209
+        object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))
210
+        local container_port
211
+        container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))
212
+        local account_port
213
+        account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))
211 214
 
212 215
         sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number})
213 216
         sudo sed -e "
... ...
@@ -504,7 +507,8 @@ EOF
504 504
 
505 505
     if is_service_enabled keystone; then
506 506
         iniuncomment ${testfile} func_test auth_version
507
-        local auth_vers=$(iniget ${testfile} func_test auth_version)
507
+        local auth_vers
508
+        auth_vers=$(iniget ${testfile} func_test auth_version)
508 509
         iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
509 510
         iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
510 511
         if [[ $auth_vers == "3" ]]; then
... ...
@@ -514,7 +518,8 @@ EOF
514 514
         fi
515 515
     fi
516 516
 
517
-    local user_group=$(id -g ${STACK_USER})
517
+    local user_group
518
+    user_group=$(id -g ${STACK_USER})
518 519
     sudo install -d -o ${STACK_USER} -g ${user_group} ${SWIFT_DATA_DIR}
519 520
 
520 521
     local swift_log_dir=${SWIFT_DATA_DIR}/logs
... ...
@@ -540,7 +545,8 @@ function create_swift_disk {
540 540
     # First do a bit of setup by creating the directories and
541 541
     # changing the permissions so we can run it as our user.
542 542
 
543
-    local user_group=$(id -g ${STACK_USER})
543
+    local user_group
544
+    user_group=$(id -g ${STACK_USER})
544 545
     sudo install -d -o ${STACK_USER} -g ${user_group} ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
545 546
 
546 547
     # Create a loopback disk and format it to XFS.
... ...
@@ -607,7 +613,8 @@ function create_swift_accounts {
607 607
 
608 608
     KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
609 609
 
610
-    local another_role=$(get_or_create_role "anotherrole")
610
+    local another_role
611
+    another_role=$(get_or_create_role "anotherrole")
611 612
 
612 613
     # NOTE(jroll): Swift doesn't need the admin role here, however Ironic uses
613 614
     # temp urls, which break when uploaded by a non-admin role
... ...
@@ -623,33 +630,40 @@ function create_swift_accounts {
623 623
             "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
624 624
     fi
625 625
 
626
-    local swift_tenant_test1=$(get_or_create_project swifttenanttest1 default)
626
+    local swift_tenant_test1
627
+    swift_tenant_test1=$(get_or_create_project swifttenanttest1 default)
627 628
     die_if_not_set $LINENO swift_tenant_test1 "Failure creating swift_tenant_test1"
628 629
     SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password \
629 630
                         "default" "test@example.com")
630 631
     die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
631 632
     get_or_add_user_project_role admin $SWIFT_USER_TEST1 $swift_tenant_test1
632 633
 
633
-    local swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \
634
+    local swift_user_test3
635
+    swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \
634 636
                                 "default" "test3@example.com")
635 637
     die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3"
636 638
     get_or_add_user_project_role $another_role $swift_user_test3 $swift_tenant_test1
637 639
 
638
-    local swift_tenant_test2=$(get_or_create_project swifttenanttest2 default)
640
+    local swift_tenant_test2
641
+    swift_tenant_test2=$(get_or_create_project swifttenanttest2 default)
639 642
     die_if_not_set $LINENO swift_tenant_test2 "Failure creating swift_tenant_test2"
640 643
 
641
-    local swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \
644
+    local swift_user_test2
645
+    swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \
642 646
                                 "default" "test2@example.com")
643 647
     die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2"
644 648
     get_or_add_user_project_role admin $swift_user_test2 $swift_tenant_test2
645 649
 
646
-    local swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
650
+    local swift_domain
651
+    swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
647 652
     die_if_not_set $LINENO swift_domain "Failure creating swift_test domain"
648 653
 
649
-    local swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain)
654
+    local swift_tenant_test4
655
+    swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain)
650 656
     die_if_not_set $LINENO swift_tenant_test4 "Failure creating swift_tenant_test4"
651 657
 
652
-    local swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \
658
+    local swift_user_test4
659
+    swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \
653 660
                                 $swift_domain "test4@example.com")
654 661
     die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4"
655 662
     get_or_add_user_project_role admin $swift_user_test4 $swift_tenant_test4
... ...
@@ -372,7 +372,8 @@ function configure_tempest {
372 372
     # Compute Features
373 373
     # Run ``verify_tempest_config -ur`` to retrieve enabled extensions on API endpoints
374 374
     # NOTE(mtreinish): This must be done after auth settings are added to the tempest config
375
-    local tmp_cfg_file=$(mktemp)
375
+    local tmp_cfg_file
376
+    tmp_cfg_file=$(mktemp)
376 377
     cd $TEMPEST_DIR
377 378
     tox -revenv -- verify-tempest-config -uro $tmp_cfg_file
378 379
 
... ...
@@ -346,7 +346,8 @@ function make_root_CA {
346 346
 # we need to change it.
347 347
 function fix_system_ca_bundle_path {
348 348
     if is_service_enabled tls-proxy || [ "$USE_SSL" == "True" ]; then
349
-        local capath=$(python -c $'try:\n from requests import certs\n print certs.where()\nexcept ImportError: pass')
349
+        local capath
350
+        capath=$(python -c $'try:\n from requests import certs\n print certs.where()\nexcept ImportError: pass')
350 351
 
351 352
         if [[ ! $capath == "" && ! $capath =~ ^/etc/.* && ! -L $capath ]]; then
352 353
             if is_fedora; then
... ...
@@ -20,8 +20,10 @@ FAILED_FUNCS=""
20 20
 # pass a test, printing out MSG
21 21
 #  usage: passed message
22 22
 function passed {
23
-    local lineno=$(caller 0 | awk '{print $1}')
24
-    local function=$(caller 0 | awk '{print $2}')
23
+    local lineno
24
+    lineno=$(caller 0 | awk '{print $1}')
25
+    local function
26
+    function=$(caller 0 | awk '{print $2}')
25 27
     local msg="$1"
26 28
     if [ -z "$msg" ]; then
27 29
         msg="OK"
... ...
@@ -33,8 +35,10 @@ function passed {
33 33
 # fail a test, printing out MSG
34 34
 #  usage: failed message
35 35
 function failed {
36
-    local lineno=$(caller 0 | awk '{print $1}')
37
-    local function=$(caller 0 | awk '{print $2}')
36
+    local lineno
37
+    lineno=$(caller 0 | awk '{print $1}')
38
+    local function
39
+    function=$(caller 0 | awk '{print $2}')
38 40
     local msg="$1"
39 41
     FAILED_FUNCS+="$function:L$lineno\n"
40 42
     echo "ERROR: $function:L$lineno!"
... ...
@@ -45,8 +49,10 @@ function failed {
45 45
 # assert string comparision of val1 equal val2, printing out msg
46 46
 #  usage: assert_equal val1 val2 msg
47 47
 function assert_equal {
48
-    local lineno=`caller 0 | awk '{print $1}'`
49
-    local function=`caller 0 | awk '{print $2}'`
48
+    local lineno
49
+    lineno=`caller 0 | awk '{print $1}'`
50
+    local function
51
+    function=`caller 0 | awk '{print $2}'`
50 52
     local msg=$3
51 53
 
52 54
     if [ -z "$msg" ]; then
... ...
@@ -66,8 +72,10 @@ function assert_equal {
66 66
 # assert variable is empty/blank, printing out msg
67 67
 #  usage: assert_empty VAR msg
68 68
 function assert_empty {
69
-    local lineno=`caller 0 | awk '{print $1}'`
70
-    local function=`caller 0 | awk '{print $2}'`
69
+    local lineno
70
+    lineno=`caller 0 | awk '{print $1}'`
71
+    local function
72
+    function=`caller 0 | awk '{print $2}'`
71 73
     local msg=$2
72 74
 
73 75
     if [ -z "$msg" ]; then
... ...
@@ -190,7 +190,8 @@ function add_entry {
190 190
     local user_passwd=$5
191 191
 
192 192
     # The admin user can see all user's secret AWS keys, it does not looks good
193
-    local line=`openstack ec2 credentials list --user $user_id | grep " $project_id "`
193
+    local line
194
+    line=$(openstack ec2 credentials list --user $user_id | grep " $project_id " || true)
194 195
     if [ -z "$line" ]; then
195 196
         openstack ec2 credentials create --user $user_id --project $project_id 1>&2
196 197
         line=`openstack ec2 credentials list --user $user_id | grep " $project_id "`
... ...
@@ -41,10 +41,12 @@ function get_mem_available {
41 41
 # snapshot of current usage; i.e. checking the latest entry in the
42 42
 # file will give the peak-memory usage
43 43
 function tracker {
44
-    local low_point=$(get_mem_available)
44
+    local low_point
45
+    low_point=$(get_mem_available)
45 46
     while [ 1 ]; do
46 47
 
47
-        local mem_available=$(get_mem_available)
48
+        local mem_available
49
+        mem_available=$(get_mem_available)
48 50
 
49 51
         if [[ $mem_available -lt $low_point ]]; then
50 52
             low_point=$mem_available
... ...
@@ -100,7 +100,8 @@ create_vif()
100 100
 {
101 101
     local v="$1"
102 102
     echo "Installing VM interface on [$BRIDGE]"
103
-    local out_network_uuid=$(find_network "$BRIDGE")
103
+    local out_network_uuid
104
+    out_network_uuid=$(find_network "$BRIDGE")
104 105
     xe vif-create vm-uuid="$v" network-uuid="$out_network_uuid" device="0"
105 106
 }
106 107
 
... ...
@@ -35,9 +35,12 @@ xe_min()
35 35
 destroy_vdi()
36 36
 {
37 37
     local vbd_uuid="$1"
38
-    local type=$(xe_min vbd-list uuid=$vbd_uuid params=type)
39
-    local dev=$(xe_min vbd-list uuid=$vbd_uuid params=userdevice)
40
-    local vdi_uuid=$(xe_min vbd-list uuid=$vbd_uuid params=vdi-uuid)
38
+    local type
39
+    type=$(xe_min vbd-list uuid=$vbd_uuid params=type)
40
+    local dev
41
+    dev=$(xe_min vbd-list uuid=$vbd_uuid params=userdevice)
42
+    local vdi_uuid
43
+    vdi_uuid=$(xe_min vbd-list uuid=$vbd_uuid params=vdi-uuid)
41 44
 
42 45
     if [ "$type" == 'Disk' ] && [ "$dev" != 'xvda' ] && [ "$dev" != '0' ]; then
43 46
         xe vdi-destroy uuid=$vdi_uuid
... ...
@@ -47,7 +50,8 @@ destroy_vdi()
47 47
 uninstall()
48 48
 {
49 49
     local vm_uuid="$1"
50
-    local power_state=$(xe_min vm-list uuid=$vm_uuid params=power-state)
50
+    local power_state
51
+    power_state=$(xe_min vm-list uuid=$vm_uuid params=power-state)
51 52
 
52 53
     if [ "$power_state" != "halted" ]; then
53 54
         xe vm-shutdown vm=$vm_uuid force=true
... ...
@@ -165,7 +165,8 @@ EOF
165 165
 function test_get_local_sr {
166 166
     setup_xe_response "uuid123"
167 167
 
168
-    local RESULT=$(. mocks && get_local_sr)
168
+    local RESULT
169
+    RESULT=$(. mocks && get_local_sr)
169 170
 
170 171
     [ "$RESULT" == "uuid123" ]
171 172
 
... ...
@@ -173,7 +174,8 @@ function test_get_local_sr {
173 173
 }
174 174
 
175 175
 function test_get_local_sr_path {
176
-    local RESULT=$(mock_out get_local_sr "uuid1" && get_local_sr_path)
176
+    local RESULT
177
+    RESULT=$(mock_out get_local_sr "uuid1" && get_local_sr_path)
177 178
 
178 179
     [ "/var/run/sr-mount/uuid1" == "$RESULT" ]
179 180
 }