Browse code

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

Ian Wienand authored on 2015/10/07 11:29:31
Showing 3 changed files
... ...
@@ -111,7 +111,8 @@ function write_clouds_yaml {
111 111
 # Accepts as True: 1 yes Yes YES true True TRUE
112 112
 # VAR=$(trueorfalse default-value test-value)
113 113
 function trueorfalse {
114
-    local xtrace=$(set +o | grep xtrace)
114
+    local xtrace
115
+    xtrace=$(set +o | grep xtrace)
115 116
     set +o xtrace
116 117
 
117 118
     local default=$1
... ...
@@ -169,7 +170,8 @@ function die {
169 169
 # die_if_not_set $LINENO env-var "message"
170 170
 function die_if_not_set {
171 171
     local exitcode=$?
172
-    local xtrace=$(set +o | grep xtrace)
172
+    local xtrace
173
+    xtrace=$(set +o | grep xtrace)
173 174
     set +o xtrace
174 175
     local line=$1; shift
175 176
     local evar=$1; shift
... ...
@@ -183,7 +185,8 @@ function die_if_not_set {
183 183
 # err $LINENO "message"
184 184
 function err {
185 185
     local exitcode=$?
186
-    local xtrace=$(set +o | grep xtrace)
186
+    local xtrace
187
+    xtrace=$(set +o | grep xtrace)
187 188
     set +o xtrace
188 189
     local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2"
189 190
     echo $msg 1>&2;
... ...
@@ -200,7 +203,8 @@ function err {
200 200
 # err_if_not_set $LINENO env-var "message"
201 201
 function err_if_not_set {
202 202
     local exitcode=$?
203
-    local xtrace=$(set +o | grep xtrace)
203
+    local xtrace
204
+    xtrace=$(set +o | grep xtrace)
204 205
     set +o xtrace
205 206
     local line=$1; shift
206 207
     local evar=$1; shift
... ...
@@ -236,7 +240,8 @@ function is_set {
236 236
 # warn $LINENO "message"
237 237
 function warn {
238 238
     local exitcode=$?
239
-    local xtrace=$(set +o | grep xtrace)
239
+    local xtrace
240
+    xtrace=$(set +o | grep xtrace)
240 241
     set +o xtrace
241 242
     local msg="[WARNING] ${BASH_SOURCE[2]}:$1 $2"
242 243
     echo $msg
... ...
@@ -986,7 +991,8 @@ function _get_package_dir {
986 986
 # Uses globals ``OFFLINE``, ``*_proxy``
987 987
 # apt_get operation package [package ...]
988 988
 function apt_get {
989
-    local xtrace=$(set +o | grep xtrace)
989
+    local xtrace
990
+    xtrace=$(set +o | grep xtrace)
990 991
     set +o xtrace
991 992
 
992 993
     [[ "$OFFLINE" = "True" || -z "$@" ]] && return
... ...
@@ -1055,7 +1061,8 @@ function _parse_package_files {
1055 1055
 # - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
1056 1056
 #   of the package to the distros listed.  The distro names are case insensitive.
1057 1057
 function get_packages {
1058
-    local xtrace=$(set +o | grep xtrace)
1058
+    local xtrace
1059
+    xtrace=$(set +o | grep xtrace)
1059 1060
     set +o xtrace
1060 1061
     local services=$@
1061 1062
     local package_dir=$(_get_package_dir)
... ...
@@ -1123,7 +1130,8 @@ function get_packages {
1123 1123
 # The same metadata used in the main DevStack prerequisite files may be used
1124 1124
 # in these prerequisite files, see get_packages() for more info.
1125 1125
 function get_plugin_packages {
1126
-    local xtrace=$(set +o | grep xtrace)
1126
+    local xtrace
1127
+    xtrace=$(set +o | grep xtrace)
1127 1128
     set +o xtrace
1128 1129
     local files_to_parse=""
1129 1130
     local package_dir=""
... ...
@@ -1148,7 +1156,8 @@ function update_package_repo {
1148 1148
     fi
1149 1149
 
1150 1150
     if is_ubuntu; then
1151
-        local xtrace=$(set +o | grep xtrace)
1151
+        local xtrace
1152
+    xtrace=$(set +o | grep xtrace)
1152 1153
         set +o xtrace
1153 1154
         if [[ "$REPOS_UPDATED" != "True" || "$RETRY_UPDATE" = "True" ]]; then
1154 1155
             # if there are transient errors pulling the updates, that's fine.
... ...
@@ -1854,7 +1863,8 @@ function enable_service {
1854 1854
 # Uses global ``ENABLED_SERVICES``
1855 1855
 # is_service_enabled service [service ...]
1856 1856
 function is_service_enabled {
1857
-    local xtrace=$(set +o | grep xtrace)
1857
+    local xtrace
1858
+    xtrace=$(set +o | grep xtrace)
1858 1859
     set +o xtrace
1859 1860
     local enabled=1
1860 1861
     local services=$@
... ...
@@ -1933,7 +1943,8 @@ function use_exclusive_service {
1933 1933
 # Only run the command if the target file (the last arg) is not on an
1934 1934
 # NFS filesystem.
1935 1935
 function _safe_permission_operation {
1936
-    local xtrace=$(set +o | grep xtrace)
1936
+    local xtrace
1937
+    xtrace=$(set +o | grep xtrace)
1937 1938
     set +o xtrace
1938 1939
     local args=( $@ )
1939 1940
     local last
... ...
@@ -17,7 +17,8 @@ set +o xtrace
17 17
 # Append a new option in an ini file without replacing the old value
18 18
 # iniadd [-sudo] config-file section option value1 value2 value3 ...
19 19
 function iniadd {
20
-    local xtrace=$(set +o | grep xtrace)
20
+    local xtrace
21
+    xtrace=$(set +o | grep xtrace)
21 22
     set +o xtrace
22 23
     local sudo=""
23 24
     if [ $1 == "-sudo" ]; then
... ...
@@ -37,7 +38,8 @@ function iniadd {
37 37
 # Comment an option in an INI file
38 38
 # inicomment [-sudo] config-file section option
39 39
 function inicomment {
40
-    local xtrace=$(set +o | grep xtrace)
40
+    local xtrace
41
+    xtrace=$(set +o | grep xtrace)
41 42
     set +o xtrace
42 43
     local sudo=""
43 44
     if [ $1 == "-sudo" ]; then
... ...
@@ -55,7 +57,8 @@ function inicomment {
55 55
 # Get an option from an INI file
56 56
 # iniget config-file section option
57 57
 function iniget {
58
-    local xtrace=$(set +o | grep xtrace)
58
+    local xtrace
59
+    xtrace=$(set +o | grep xtrace)
59 60
     set +o xtrace
60 61
     local file=$1
61 62
     local section=$2
... ...
@@ -70,7 +73,8 @@ function iniget {
70 70
 # Get a multiple line option from an INI file
71 71
 # iniget_multiline config-file section option
72 72
 function iniget_multiline {
73
-    local xtrace=$(set +o | grep xtrace)
73
+    local xtrace
74
+    xtrace=$(set +o | grep xtrace)
74 75
     set +o xtrace
75 76
     local file=$1
76 77
     local section=$2
... ...
@@ -85,7 +89,8 @@ function iniget_multiline {
85 85
 # Determinate is the given option present in the INI file
86 86
 # ini_has_option config-file section option
87 87
 function ini_has_option {
88
-    local xtrace=$(set +o | grep xtrace)
88
+    local xtrace
89
+    xtrace=$(set +o | grep xtrace)
89 90
     set +o xtrace
90 91
     local file=$1
91 92
     local section=$2
... ...
@@ -107,7 +112,8 @@ function ini_has_option {
107 107
 #
108 108
 # iniadd_literal [-sudo] config-file section option value
109 109
 function iniadd_literal {
110
-    local xtrace=$(set +o | grep xtrace)
110
+    local xtrace
111
+    xtrace=$(set +o | grep xtrace)
111 112
     set +o xtrace
112 113
     local sudo=""
113 114
     if [ $1 == "-sudo" ]; then
... ...
@@ -135,7 +141,8 @@ $option = $value
135 135
 # Remove an option from an INI file
136 136
 # inidelete [-sudo] config-file section option
137 137
 function inidelete {
138
-    local xtrace=$(set +o | grep xtrace)
138
+    local xtrace
139
+    xtrace=$(set +o | grep xtrace)
139 140
     set +o xtrace
140 141
     local sudo=""
141 142
     if [ $1 == "-sudo" ]; then
... ...
@@ -161,7 +168,8 @@ function inidelete {
161 161
 # iniset [-sudo] config-file section option value
162 162
 #  - if the file does not exist, it is created
163 163
 function iniset {
164
-    local xtrace=$(set +o | grep xtrace)
164
+    local xtrace
165
+    xtrace=$(set +o | grep xtrace)
165 166
     set +o xtrace
166 167
     local sudo=""
167 168
     if [ $1 == "-sudo" ]; then
... ...
@@ -198,7 +206,8 @@ $option = $value
198 198
 # Set a multiple line option in an INI file
199 199
 # iniset_multiline [-sudo] config-file section option value1 value2 valu3 ...
200 200
 function iniset_multiline {
201
-    local xtrace=$(set +o | grep xtrace)
201
+    local xtrace
202
+    xtrace=$(set +o | grep xtrace)
202 203
     set +o xtrace
203 204
     local sudo=""
204 205
     if [ $1 == "-sudo" ]; then
... ...
@@ -236,7 +245,8 @@ $option = $v
236 236
 # Uncomment an option in an INI file
237 237
 # iniuncomment config-file section option
238 238
 function iniuncomment {
239
-    local xtrace=$(set +o | grep xtrace)
239
+    local xtrace
240
+    xtrace=$(set +o | grep xtrace)
240 241
     set +o xtrace
241 242
     local sudo=""
242 243
     if [ $1 == "-sudo" ]; then
... ...
@@ -38,7 +38,8 @@ function get_pip_command {
38 38
 # Get the path to the direcotry where python executables are installed.
39 39
 # get_python_exec_prefix
40 40
 function get_python_exec_prefix {
41
-    local xtrace=$(set +o | grep xtrace)
41
+    local xtrace
42
+    xtrace=$(set +o | grep xtrace)
42 43
     set +o xtrace
43 44
     if [[ -z "$os_PACKAGE" ]]; then
44 45
         GetOSVersion
... ...
@@ -69,7 +70,8 @@ function pip_install_gr {
69 69
 # ``PIP_UPGRADE``, ``TRACK_DEPENDS``, ``*_proxy``,
70 70
 # pip_install package [package ...]
71 71
 function pip_install {
72
-    local xtrace=$(set +o | grep xtrace)
72
+    local xtrace
73
+    xtrace=$(set +o | grep xtrace)
73 74
     set +o xtrace
74 75
     local upgrade=""
75 76
     local offline=${OFFLINE:-False}