Browse code

Merge "Don't die when yum fails."

Jenkins authored on 2016/02/09 08:07:28
Showing 1 changed files
... ...
@@ -1338,27 +1338,35 @@ function uninstall_package {
1338 1338
 # Uses globals ``OFFLINE``, ``*_proxy``, ``YUM``
1339 1339
 # yum_install package [package ...]
1340 1340
 function yum_install {
1341
+    local result parse_yum_result
1342
+
1341 1343
     [[ "$OFFLINE" = "True" ]] && return
1342
-    local sudo="sudo"
1343
-    [[ "$(id -u)" = "0" ]] && sudo="env"
1344
+
1345
+    time_start "yum_install"
1346
+
1347
+    # Warning: this would not work if yum output message
1348
+    # have been translated to another language
1349
+    parse_yum_result='\
1350
+        BEGIN { result=0 }\
1351
+        /^YUM_FAILED/ { exit $2 }\
1352
+        /^No package/ { result=1 }\
1353
+        //{ print }\
1354
+        END { exit result }'
1344 1355
 
1345 1356
     # The manual check for missing packages is because yum -y assumes
1346
-    # missing packages are OK.  See
1347
-    # https://bugzilla.redhat.com/show_bug.cgi?id=965567
1348
-    $sudo http_proxy="${http_proxy:-}" https_proxy="${https_proxy:-}" \
1349
-        no_proxy="${no_proxy:-}" \
1350
-        ${YUM:-yum} install -y "$@" 2>&1 | \
1351
-        awk '
1352
-            BEGIN { fail=0 }
1353
-            /No package/ { fail=1 }
1354
-            { print }
1355
-            END { exit fail }' || \
1356
-                die $LINENO "Missing packages detected"
1357
+    # missing packages are OK.
1358
+    # See https://bugzilla.redhat.com/show_bug.cgi?id=965567
1359
+    (sudo_with_proxies "${YUM:-yum}" install -y "$@" 2>&1 || echo YUM_FAILED $?) \
1360
+        | awk "$parse_yum_result"
1361
+    result=$?
1357 1362
 
1358
-    # also ensure we catch a yum failure
1359
-    if [[ ${PIPESTATUS[0]} != 0 ]]; then
1360
-        die $LINENO "${YUM:-yum} install failure"
1363
+    if [ "$result" != 0 ]; then
1364
+        echo $LINENO "${YUM:-yum}" install failure: $result
1361 1365
     fi
1366
+
1367
+    time_stop "yum_install"
1368
+
1369
+    return "$result"
1362 1370
 }
1363 1371
 
1364 1372
 # zypper wrapper to set arguments correctly
... ...
@@ -2297,6 +2305,18 @@ function test_with_retry {
2297 2297
     time_stop "test_with_retry"
2298 2298
 }
2299 2299
 
2300
+# Like sudo but forwarding http_proxy https_proxy no_proxy environment vars.
2301
+# If it is run as superuser then sudo is replaced by env.
2302
+#
2303
+function sudo_with_proxies {
2304
+    local sudo
2305
+
2306
+    [[ "$(id -u)" = "0" ]] && sudo="env" || sudo="sudo"
2307
+
2308
+    $sudo http_proxy="${http_proxy:-}" https_proxy="${https_proxy:-}"\
2309
+        no_proxy="${no_proxy:-}" "$@"
2310
+}
2311
+
2300 2312
 # Timing infrastructure - figure out where large blocks of time are
2301 2313
 # used in DevStack
2302 2314
 #