we are xtrace happy, however that's just generating bulk in log
files that are mostly ignorable. For the basically bullet proof
functions we should not xtrace.
Change-Id: Iab4e6d270c1546e0db2a06395cefcdf7f7929c3c
... | ... |
@@ -39,59 +39,76 @@ set +o xtrace |
39 | 39 |
# Append a new option in an ini file without replacing the old value |
40 | 40 |
# iniadd config-file section option value1 value2 value3 ... |
41 | 41 |
function iniadd() { |
42 |
+ local xtrace=$(set +o | grep xtrace) |
|
43 |
+ set +o xtrace |
|
42 | 44 |
local file=$1 |
43 | 45 |
local section=$2 |
44 | 46 |
local option=$3 |
45 | 47 |
shift 3 |
46 | 48 |
local values="$(iniget_multiline $file $section $option) $@" |
47 | 49 |
iniset_multiline $file $section $option $values |
50 |
+ $xtrace |
|
48 | 51 |
} |
49 | 52 |
|
50 | 53 |
# Comment an option in an INI file |
51 | 54 |
# inicomment config-file section option |
52 | 55 |
function inicomment() { |
56 |
+ local xtrace=$(set +o | grep xtrace) |
|
57 |
+ set +o xtrace |
|
53 | 58 |
local file=$1 |
54 | 59 |
local section=$2 |
55 | 60 |
local option=$3 |
56 | 61 |
sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" "$file" |
62 |
+ $xtrace |
|
57 | 63 |
} |
58 | 64 |
|
59 | 65 |
# Get an option from an INI file |
60 | 66 |
# iniget config-file section option |
61 | 67 |
function iniget() { |
68 |
+ local xtrace=$(set +o | grep xtrace) |
|
69 |
+ set +o xtrace |
|
62 | 70 |
local file=$1 |
63 | 71 |
local section=$2 |
64 | 72 |
local option=$3 |
65 | 73 |
local line |
66 | 74 |
line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file") |
67 | 75 |
echo ${line#*=} |
76 |
+ $xtrace |
|
68 | 77 |
} |
69 | 78 |
|
70 | 79 |
# Get a multiple line option from an INI file |
71 | 80 |
# iniget_multiline config-file section option |
72 | 81 |
function iniget_multiline() { |
82 |
+ local xtrace=$(set +o | grep xtrace) |
|
83 |
+ set +o xtrace |
|
73 | 84 |
local file=$1 |
74 | 85 |
local section=$2 |
75 | 86 |
local option=$3 |
76 | 87 |
local values |
77 | 88 |
values=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { s/^$option[ \t]*=[ \t]*//gp; }" "$file") |
78 | 89 |
echo ${values} |
90 |
+ $xtrace |
|
79 | 91 |
} |
80 | 92 |
|
81 | 93 |
# Determinate is the given option present in the INI file |
82 | 94 |
# ini_has_option config-file section option |
83 | 95 |
function ini_has_option() { |
96 |
+ local xtrace=$(set +o | grep xtrace) |
|
97 |
+ set +o xtrace |
|
84 | 98 |
local file=$1 |
85 | 99 |
local section=$2 |
86 | 100 |
local option=$3 |
87 | 101 |
local line |
88 | 102 |
line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file") |
103 |
+ $xtrace |
|
89 | 104 |
[ -n "$line" ] |
90 | 105 |
} |
91 | 106 |
|
92 | 107 |
# Set an option in an INI file |
93 | 108 |
# iniset config-file section option value |
94 | 109 |
function iniset() { |
110 |
+ local xtrace=$(set +o | grep xtrace) |
|
111 |
+ set +o xtrace |
|
95 | 112 |
local file=$1 |
96 | 113 |
local section=$2 |
97 | 114 |
local option=$3 |
... | ... |
@@ -113,11 +130,14 @@ $option = $value |
113 | 113 |
# Replace it |
114 | 114 |
sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('${option}'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file" |
115 | 115 |
fi |
116 |
+ $xtrace |
|
116 | 117 |
} |
117 | 118 |
|
118 | 119 |
# Set a multiple line option in an INI file |
119 | 120 |
# iniset_multiline config-file section option value1 value2 valu3 ... |
120 | 121 |
function iniset_multiline() { |
122 |
+ local xtrace=$(set +o | grep xtrace) |
|
123 |
+ set +o xtrace |
|
121 | 124 |
local file=$1 |
122 | 125 |
local section=$2 |
123 | 126 |
local option=$3 |
... | ... |
@@ -142,15 +162,19 @@ function iniset_multiline() { |
142 | 142 |
$option = $v |
143 | 143 |
" "$file" |
144 | 144 |
done |
145 |
+ $xtrace |
|
145 | 146 |
} |
146 | 147 |
|
147 | 148 |
# Uncomment an option in an INI file |
148 | 149 |
# iniuncomment config-file section option |
149 | 150 |
function iniuncomment() { |
151 |
+ local xtrace=$(set +o | grep xtrace) |
|
152 |
+ set +o xtrace |
|
150 | 153 |
local file=$1 |
151 | 154 |
local section=$2 |
152 | 155 |
local option=$3 |
153 | 156 |
sed -i -e "/^\[$section\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" "$file" |
157 |
+ $xtrace |
|
154 | 158 |
} |
155 | 159 |
|
156 | 160 |
# Normalize config values to True or False |
... | ... |
@@ -158,6 +182,8 @@ function iniuncomment() { |
158 | 158 |
# Accepts as True: 1 yes Yes YES true True TRUE |
159 | 159 |
# VAR=$(trueorfalse default-value test-value) |
160 | 160 |
function trueorfalse() { |
161 |
+ local xtrace=$(set +o | grep xtrace) |
|
162 |
+ set +o xtrace |
|
161 | 163 |
local default=$1 |
162 | 164 |
local testval=$2 |
163 | 165 |
|
... | ... |
@@ -165,6 +191,7 @@ function trueorfalse() { |
165 | 165 |
[[ "0 no No NO false False FALSE" =~ "$testval" ]] && { echo "False"; return; } |
166 | 166 |
[[ "1 yes Yes YES true True TRUE" =~ "$testval" ]] && { echo "True"; return; } |
167 | 167 |
echo "$default" |
168 |
+ $xtrace |
|
168 | 169 |
} |
169 | 170 |
|
170 | 171 |
|
... | ... |
@@ -675,9 +702,14 @@ function _get_package_dir() { |
675 | 675 |
# Uses globals ``OFFLINE``, ``*_proxy`` |
676 | 676 |
# apt_get operation package [package ...] |
677 | 677 |
function apt_get() { |
678 |
+ local xtrace=$(set +o | grep xtrace) |
|
679 |
+ set +o xtrace |
|
680 |
+ |
|
678 | 681 |
[[ "$OFFLINE" = "True" || -z "$@" ]] && return |
679 | 682 |
local sudo="sudo" |
680 | 683 |
[[ "$(id -u)" = "0" ]] && sudo="env" |
684 |
+ |
|
685 |
+ $xtrace |
|
681 | 686 |
$sudo DEBIAN_FRONTEND=noninteractive \ |
682 | 687 |
http_proxy=$http_proxy https_proxy=$https_proxy \ |
683 | 688 |
no_proxy=$no_proxy \ |
... | ... |
@@ -695,6 +727,8 @@ function apt_get() { |
695 | 695 |
# - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection |
696 | 696 |
# of the package to the distros listed. The distro names are case insensitive. |
697 | 697 |
function get_packages() { |
698 |
+ local xtrace=$(set +o | grep xtrace) |
|
699 |
+ set +o xtrace |
|
698 | 700 |
local services=$@ |
699 | 701 |
local package_dir=$(_get_package_dir) |
700 | 702 |
local file_to_parse |
... | ... |
@@ -706,6 +740,7 @@ function get_packages() { |
706 | 706 |
fi |
707 | 707 |
if [[ -z "$DISTRO" ]]; then |
708 | 708 |
GetDistro |
709 |
+ echo "Found Distro $DISTRO" |
|
709 | 710 |
fi |
710 | 711 |
for service in ${services//,/ }; do |
711 | 712 |
# Allow individual services to specify dependencies |
... | ... |
@@ -797,23 +832,30 @@ function get_packages() { |
797 | 797 |
done |
798 | 798 |
IFS=$OIFS |
799 | 799 |
done |
800 |
+ $xtrace |
|
800 | 801 |
} |
801 | 802 |
|
802 | 803 |
# Distro-agnostic package installer |
803 | 804 |
# install_package package [package ...] |
804 | 805 |
function install_package() { |
806 |
+ local xtrace=$(set +o | grep xtrace) |
|
807 |
+ set +o xtrace |
|
805 | 808 |
if is_ubuntu; then |
806 | 809 |
# if there are transient errors pulling the updates, that's fine. It may |
807 | 810 |
# be secondary repositories that we don't really care about. |
808 | 811 |
[[ "$NO_UPDATE_REPOS" = "True" ]] || apt_get update || /bin/true |
809 | 812 |
NO_UPDATE_REPOS=True |
810 | 813 |
|
814 |
+ $xtrace |
|
811 | 815 |
apt_get install "$@" |
812 | 816 |
elif is_fedora; then |
817 |
+ $xtrace |
|
813 | 818 |
yum_install "$@" |
814 | 819 |
elif is_suse; then |
820 |
+ $xtrace |
|
815 | 821 |
zypper_install "$@" |
816 | 822 |
else |
823 |
+ $xtrace |
|
817 | 824 |
exit_distro_not_supported "installing packages" |
818 | 825 |
fi |
819 | 826 |
} |
... | ... |
@@ -1092,7 +1134,13 @@ function get_python_exec_prefix() { |
1092 | 1092 |
# ``TRACK_DEPENDS``, ``*_proxy`` |
1093 | 1093 |
# pip_install package [package ...] |
1094 | 1094 |
function pip_install { |
1095 |
- [[ "$OFFLINE" = "True" || -z "$@" ]] && return |
|
1095 |
+ local xtrace=$(set +o | grep xtrace) |
|
1096 |
+ set +o xtrace |
|
1097 |
+ if [[ "$OFFLINE" = "True" || -z "$@" ]]; then |
|
1098 |
+ $xtrace |
|
1099 |
+ return |
|
1100 |
+ fi |
|
1101 |
+ |
|
1096 | 1102 |
if [[ -z "$os_PACKAGE" ]]; then |
1097 | 1103 |
GetOSVersion |
1098 | 1104 |
fi |
... | ... |
@@ -1121,6 +1169,7 @@ function pip_install { |
1121 | 1121 |
# this problem. See https://github.com/pypa/pip/issues/709 |
1122 | 1122 |
local pip_build_tmp=$(mktemp --tmpdir -d pip-build.XXXXX) |
1123 | 1123 |
|
1124 |
+ $xtrace |
|
1124 | 1125 |
$SUDO_PIP PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-/var/cache/pip} \ |
1125 | 1126 |
HTTP_PROXY=$http_proxy \ |
1126 | 1127 |
HTTPS_PROXY=$https_proxy \ |
... | ... |
@@ -1235,32 +1284,36 @@ function enable_service() { |
1235 | 1235 |
# Uses global ``ENABLED_SERVICES`` |
1236 | 1236 |
# is_service_enabled service [service ...] |
1237 | 1237 |
function is_service_enabled() { |
1238 |
+ local xtrace=$(set +o | grep xtrace) |
|
1239 |
+ set +o xtrace |
|
1240 |
+ local enabled=1 |
|
1238 | 1241 |
services=$@ |
1239 | 1242 |
for service in ${services}; do |
1240 |
- [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0 |
|
1243 |
+ [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && enabled=0 |
|
1241 | 1244 |
|
1242 | 1245 |
# Look for top-level 'enabled' function for this service |
1243 | 1246 |
if type is_${service}_enabled >/dev/null 2>&1; then |
1244 | 1247 |
# A function exists for this service, use it |
1245 | 1248 |
is_${service}_enabled |
1246 |
- return $? |
|
1249 |
+ enabled=$? |
|
1247 | 1250 |
fi |
1248 | 1251 |
|
1249 | 1252 |
# TODO(dtroyer): Remove these legacy special-cases after the is_XXX_enabled() |
1250 | 1253 |
# are implemented |
1251 | 1254 |
|
1252 |
- [[ ${service} == n-cell-* && ${ENABLED_SERVICES} =~ "n-cell" ]] && return 0 |
|
1253 |
- [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0 |
|
1254 |
- [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && return 0 |
|
1255 |
- [[ ${service} == "ceilometer" && ${ENABLED_SERVICES} =~ "ceilometer-" ]] && return 0 |
|
1256 |
- [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0 |
|
1257 |
- [[ ${service} == "ironic" && ${ENABLED_SERVICES} =~ "ir-" ]] && return 0 |
|
1258 |
- [[ ${service} == "neutron" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0 |
|
1259 |
- [[ ${service} == "trove" && ${ENABLED_SERVICES} =~ "tr-" ]] && return 0 |
|
1260 |
- [[ ${service} == "swift" && ${ENABLED_SERVICES} =~ "s-" ]] && return 0 |
|
1261 |
- [[ ${service} == s-* && ${ENABLED_SERVICES} =~ "swift" ]] && return 0 |
|
1255 |
+ [[ ${service} == n-cell-* && ${ENABLED_SERVICES} =~ "n-cell" ]] && enabled=0 |
|
1256 |
+ [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && enabled=0 |
|
1257 |
+ [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && enabled=0 |
|
1258 |
+ [[ ${service} == "ceilometer" && ${ENABLED_SERVICES} =~ "ceilometer-" ]] && enabled=0 |
|
1259 |
+ [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && enabled=0 |
|
1260 |
+ [[ ${service} == "ironic" && ${ENABLED_SERVICES} =~ "ir-" ]] && enabled=0 |
|
1261 |
+ [[ ${service} == "neutron" && ${ENABLED_SERVICES} =~ "q-" ]] && enabled=0 |
|
1262 |
+ [[ ${service} == "trove" && ${ENABLED_SERVICES} =~ "tr-" ]] && enabled=0 |
|
1263 |
+ [[ ${service} == "swift" && ${ENABLED_SERVICES} =~ "s-" ]] && enabled=0 |
|
1264 |
+ [[ ${service} == s-* && ${ENABLED_SERVICES} =~ "swift" ]] && enabled=0 |
|
1262 | 1265 |
done |
1263 |
- return 1 |
|
1266 |
+ $xtrace |
|
1267 |
+ return $enabled |
|
1264 | 1268 |
} |
1265 | 1269 |
|
1266 | 1270 |
# Toggle enable/disable_service for services that must run exclusive of each other |
... | ... |
@@ -1286,6 +1339,8 @@ function use_exclusive_service { |
1286 | 1286 |
# Only run the command if the target file (the last arg) is not on an |
1287 | 1287 |
# NFS filesystem. |
1288 | 1288 |
function _safe_permission_operation() { |
1289 |
+ local xtrace=$(set +o | grep xtrace) |
|
1290 |
+ set +o xtrace |
|
1289 | 1291 |
local args=( $@ ) |
1290 | 1292 |
local last |
1291 | 1293 |
local sudo_cmd |
... | ... |
@@ -1299,6 +1354,7 @@ function _safe_permission_operation() { |
1299 | 1299 |
fi |
1300 | 1300 |
|
1301 | 1301 |
if is_nfs_directory "$dir_to_check" ; then |
1302 |
+ $xtrace |
|
1302 | 1303 |
return 0 |
1303 | 1304 |
fi |
1304 | 1305 |
|
... | ... |
@@ -1308,6 +1364,7 @@ function _safe_permission_operation() { |
1308 | 1308 |
sudo_cmd="sudo" |
1309 | 1309 |
fi |
1310 | 1310 |
|
1311 |
+ $xtrace |
|
1311 | 1312 |
$sudo_cmd $@ |
1312 | 1313 |
} |
1313 | 1314 |
|
... | ... |
@@ -529,6 +529,7 @@ if [[ -n "$LOGFILE" ]]; then |
529 | 529 |
if [[ "$VERBOSE" == "True" ]]; then |
530 | 530 |
# Redirect stdout/stderr to tee to write the log file |
531 | 531 |
exec 1> >( awk ' |
532 |
+ /((set \+o$)|xtrace)/ { next } |
|
532 | 533 |
{ |
533 | 534 |
cmd ="date +\"%Y-%m-%d %H:%M:%S \"" |
534 | 535 |
cmd | getline now |