Browse code

yum_install: fix awk return code

TIL:

Similarly, all the END rules are merged, and executed when all the
input is exhausted (or when an exit statement is executed).

i.e. matching YUM_FAILED calls "exit", which falls through to the END
rules which calls "exit result" ... which is zero. i.e. if the return
code is 1 then we actually hide that and return with zero.

This is rather annoying because errors that should halt to alert us of
a package install failure pass through, only for you to have to debug
much later on seemingly unrelated problems.

This always sets "result" and thus should be returning the right
thing. I've updated the documentation to hopefully make it clearer
what's going on.

Change-Id: Ia15b7dc55efb8d3e3e945241b67a468b8a914672

Ian Wienand authored on 2016/09/23 14:08:48
Showing 1 changed files
... ...
@@ -1346,20 +1346,26 @@ function yum_install {
1346 1346
 
1347 1347
     time_start "yum_install"
1348 1348
 
1349
-    # - We run with LC_ALL=C so string matching *should* be OK
1350
-    # - Exit 1 if the failure might get better with a retry.
1351
-    # - Exit 2 if it is fatal.
1352
-    parse_yum_result='             \
1353
-        BEGIN { result=0 }         \
1354
-        /^YUM_FAILED/ { exit $2 }  \
1355
-        /^No package/ { result=2 } \
1356
-        /^Failed:/    { result=2 } \
1357
-        //{ print }                \
1349
+    # This is a bit tricky, because yum -y assumes missing or failed
1350
+    # packages are OK (see [1]).  We want devstack to stop if we are
1351
+    # installing missing packages.
1352
+    #
1353
+    # Thus we manually match on the output (stack.sh runs in a fixed
1354
+    # locale, so lang shouldn't change).
1355
+    #
1356
+    # If yum returns !0, we echo the result as "YUM_FAILED" and return
1357
+    # that from the awk (we're subverting -e with this trick).
1358
+    # Otherwise we use awk to look for failure strings and return "2"
1359
+    # to indicate a terminal failure.
1360
+    #
1361
+    # [1] https://bugzilla.redhat.com/show_bug.cgi?id=965567
1362
+    parse_yum_result='              \
1363
+        BEGIN { result=0 }          \
1364
+        /^YUM_FAILED/ { result=$2 } \
1365
+        /^No package/ { result=2 }  \
1366
+        /^Failed:/    { result=2 }  \
1367
+        //{ print }                 \
1358 1368
         END { exit result }'
1359
-
1360
-    # The manual check for missing packages is because yum -y assumes
1361
-    # missing or failed packages are OK.
1362
-    # See https://bugzilla.redhat.com/show_bug.cgi?id=965567
1363 1369
     (sudo_with_proxies "${YUM:-yum}" install -y "$@" 2>&1 || echo YUM_FAILED $?) \
1364 1370
         | awk "$parse_yum_result" && result=$? || result=$?
1365 1371