Package validation: also detect packages that failed to install
authorMichael Prokop <mika@grml.org>
Sun, 15 Jan 2012 22:05:08 +0000 (23:05 +0100)
committerMichael Prokop <mika@grml.org>
Sun, 15 Jan 2012 22:05:08 +0000 (23:05 +0100)
So far we detected only packages that have been requested for
installation but failed because the package isn't *available*
(as in not available in the configured Debian repositories).

Without checking for packages that have been requested for
installation but failed because of dependency issues we
might be left in a state with missing packages.

So let's check for both situations and generate according JUnit
reports.

etc/grml/fai/config/scripts/GRMLBASE/01-packages
grml-live

index 467586c..b13aab5 100755 (executable)
@@ -15,11 +15,22 @@ if ! [ -r "$target/${PACKAGE_LIST}" ] ; then
    echo "No $target/${PACKAGE_LIST} found, will not run package validation check."
 else
    printf "Validating package list: "
-   if $ROOTCMD dpkg --list $(grep -v '^#' $target/${PACKAGE_LIST} | grep -v -- '-$') >/dev/null 2>$LOGDIR/package_errors.log ; then
-      printf "done - no errors found\n"
-   else
+   TMPFILE=$(mktemp)
+
+   $ROOTCMD dpkg --list $(grep -v '^#' $target/${PACKAGE_LIST} | grep -v -- '-$') 2>&1 | \
+     grep -e '^un' -e 'No packages' > "$TMPFILE" || true
+
+   awk '/^un/ {print $2 " not_installable"}' "$TMPFILE" > "$LOGDIR/package_errors.log"
+   awk '/^No packages found matching/ {print $5 " not_available"}' "$TMPFILE" | \
+     sed 's/\. / /' >> "$LOGDIR/package_errors.log"
+
+   if [ -s "$TMPFILE" ] ; then
       printf "failed (there have been errors, find them at $LOGDIR/package_errors.log)\n"
+   else
+      printf "done - no errors found\n"
    fi
+
+   rm -f "$TMPFILE"
 fi
 
 ## END OF FILE #################################################################
index 1b119c1..efd7f7c 100755 (executable)
--- a/grml-live
+++ b/grml-live
@@ -754,11 +754,12 @@ else
 <testsuite name="grml-live-missing-packages" tests="${package_count}" time="1" failures="${package_errors}" errors="${package_errors}" skipped="0" assertions="0">
 EOF
 
-  for package in $(awk '{print $5}' "${CHECKLOG}/package_errors.log" | sed 's/\.$//') ; do
+  for package in $(awk '{print $1}' "${CHECKLOG}/package_errors.log") ; do
+    failure_reason="$(awk "/$package/ {print \$2}" "${CHECKLOG}/package_errors.log")"
     cat >> "${REPORT_MISSING_PACKAGES}" << EOF
   <testcase name="test_missing_packages_${package}" time="0" assertions="0">
-    <failure type="RuntimeError" message="Package ${package} is missing">
-Package $package is missing in chroot
+    <failure type="${failure_reason}" message="Package ${package} is missing">
+Package $package is missing in chroot (${failure_reason})
   </failure>
   </testcase>
 EOF