From 0919f97151cc7edd3aaa0eeefb5b087aef39ee50 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Wed, 30 Apr 2025 10:42:38 +0100 Subject: [PATCH 1/2] Allow more than 1 second for relevant entries to appear in `/var/log/maillog` With this change, the test will give up after a minute but will check for the expected pattern in the log every second This script runs with `/bin/sh` but really, it will fail in all below places with multiple POSIX compat shells and was clearly designed to run with BASH: ``` if [ $MTA_ACCEPT == 0 ] # W: In POSIX sh, == in place of = is undefined. if [[ $mail =~ $regex ]] # W: In POSIX sh, [[ ]] is undefined. if ([ $MTA_ACCEPT == 0 ] && [ $DELIVERED == 0 ]) # W: In POSIX sh, == in place of = is undefined. egrep -q "${BASH_REMATCH[1]}\:.*stat\=Sent" /var/log/maillog # W: In POSIX sh, BASH_REMATCH is undefined. echo -e # W: In POSIX sh, echo flags are undefined. ``` Wherever possible, I replaced `==` with `=` (which will work with BASH and any POSIX compat shell) but since there are other BASH specific features that are being used, changed to `#!/bin/bash` --- tests/p_sendmail/20_sendmail_mta.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/p_sendmail/20_sendmail_mta.sh b/tests/p_sendmail/20_sendmail_mta.sh index 2e24960..5f59f0d 100755 --- a/tests/p_sendmail/20_sendmail_mta.sh +++ b/tests/p_sendmail/20_sendmail_mta.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Author: Christoph Galuschka t_Log "Running $0 - sendmail can accept and deliver local email." @@ -7,16 +7,16 @@ if [ "$CONTAINERTEST" -eq "1" ]; then exit 0 fi ret_val=1 +DELIVERED=1 # send mail to localhost mail=$(echo -e "helo localhost\nmail from: root@localhost\nrcpt to: root@localhost\ndata\nt_functional test\n.\nquit\n" | nc -w 5 127.0.0.1 25 | grep accepted) MTA_ACCEPT=$? -if [ $MTA_ACCEPT == 0 ] +if [ $MTA_ACCEPT = 0 ] then t_Log 'Mail has been queued successfully' fi -sleep 1 if [ "$centos_ver" -eq "8" ]; then t_Log "Dumping journalctl to /var/log/maillog" @@ -25,11 +25,18 @@ fi regex='250\ 2\.0\.0\ ([0-9A-Za-z]*)\ Message\ accepted\ for\ delivery' if [[ $mail =~ $regex ]] then - egrep -q "${BASH_REMATCH[1]}\:.*stat\=Sent" /var/log/maillog - DELIVERED=$? + for i in $(seq 1 60); do + egrep -q "${BASH_REMATCH[1]}\:.*stat\=Sent" /var/log/maillog + DELIVERED=$? + if [ "$DELIVERED" -ne 0 ];then + sleep 1 + else + break; + fi + done fi -if ([ $MTA_ACCEPT == 0 ] && [ $DELIVERED == 0 ]) +if [ $MTA_ACCEPT = 0 ] && [ $DELIVERED = 0 ] then ret_val=0 t_Log 'Mail has been delivered and removed from queue.' From 1d9f72a8352738fcb50478b2dfccd22feca29c8f Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Wed, 30 Apr 2025 10:42:55 +0100 Subject: [PATCH 2/2] `SKIP_QA_HARNESS` is set in `runtests.sh` (line 17) but if you run this single test directly, it will fail with: > tests/p_squid/squid_test.sh: line 9: [: : integer expression expected Fixed by setting `SKIP_QA_HARNESS` to 1 if it is unset. --- tests/p_squid/squid_test.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/p_squid/squid_test.sh b/tests/p_squid/squid_test.sh index ba81826..e4e4b4c 100755 --- a/tests/p_squid/squid_test.sh +++ b/tests/p_squid/squid_test.sh @@ -3,9 +3,14 @@ t_Log "Running $0 - Squid test." -if [ $SKIP_QA_HARNESS -eq 1 ]; then - URL="http://mirror.centos.org/" - CHECK_FOR="timestamp" +if [ -z "$SKIP_QA_HARNESS" ];then + SKIP_QA_HARNESS=1 +fi + +if [ "$SKIP_QA_HARNESS" -eq 1 ]; then + URL="http://www.centos.org/" + #CHECK_FOR="timestamp" # Before 2024-12-13: https://web.archive.org/web/20241212132650/https://www.centos.org/ - RDA - 250109 + CHECK_FOR="CentOS Project" # After 2024-12-13 : https://web.archive.org/web/20241213163833/https://www.centos.org/ - RDA - 250109 else URL="http://repo.centos.qa/qa/" CHECK_FOR="ks_cfg"