123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- #!/bin/bash
-
- shellfu import jat
- shellfu import jat_dump
- shellfu import preupg
- shellfu import preupg_fupath
- shellfu import xcase
-
- T_MESSAGE=
- T_RISKTXT='Please, install all required packages (and binaries) and run preupg again to process check properly.'
- #shellcheck disable=SC2034
- PREUPG__RULE=xccdf_preupg_rule_api_binary_req_check
-
- assert_irisknum() {
- jat__cmp -h "number of per-item risks is $1" \
- "$(wc -l <irisks)" eq "$1"
- }
-
- mkbrq() {
- #
- # Produce the binary_req INI key/value pair
- #
- local head=true
- test -n "$bins" || return 0
- echo -n "binary_req = "
- for bin in "${bins[@]}";
- do
- $head || echo -n ', '
- case $bin in
- mandatory) echo -n "rpm" ;;
- impossible) echo -n "nonexistentbin$(rtoken)" ;;
- esac
- head=false
- done
- echo
- }
-
- rtoken() {
- head -c 1000 /dev/urandom \
- | md5sum \
- | head -c 7
- }
-
- XCASE__ARRAYS=bins
-
- xcase__enum() {
- #
- # Enumerate subtest ids
- #
- # Variables:
- #
- # * lang - language used: `py` for Python, `sh` for Bash
- #
- # * bins - binary "availability classes" used for testing. This defines
- # what kind of binary name will be added to binary_req. Multiple
- # classes mean there will be multiple binary names.
- #
- # `mandatory` means a binary such as "rpm" that is impossible to
- # *not* be on the system. `impossible` means a randomly generated
- # binary name.
- #
- #
-
- for lang in py sh;
- do
- echo lang=$lang,bins=mandatory
- echo lang=$lang,bins=impossible
- echo lang=$lang,bins=
- echo lang=$lang,bins=mandatory+mandatory
- echo lang=$lang,bins=mandatory+impossible
- echo lang=$lang,bins=impossible+mandatory
- echo lang=$lang,bins=impossible+impossible
- done
-
- }
-
- #shellcheck disable=SC2154
- xcase__setup() {
- #
- # Prepare for subtest
- #
- T_MESSAGE=message$(rtoken)
- {
- echo '[preupgrade]'
- mkbrq
- echo "[MODULE]"
- echo "GROUP = api"
- echo "NAME = binary_req"
- echo "LANG = $lang"
- case $lang in
- py)
- echo "CODE = log_info('$T_MESSAGE')"
- echo "CODE = exit_informational()"
- ;;
- sh)
- echo "CODE = log_info $T_MESSAGE"
- echo "CODE = exit_informational"
- ;;
- esac
- } > module.ini
- preupg_fupath RHEL6_7 module.ini
- jat__cmd -h "work around BZ#1368823" \
- cp -ar RHEL6_7 RHEL6_7-backup
- PREUPG__UPATH="RHEL6_7/all-xccdf.xml" \
- preupg__run1
- preupg__get_messages > messages
- preupg__get_risks > risks
- grep 'HIGH: Binary .* is not installed' risks > irisks
- }
-
- xcase__test() {
- #
- # Do the work
- #
- local o_behavior=ok # behavior class
- local o_irisknum=0 # per-item risks
-
- for bin in "${bins[@]}"
- do
- case $bin in
- impossible)
- o_behavior=fail
- ((o_irisknum++))
- ;;
- esac
- done
-
- case $o_behavior in
- ok)
- preupg__assert \
- result "informational" \
- -N risk.high "$T_RISKTXT" \
- msg.info "$T_MESSAGE"
- assert_irisknum 0
- ;;
- fail)
- preupg__assert \
- result "needs_action" \
- risk.high "$T_RISKTXT" \
- -N msg.info "$T_MESSAGE"
- assert_irisknum $o_irisknum
- ;;
- esac
-
- }
-
- xcase__diag() {
- #
- # Burp up some diag
- #
- jat_dump__file module.ini risks messages irisks
- }
-
- xcase__cleanup() {
- #
- # Clean up after subtest
- #
- preupg__rmresult
- }
-
-
- xcase__run -v
- preupg__Cleanup
|