provide report of missing packages in xunit format for usage within e.g. Jenkins
[grml-live.git] / grml-live
index 3c15497..b14320b 100755 (executable)
--- a/grml-live
+++ b/grml-live
@@ -360,6 +360,7 @@ shift $(($OPTIND - 1))  # set ARGV to the first not parsed commandline parameter
 [ -n "$CHROOT_ARCHIVE" ]   || CHROOT_ARCHIVE="$OUTPUT/$(basename $CHROOT_OUTPUT).tgz"
 [ -n "$ISO_OUTPUT" ]       || ISO_OUTPUT="$OUTPUT/grml_isos"
 [ -n "$LOG_OUTPUT" ]       || LOG_OUTPUT="$OUTPUT/grml_logs"
+[ -n "$REPORTS" ]          || REPORTS="${LOG_OUTPUT}/reports/"
 # }}}
 
 # some misc checks before executing FAI {{{
@@ -696,20 +697,78 @@ fi # BUILD_DIRTY?
 
 # package validator {{{
 CHECKLOG=/var/log/fai/$HOSTNAME/last
-# package validator
-if [ -r "$CHECKLOG/package_errors.log" ] && grep -q '[a-z]' "$CHECKLOG/package_errors.log" ; then
+if [ -r "$CHECKLOG/dpkg.selections" ] ; then
+  package_count=$(wc -l "$CHECKLOG/dpkg.selections" | awk '{print $1}')
+else
+  package_count="unknown"
+fi
 
-   if [ -n "$EXIT_ON_MISSING_PACKAGES" -a -z "$BUILD_DIRTY" ] ; then
-      eerror "The following packages were requested for installation but could not be processed:"
-      cat $CHECKLOG/package_errors.log
-      eerror "... exiting as requested via \$EXIT_ON_MISSING_PACKAGES."
-      eend 1
-      bailout 13
-   else
-      ewarn "The following packages were requested for installation but could not be processed:"
-      cat $CHECKLOG/package_errors.log
-      eend 0
-   fi
+mkdir -p "$REPORTS"
+REPORT_MISSING_PACKAGES="${REPORTS}/TEST-MissingPackages.xml"
+
+# check for missing packages
+if ! [ -s "$CHECKLOG/package_errors.log" ] ; then
+  einfo "No missing packages found, generating empty junit report."
+
+  cat > "${REPORT_MISSING_PACKAGES}" << EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<testsuite name="grml-live-missing-packages" tests="${package_count}" time="1" failures="0" errors="0" skipped="0" assertions="0">
+  <testcase name="test_missing_packages" time="0" assertions="0">
+  </testcase>
+  <system-out>
+  </system-out>
+  <system-err>
+  </system-err>
+</testsuite>
+EOF
+  eend 0
+else
+  einfo "Missing packages found, generating junit report."
+
+  if [ -r "$CHECKLOG/package_errors.log" ] ; then
+    package_errors=$(wc -l "$CHECKLOG/package_errors.log" | awk '{print $1}')
+  else
+    package_errors="unknown"
+  fi
+
+  mkdir -p "$REPORTS"
+  REPORT_MISSING_PACKAGES="${REPORTS}/TEST-MissingPackages.xml"
+
+  cat > "${REPORT_MISSING_PACKAGES}" << EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<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
+    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>
+  </testcase>
+EOF
+  done
+
+  cat >> "${REPORT_MISSING_PACKAGES}" << EOF
+  <system-out>
+  </system-out>
+  <system-err>
+  </system-err>
+</testsuite>
+EOF
+  eend 0
+
+  if [ -n "$EXIT_ON_MISSING_PACKAGES" -a -z "$BUILD_DIRTY" ] ; then
+    eerror "The following packages were requested for installation but could not be processed:"
+    cat "$CHECKLOG/package_errors.log"
+    eerror "... exiting as requested via \$EXIT_ON_MISSING_PACKAGES."
+    eend 1
+    bailout 13
+  else
+    ewarn "The following packages were requested for installation but could not be processed:"
+    cat "$CHECKLOG/package_errors.log"
+    eend 0
+  fi
 fi
 # }}}