Not all yum failures has to be considered
catastrofic failures also because install_package
function should implement the same behavior in Fedora,
CentOS and Ubuntu. Let return the error to be solved at higher
level.
Change-Id: I93e9f312a94aeb086925e069a83ec1d3d3419423
Closes-Bug: #1522590
| ... | ... |
@@ -1320,27 +1320,35 @@ function uninstall_package {
|
| 1320 | 1320 |
# Uses globals ``OFFLINE``, ``*_proxy``, ``YUM`` |
| 1321 | 1321 |
# yum_install package [package ...] |
| 1322 | 1322 |
function yum_install {
|
| 1323 |
+ local result parse_yum_result |
|
| 1324 |
+ |
|
| 1323 | 1325 |
[[ "$OFFLINE" = "True" ]] && return |
| 1324 |
- local sudo="sudo" |
|
| 1325 |
- [[ "$(id -u)" = "0" ]] && sudo="env" |
|
| 1326 |
+ |
|
| 1327 |
+ time_start "yum_install" |
|
| 1328 |
+ |
|
| 1329 |
+ # Warning: this would not work if yum output message |
|
| 1330 |
+ # have been translated to another language |
|
| 1331 |
+ parse_yum_result='\ |
|
| 1332 |
+ BEGIN { result=0 }\
|
|
| 1333 |
+ /^YUM_FAILED/ { exit $2 }\
|
|
| 1334 |
+ /^No package/ { result=1 }\
|
|
| 1335 |
+ //{ print }\
|
|
| 1336 |
+ END { exit result }'
|
|
| 1326 | 1337 |
|
| 1327 | 1338 |
# The manual check for missing packages is because yum -y assumes |
| 1328 |
- # missing packages are OK. See |
|
| 1329 |
- # https://bugzilla.redhat.com/show_bug.cgi?id=965567 |
|
| 1330 |
- $sudo http_proxy="${http_proxy:-}" https_proxy="${https_proxy:-}" \
|
|
| 1331 |
- no_proxy="${no_proxy:-}" \
|
|
| 1332 |
- ${YUM:-yum} install -y "$@" 2>&1 | \
|
|
| 1333 |
- awk ' |
|
| 1334 |
- BEGIN { fail=0 }
|
|
| 1335 |
- /No package/ { fail=1 }
|
|
| 1336 |
- { print }
|
|
| 1337 |
- END { exit fail }' || \
|
|
| 1338 |
- die $LINENO "Missing packages detected" |
|
| 1339 |
+ # missing packages are OK. |
|
| 1340 |
+ # See https://bugzilla.redhat.com/show_bug.cgi?id=965567 |
|
| 1341 |
+ (sudo_with_proxies "${YUM:-yum}" install -y "$@" 2>&1 || echo YUM_FAILED $?) \
|
|
| 1342 |
+ | awk "$parse_yum_result" |
|
| 1343 |
+ result=$? |
|
| 1339 | 1344 |
|
| 1340 |
- # also ensure we catch a yum failure |
|
| 1341 |
- if [[ ${PIPESTATUS[0]} != 0 ]]; then
|
|
| 1342 |
- die $LINENO "${YUM:-yum} install failure"
|
|
| 1345 |
+ if [ "$result" != 0 ]; then |
|
| 1346 |
+ echo $LINENO "${YUM:-yum}" install failure: $result
|
|
| 1343 | 1347 |
fi |
| 1348 |
+ |
|
| 1349 |
+ time_stop "yum_install" |
|
| 1350 |
+ |
|
| 1351 |
+ return "$result" |
|
| 1344 | 1352 |
} |
| 1345 | 1353 |
|
| 1346 | 1354 |
# zypper wrapper to set arguments correctly |
| ... | ... |
@@ -2279,6 +2287,18 @@ function test_with_retry {
|
| 2279 | 2279 |
time_stop "test_with_retry" |
| 2280 | 2280 |
} |
| 2281 | 2281 |
|
| 2282 |
+# Like sudo but forwarding http_proxy https_proxy no_proxy environment vars. |
|
| 2283 |
+# If it is run as superuser then sudo is replaced by env. |
|
| 2284 |
+# |
|
| 2285 |
+function sudo_with_proxies {
|
|
| 2286 |
+ local sudo |
|
| 2287 |
+ |
|
| 2288 |
+ [[ "$(id -u)" = "0" ]] && sudo="env" || sudo="sudo" |
|
| 2289 |
+ |
|
| 2290 |
+ $sudo http_proxy="${http_proxy:-}" https_proxy="${https_proxy:-}"\
|
|
| 2291 |
+ no_proxy="${no_proxy:-}" "$@"
|
|
| 2292 |
+} |
|
| 2293 |
+ |
|
| 2282 | 2294 |
# Timing infrastructure - figure out where large blocks of time are |
| 2283 | 2295 |
# used in DevStack |
| 2284 | 2296 |
# |