Skip to content

Commit 433a9b1

Browse files
committed
Don't set xtrace directly in local call
Ia0957b47187c3dcadd46154b17022c4213781112 detects setting local variables with subshell commands. Although this is a particuarly benign case, it trips the test. Rather than putting in an ignore for this, we can easily change it to make the test pass. This seems better than putting in special work-arounds to bashate, etc. Change-Id: I37c3967c0f2d780a636a7d26cda83755085c5c69
1 parent 561137e commit 433a9b1

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

functions-common

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ function write_clouds_yaml {
111111
# Accepts as True: 1 yes Yes YES true True TRUE
112112
# VAR=$(trueorfalse default-value test-value)
113113
function trueorfalse {
114-
local xtrace=$(set +o | grep xtrace)
114+
local xtrace
115+
xtrace=$(set +o | grep xtrace)
115116
set +o xtrace
116117

117118
local default=$1
@@ -169,7 +170,8 @@ function die {
169170
# die_if_not_set $LINENO env-var "message"
170171
function die_if_not_set {
171172
local exitcode=$?
172-
local xtrace=$(set +o | grep xtrace)
173+
local xtrace
174+
xtrace=$(set +o | grep xtrace)
173175
set +o xtrace
174176
local line=$1; shift
175177
local evar=$1; shift
@@ -183,7 +185,8 @@ function die_if_not_set {
183185
# err $LINENO "message"
184186
function err {
185187
local exitcode=$?
186-
local xtrace=$(set +o | grep xtrace)
188+
local xtrace
189+
xtrace=$(set +o | grep xtrace)
187190
set +o xtrace
188191
local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2"
189192
echo $msg 1>&2;
@@ -200,7 +203,8 @@ function err {
200203
# err_if_not_set $LINENO env-var "message"
201204
function err_if_not_set {
202205
local exitcode=$?
203-
local xtrace=$(set +o | grep xtrace)
206+
local xtrace
207+
xtrace=$(set +o | grep xtrace)
204208
set +o xtrace
205209
local line=$1; shift
206210
local evar=$1; shift
@@ -236,7 +240,8 @@ function is_set {
236240
# warn $LINENO "message"
237241
function warn {
238242
local exitcode=$?
239-
local xtrace=$(set +o | grep xtrace)
243+
local xtrace
244+
xtrace=$(set +o | grep xtrace)
240245
set +o xtrace
241246
local msg="[WARNING] ${BASH_SOURCE[2]}:$1 $2"
242247
echo $msg
@@ -986,7 +991,8 @@ function _get_package_dir {
986991
# Uses globals ``OFFLINE``, ``*_proxy``
987992
# apt_get operation package [package ...]
988993
function apt_get {
989-
local xtrace=$(set +o | grep xtrace)
994+
local xtrace
995+
xtrace=$(set +o | grep xtrace)
990996
set +o xtrace
991997

992998
[[ "$OFFLINE" = "True" || -z "$@" ]] && return
@@ -1055,7 +1061,8 @@ function _parse_package_files {
10551061
# - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
10561062
# of the package to the distros listed. The distro names are case insensitive.
10571063
function get_packages {
1058-
local xtrace=$(set +o | grep xtrace)
1064+
local xtrace
1065+
xtrace=$(set +o | grep xtrace)
10591066
set +o xtrace
10601067
local services=$@
10611068
local package_dir=$(_get_package_dir)
@@ -1123,7 +1130,8 @@ function get_packages {
11231130
# The same metadata used in the main DevStack prerequisite files may be used
11241131
# in these prerequisite files, see get_packages() for more info.
11251132
function get_plugin_packages {
1126-
local xtrace=$(set +o | grep xtrace)
1133+
local xtrace
1134+
xtrace=$(set +o | grep xtrace)
11271135
set +o xtrace
11281136
local files_to_parse=""
11291137
local package_dir=""
@@ -1148,7 +1156,8 @@ function update_package_repo {
11481156
fi
11491157

11501158
if is_ubuntu; then
1151-
local xtrace=$(set +o | grep xtrace)
1159+
local xtrace
1160+
xtrace=$(set +o | grep xtrace)
11521161
set +o xtrace
11531162
if [[ "$REPOS_UPDATED" != "True" || "$RETRY_UPDATE" = "True" ]]; then
11541163
# if there are transient errors pulling the updates, that's fine.
@@ -1854,7 +1863,8 @@ function enable_service {
18541863
# Uses global ``ENABLED_SERVICES``
18551864
# is_service_enabled service [service ...]
18561865
function is_service_enabled {
1857-
local xtrace=$(set +o | grep xtrace)
1866+
local xtrace
1867+
xtrace=$(set +o | grep xtrace)
18581868
set +o xtrace
18591869
local enabled=1
18601870
local services=$@
@@ -1933,7 +1943,8 @@ function use_exclusive_service {
19331943
# Only run the command if the target file (the last arg) is not on an
19341944
# NFS filesystem.
19351945
function _safe_permission_operation {
1936-
local xtrace=$(set +o | grep xtrace)
1946+
local xtrace
1947+
xtrace=$(set +o | grep xtrace)
19371948
set +o xtrace
19381949
local args=( $@ )
19391950
local last

inc/ini-config

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ set +o xtrace
1717
# Append a new option in an ini file without replacing the old value
1818
# iniadd [-sudo] config-file section option value1 value2 value3 ...
1919
function iniadd {
20-
local xtrace=$(set +o | grep xtrace)
20+
local xtrace
21+
xtrace=$(set +o | grep xtrace)
2122
set +o xtrace
2223
local sudo=""
2324
if [ $1 == "-sudo" ]; then
@@ -37,7 +38,8 @@ function iniadd {
3738
# Comment an option in an INI file
3839
# inicomment [-sudo] config-file section option
3940
function inicomment {
40-
local xtrace=$(set +o | grep xtrace)
41+
local xtrace
42+
xtrace=$(set +o | grep xtrace)
4143
set +o xtrace
4244
local sudo=""
4345
if [ $1 == "-sudo" ]; then
@@ -55,7 +57,8 @@ function inicomment {
5557
# Get an option from an INI file
5658
# iniget config-file section option
5759
function iniget {
58-
local xtrace=$(set +o | grep xtrace)
60+
local xtrace
61+
xtrace=$(set +o | grep xtrace)
5962
set +o xtrace
6063
local file=$1
6164
local section=$2
@@ -70,7 +73,8 @@ function iniget {
7073
# Get a multiple line option from an INI file
7174
# iniget_multiline config-file section option
7275
function iniget_multiline {
73-
local xtrace=$(set +o | grep xtrace)
76+
local xtrace
77+
xtrace=$(set +o | grep xtrace)
7478
set +o xtrace
7579
local file=$1
7680
local section=$2
@@ -85,7 +89,8 @@ function iniget_multiline {
8589
# Determinate is the given option present in the INI file
8690
# ini_has_option config-file section option
8791
function ini_has_option {
88-
local xtrace=$(set +o | grep xtrace)
92+
local xtrace
93+
xtrace=$(set +o | grep xtrace)
8994
set +o xtrace
9095
local file=$1
9196
local section=$2
@@ -107,7 +112,8 @@ function ini_has_option {
107112
#
108113
# iniadd_literal [-sudo] config-file section option value
109114
function iniadd_literal {
110-
local xtrace=$(set +o | grep xtrace)
115+
local xtrace
116+
xtrace=$(set +o | grep xtrace)
111117
set +o xtrace
112118
local sudo=""
113119
if [ $1 == "-sudo" ]; then
@@ -135,7 +141,8 @@ $option = $value
135141
# Remove an option from an INI file
136142
# inidelete [-sudo] config-file section option
137143
function inidelete {
138-
local xtrace=$(set +o | grep xtrace)
144+
local xtrace
145+
xtrace=$(set +o | grep xtrace)
139146
set +o xtrace
140147
local sudo=""
141148
if [ $1 == "-sudo" ]; then
@@ -161,7 +168,8 @@ function inidelete {
161168
# iniset [-sudo] config-file section option value
162169
# - if the file does not exist, it is created
163170
function iniset {
164-
local xtrace=$(set +o | grep xtrace)
171+
local xtrace
172+
xtrace=$(set +o | grep xtrace)
165173
set +o xtrace
166174
local sudo=""
167175
if [ $1 == "-sudo" ]; then
@@ -198,7 +206,8 @@ $option = $value
198206
# Set a multiple line option in an INI file
199207
# iniset_multiline [-sudo] config-file section option value1 value2 valu3 ...
200208
function iniset_multiline {
201-
local xtrace=$(set +o | grep xtrace)
209+
local xtrace
210+
xtrace=$(set +o | grep xtrace)
202211
set +o xtrace
203212
local sudo=""
204213
if [ $1 == "-sudo" ]; then
@@ -236,7 +245,8 @@ $option = $v
236245
# Uncomment an option in an INI file
237246
# iniuncomment config-file section option
238247
function iniuncomment {
239-
local xtrace=$(set +o | grep xtrace)
248+
local xtrace
249+
xtrace=$(set +o | grep xtrace)
240250
set +o xtrace
241251
local sudo=""
242252
if [ $1 == "-sudo" ]; then

inc/python

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function get_pip_command {
3838
# Get the path to the direcotry where python executables are installed.
3939
# get_python_exec_prefix
4040
function get_python_exec_prefix {
41-
local xtrace=$(set +o | grep xtrace)
41+
local xtrace
42+
xtrace=$(set +o | grep xtrace)
4243
set +o xtrace
4344
if [[ -z "$os_PACKAGE" ]]; then
4445
GetOSVersion
@@ -69,7 +70,8 @@ function pip_install_gr {
6970
# ``PIP_UPGRADE``, ``TRACK_DEPENDS``, ``*_proxy``,
7071
# pip_install package [package ...]
7172
function pip_install {
72-
local xtrace=$(set +o | grep xtrace)
73+
local xtrace
74+
xtrace=$(set +o | grep xtrace)
7375
set +o xtrace
7476
local upgrade=""
7577
local offline=${OFFLINE:-False}

0 commit comments

Comments
 (0)