From afef8bf097356d7bb37c57d0daa44653c7905c17 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 6 Mar 2017 14:07:23 -0500 Subject: [PATCH] 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 Change-Id: I2180b68fe861ad19c6d4ec0df0f9f8a528347862 --- functions | 2 +- functions-common | 18 +++++++++--------- inc/python | 2 +- lib/neutron | 2 +- lib/neutron-legacy | 4 ++-- stackrc | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/functions b/functions index 89ee3672d3..48c821c0a6 100644 --- a/functions +++ b/functions @@ -12,7 +12,7 @@ # ensure we don't re-source this in the same environment [[ -z "$_DEVSTACK_FUNCTIONS" ]] || return 0 -declare -r _DEVSTACK_FUNCTIONS=1 +declare -r -g _DEVSTACK_FUNCTIONS=1 # Include the common functions FUNC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd) diff --git a/functions-common b/functions-common index 0d1b01f2fe..64f97f005a 100644 --- a/functions-common +++ b/functions-common @@ -37,12 +37,12 @@ set +o xtrace # ensure we don't re-source this in the same environment [[ -z "$_DEVSTACK_FUNCTIONS_COMMON" ]] || return 0 -declare -r _DEVSTACK_FUNCTIONS_COMMON=1 +declare -r -g _DEVSTACK_FUNCTIONS_COMMON=1 # Global Config Variables -declare -A GITREPO -declare -A GITBRANCH -declare -A GITDIR +declare -A -g GITREPO +declare -A -g GITBRANCH +declare -A -g GITDIR TRACK_DEPENDS=${TRACK_DEPENDS:-False} @@ -306,7 +306,7 @@ function warn { # ``os_PACKAGE`` - package type: ``deb`` or ``rpm`` # ``os_CODENAME`` - vendor's codename for release: ``xenial`` -declare os_VENDOR os_RELEASE os_PACKAGE os_CODENAME +declare -g os_VENDOR os_RELEASE os_PACKAGE os_CODENAME # Make a *best effort* attempt to install lsb_release packages for the # user if not available. Note can't use generic install_package* @@ -361,7 +361,7 @@ function GetOSVersion { # Translate the OS version values into common nomenclature # Sets global ``DISTRO`` from the ``os_*`` values -declare DISTRO +declare -g DISTRO function GetDistro { GetOSVersion @@ -2376,9 +2376,9 @@ function sudo_with_proxies { # Resolution is only in whole seconds, so should be used for long # running activities. -declare -A _TIME_TOTAL -declare -A _TIME_START -declare -r _TIME_BEGIN=$(date +%s) +declare -A -g _TIME_TOTAL +declare -A -g _TIME_START +declare -r -g _TIME_BEGIN=$(date +%s) # time_start $name # diff --git a/inc/python b/inc/python index 5afc07f636..d0e45df489 100644 --- a/inc/python +++ b/inc/python @@ -19,7 +19,7 @@ set +o xtrace # PROJECT_VENV contains the name of the virtual environment for each # project. A null value installs to the system Python directories. -declare -A PROJECT_VENV +declare -A -g PROJECT_VENV # Python Functions diff --git a/lib/neutron b/lib/neutron index 19568eaf25..4a547ac0bf 100644 --- a/lib/neutron +++ b/lib/neutron @@ -74,7 +74,7 @@ NEUTRON_ROOTWRAP_DAEMON_CMD="sudo $NEUTRON_ROOTWRAP-daemon $NEUTRON_ROOTWRAP_CON NEUTRON_CONFIG_ARG=${NEUTRON_CONFIG_ARG:-""} # Additional neutron api config files -declare -a _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS +declare -a -g _NEUTRON_SERVER_EXTRA_CONF_FILES_ABS # Functions # --------- diff --git a/lib/neutron-legacy b/lib/neutron-legacy index b381b642c6..96d86743ab 100644 --- a/lib/neutron-legacy +++ b/lib/neutron-legacy @@ -141,10 +141,10 @@ _Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron # These config files are relative to ``/etc/neutron``. The above # example would specify ``--config-file /etc/neutron/file1`` for # neutron server. -declare -a Q_PLUGIN_EXTRA_CONF_FILES +declare -a -g Q_PLUGIN_EXTRA_CONF_FILES # same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path. -declare -a _Q_PLUGIN_EXTRA_CONF_FILES_ABS +declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf diff --git a/stackrc b/stackrc index afe385c2a1..14c5960ed4 100644 --- a/stackrc +++ b/stackrc @@ -5,7 +5,7 @@ # ensure we don't re-source this in the same environment [[ -z "$_DEVSTACK_STACKRC" ]] || return 0 -declare -r _DEVSTACK_STACKRC=1 +declare -r -g _DEVSTACK_STACKRC=1 # Find the other rc files RC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd)