#!/bin/bash shellfu import jat_dump shellfu import preupg shellfu import preupg_fupath assert_html_ok() { # # Do sanity test for result.html # local fpath="$1" jat__cmd -h "it's not empty: $fpath" \ test -s "$fpath" jat__cmd -h "no _SOLUTION_MSG* placeholders: $fpath" \ -S 1 \ grep _SOLUTION_MSG "$fpath" } assert_xml_ok() { # # Do sanity test for result.html # local fpath="$1" jat__cmd -h "its not empty: $fpath" \ test -s "$fpath" jat__cmd -h "it's a valid XML: $fpath" \ xmllint "$fpath" } assert_tarball_ok() { # # Do sanity test for tarball # local fpath="$1" # path to tarball local fname # tarball filename local path # one of mandatory paths from enum_tarball_paths() local pfx # volatile path prefix (also part of tarball name) fname=$(basename "$fpath") pfx=${fname%.tar.gz} jat__cmd -h "file name determined" \ test -n "$fpath" || return 1 jat__cmd -h "file is not empty" \ test -s "$fpath" || return 1 preupg__tar_list > tarball_contents.txt jat__cmd -h "file contents are not empty" \ test -s tarball_contents.txt || return 1 jat__cmd -h "file layout is nested" -S 1 \ grep -v "^$pfx/" tarball_contents.txt jat__cmd -h "shadow and gshadow files are not packed" -S 1 \ grep -we 'shadow$' -e 'gshadow$' tarball_contents.txt for path in $(enum_tarball_paths); do jat__cmd -h "file $path is present" \ grep -qxF "$pfx/$path" tarball_contents.txt done for path in $(enum_tarball_nopaths); do jat__cmd -h "file $path is not present" -S 1 \ grep -qxF "$pfx/$path" tarball_contents.txt done jat_dump__file tarball_contents.txt } enum_tarball_paths() { # # Enumerate relative paths that must exist in tarball # # Paths here are listed *without* the "preupg_results-160608163404" # prefix as that is volatile but expected. # echo README echo cleanconf/ echo common/ echo dirtyconf/ echo kickstart/ echo noauto_postupgrade.d/ echo postupgrade.d/ echo preupgrade-scripts/ echo result.html echo result.xml } enum_tarball_nopaths() { # # Enumerate relative paths that must NOT exist in tarball # # Paths here are listed *without* the "preupg_results-160608163404" # prefix as that is volatile but expected. # echo result-admin.html # BZ#1414322 echo result-admin.xml # BZ#1414322 } add_3pmod() { # # Add 3rdparty module # # 3rdparty modules need to be added *after* composing, so in order # to take advantage of preupgrade-assistant/fupath, we'll build # separate throw-away set and just move the source files. # preupg_fupath \ THIRD \ @3rdparty mkdir -p FOO/3rdparty/a_custom_module { echo '[preupgrade]' echo 'group_title = A nice group title' } >FOO/3rdparty/group.ini mv THIRD/3rdparty/a_custom_module/{solution.txt,check,module.ini} \ FOO/3rdparty/a_custom_module } jat__pstarts "prepare fake upgrade path" preupg_fupath \ FOO \ @failed \ @fixed \ @informational \ @needs_action \ @needs_inspection \ @not_applicable \ @pass add_3pmod jat__cmd -h "make backup of upgrade path" \ cp -ar FOO FOO-backup jat__pend jat__pstarts "prepare results" PREUPG__UPATH="FOO/all-xccdf.xml" \ preupg__run1 jat__cmd -h "tarball found" \ test -n "$(preupg__get_latest_tar)" preupg__lsrules_ast \ | jat_dump__pipe AST_RULES jat__pend jat__pstartt "check if upgrade path has been changed - BZ#1368823" jat__cmd -h "custom upgrade path has not been changed (bz1368823)" \ -o updiff \ diff -ru FOO FOO-backup jat_dump__file -E updiff test -s updiff && jat__submit updiff FOO.diff jat__pend jat__pstartt "check result*.html" assert_html_ok /root/preupgrade/result.html jat__pend jat__pstartt "check result*.xml" assert_xml_ok /root/preupgrade/result.xml jat__pend jat__pstartt "check tarball" assert_tarball_ok "$(preupg__get_latest_tar)" jat__pend jat__pstartt "check that 3rdparty module has run" preupg__assert -r xccdf_preupg_rule_3rdparty_a_custom_module_check \ result pass jat__pend preupg__Cleanup