Browse code

Make declared variables global

When variables use the 'declare' directive, it is by default a local
variable. While other variables have global scope.

For example:
declare -A AN_ARRAY # local in scope
foo=1 # global in scope

This causes errors to occur as some of the variables will be local only
and others will be global.

Update the code, as appropriate, so that variables using the 'declare'
directive also include the '-g' flag to have them also be global. Not
every instance of a declared variable has been updated.

Closes-Bug: #1669509
Co-Authored-By: John L. Villalovos <john.l.villalovos@intel.com>
Change-Id: I2180b68fe861ad19c6d4ec0df0f9f8a528347862

Sean Dague authored on 2017/03/07 04:07:23
Showing 6 changed files
... ...
@@ -12,7 +12,7 @@
12 12
 
13 13
 # ensure we don't re-source this in the same environment
14 14
 [[ -z "$_DEVSTACK_FUNCTIONS" ]] || return 0
15
-declare -r _DEVSTACK_FUNCTIONS=1
15
+declare -r -g _DEVSTACK_FUNCTIONS=1
16 16
 
17 17
 # Include the common functions
18 18
 FUNC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd)
... ...
@@ -37,12 +37,12 @@ set +o xtrace
37 37
 
38 38
 # ensure we don't re-source this in the same environment
39 39
 [[ -z "$_DEVSTACK_FUNCTIONS_COMMON" ]] || return 0
40
-declare -r _DEVSTACK_FUNCTIONS_COMMON=1
40
+declare -r -g _DEVSTACK_FUNCTIONS_COMMON=1
41 41
 
42 42
 # Global Config Variables
43
-declare -A GITREPO
44
-declare -A GITBRANCH
45
-declare -A GITDIR
43
+declare -A -g GITREPO
44
+declare -A -g GITBRANCH
45
+declare -A -g GITDIR
46 46
 
47 47
 TRACK_DEPENDS=${TRACK_DEPENDS:-False}
48 48
 
... ...
@@ -306,7 +306,7 @@ function warn {
306 306
 # ``os_PACKAGE`` - package type: ``deb`` or ``rpm``
307 307
 # ``os_CODENAME`` - vendor's codename for release: ``xenial``
308 308
 
309
-declare os_VENDOR os_RELEASE os_PACKAGE os_CODENAME
309
+declare -g os_VENDOR os_RELEASE os_PACKAGE os_CODENAME
310 310
 
311 311
 # Make a *best effort* attempt to install lsb_release packages for the
312 312
 # user if not available.  Note can't use generic install_package*
... ...
@@ -361,7 +361,7 @@ function GetOSVersion {
361 361
 
362 362
 # Translate the OS version values into common nomenclature
363 363
 # Sets global ``DISTRO`` from the ``os_*`` values
364
-declare DISTRO
364
+declare -g DISTRO
365 365
 
366 366
 function GetDistro {
367 367
     GetOSVersion
... ...
@@ -2376,9 +2376,9 @@ function sudo_with_proxies {
2376 2376
 # Resolution is only in whole seconds, so should be used for long
2377 2377
 # running activities.
2378 2378
 
2379
-declare -A _TIME_TOTAL
2380
-declare -A _TIME_START
2381
-declare -r _TIME_BEGIN=$(date +%s)
2379
+declare -A -g _TIME_TOTAL
2380
+declare -A -g _TIME_START
2381
+declare -r -g _TIME_BEGIN=$(date +%s)
2382 2382
 
2383 2383
 # time_start $name
2384 2384
 #
... ...
@@ -19,7 +19,7 @@ set +o xtrace
19 19
 
20 20
 # PROJECT_VENV contains the name of the virtual environment for each
21 21
 # project.  A null value installs to the system Python directories.
22
-declare -A PROJECT_VENV
22
+declare -A -g PROJECT_VENV
23 23
 
24 24
 
25 25
 # Python Functions
... ...
@@ -74,7 +74,7 @@ NEUTRON_ROOTWRAP_DAEMON_CMD="sudo $NEUTRON_ROOTWRAP-daemon $NEUTRON_ROOTWRAP_CON
74 74
 NEUTRON_CONFIG_ARG=${NEUTRON_CONFIG_ARG:-""}
75 75
 
76 76
 # Additional neutron api config files
77
-declare -a _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS
77
+declare -a -g _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS
78 78
 
79 79
 # Functions
80 80
 # ---------
... ...
@@ -141,10 +141,10 @@ _Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
141 141
 # These config files are relative to ``/etc/neutron``.  The above
142 142
 # example would specify ``--config-file /etc/neutron/file1`` for
143 143
 # neutron server.
144
-declare -a Q_PLUGIN_EXTRA_CONF_FILES
144
+declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
145 145
 
146 146
 # same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
147
-declare -a _Q_PLUGIN_EXTRA_CONF_FILES_ABS
147
+declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
148 148
 
149 149
 
150 150
 Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
... ...
@@ -5,7 +5,7 @@
5 5
 
6 6
 # ensure we don't re-source this in the same environment
7 7
 [[ -z "$_DEVSTACK_STACKRC" ]] || return 0
8
-declare -r _DEVSTACK_STACKRC=1
8
+declare -r -g _DEVSTACK_STACKRC=1
9 9
 
10 10
 # Find the other rc files
11 11
 RC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd)