From e40b6aecf0e5dcdf32dd9729270c267660ef7a79 Mon Sep 17 00:00:00 2001 From: Adam Kankovsky Date: Thu, 7 Nov 2024 13:54:44 +0100 Subject: [PATCH 1/3] Revert "Merge pull request #1330 from adamkankovsky/ks-script-pre-install" This reverts commit 260e105adc93e1423bcab60de5a8e4c2b352f0c0, reversing changes made to a93ede6d1a70b17d3df63d68909e259f9512fe7c. --- script-pre-install.ks.in | 8 +++++++- script-pre-install.sh | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/script-pre-install.ks.in b/script-pre-install.ks.in index bda9afa8..3d822882 100644 --- a/script-pre-install.ks.in +++ b/script-pre-install.ks.in @@ -12,10 +12,16 @@ with open("/mnt/sysroot/root/preinstall_python.log", "a") as log_file: %end # Second pre-install script with intentional error -%pre-install --log=/mnt/sysroot/root/preinstall_error.log +%pre-install --erroronfail --log=/mnt/sysroot/root/preinstall_error.log echo "SUCCESS" echo "Logging from bash pre-install script" >> /mnt/sysroot/root/preinstall_error.log +shutdown +1 exit 1 %end +# Pre-install script that should be unreachable +%pre-install +echo "Unreachable code" >> /mnt/sysroot/root/preinstall_error.log +%end + text diff --git a/script-pre-install.sh b/script-pre-install.sh index 7f6ce32c..d71d13b6 100755 --- a/script-pre-install.sh +++ b/script-pre-install.sh @@ -37,9 +37,10 @@ validate() { status=1 fi - # Check for the specific error message in the virt-install.log - if ! grep -q "kickstart.script: Error code 1 running the kickstart script" "${disksdir}/virt-install.log"; then - echo '*** ERROR: Expected error message "kickstart.script: Error code 1 running the kickstart script" not found in virt-install.log.' + # Ensure that the "Unreachable code" message is NOT present. + grep -q "Unreachable code" "${disksdir}/virt-install.log" + if [[ $? == 0 ]]; then + echo '*** ERROR: The test failed because unreachable code was executed after "exit 1".' status=1 fi From 57823cafb79d50f665aa0912e6bd7591d0575d23 Mon Sep 17 00:00:00 2001 From: Adam Kankovsky Date: Thu, 7 Nov 2024 10:51:34 +0100 Subject: [PATCH 2/3] Add config file for custom ignored_simple_tests --- script-pre-install.sh | 7 +++++++ scripts/launcher/lib/log_monitor/log_handler.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/script-pre-install.sh b/script-pre-install.sh index d71d13b6..b1bd385b 100755 --- a/script-pre-install.sh +++ b/script-pre-install.sh @@ -24,6 +24,13 @@ TESTTYPE="ksscript" . ${KSTESTDIR}/functions.sh +# Define the path to the config file (must match the path in log_handler.py) +CONFIG_FILE_PATH="/tmp/ignored_simple_tests.conf" + +# Write the messages to ignore into the config file +# In this example, we're adding "Traceback" to be ignored +echo "Traceback" > "${CONFIG_FILE_PATH}" + validate() { local disksdir=$1 local status=0 diff --git a/scripts/launcher/lib/log_monitor/log_handler.py b/scripts/launcher/lib/log_monitor/log_handler.py index 1520bdc1..8d95fcc9 100644 --- a/scripts/launcher/lib/log_monitor/log_handler.py +++ b/scripts/launcher/lib/log_monitor/log_handler.py @@ -17,6 +17,8 @@ # # Red Hat Author(s): Vendula Poncova # +import os + from pylorax.monitor import LogRequestHandler @@ -42,6 +44,18 @@ class VirtualLogRequestHandler(LogRequestHandler): "Call Trace:" ] + # Path to the config file + CONFIG_FILE_PATH = '/tmp/ignored_simple_tests.conf' + + if os.path.isfile(CONFIG_FILE_PATH): + with open(CONFIG_FILE_PATH, 'r') as config_file: + extra_ignored_tests = [line.strip() for line in config_file if line.strip()] + # Extend the ignored_simple_tests list + ignored_simple_tests.extend(extra_ignored_tests) + + # Remove the config file after reading + os.remove(CONFIG_FILE_PATH) + # Specify error lines you want to add on top # of the default ones contained in Lorax simple_tests = LogRequestHandler.simple_tests + [ From c116df63e849f850d54213e680a6f0a0d4f33c2d Mon Sep 17 00:00:00 2001 From: Adam Kankovsky Date: Thu, 7 Nov 2024 14:21:11 +0100 Subject: [PATCH 3/3] Editing a test after Traceback testing has been made available --- script-pre-install.ks.in | 5 +++-- script-pre-install.sh | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/script-pre-install.ks.in b/script-pre-install.ks.in index 3d822882..b35ca609 100644 --- a/script-pre-install.ks.in +++ b/script-pre-install.ks.in @@ -15,13 +15,14 @@ with open("/mnt/sysroot/root/preinstall_python.log", "a") as log_file: %pre-install --erroronfail --log=/mnt/sysroot/root/preinstall_error.log echo "SUCCESS" echo "Logging from bash pre-install script" >> /mnt/sysroot/root/preinstall_error.log +# fixup this workaround after non-interactive mode is fixed shutdown +1 exit 1 %end # Pre-install script that should be unreachable %pre-install -echo "Unreachable code" >> /mnt/sysroot/root/preinstall_error.log +echo "Unreachable code" %end -text +text --non-interactive diff --git a/script-pre-install.sh b/script-pre-install.sh index b1bd385b..b447518e 100755 --- a/script-pre-install.sh +++ b/script-pre-install.sh @@ -39,11 +39,17 @@ validate() { local success_count success_count=$(grep -c "SUCCESS" "${disksdir}/virt-install.log") - if [[ $success_count -ne 2 ]]; then + if [[ $success_count -lt 2 ]]; then echo "*** ERROR: Expected 2 SUCCESS messages, but found ${success_count}." status=1 fi + # Check for the specific error message in the virt-install.log + if ! grep -q "Error code 1 running the kickstart script" "${disksdir}/virt-install.log"; then + echo '*** ERROR: Expected error message "Error code 1 running the kickstart script" not found in virt-install.log.' + status=1 + fi + # Ensure that the "Unreachable code" message is NOT present. grep -q "Unreachable code" "${disksdir}/virt-install.log" if [[ $? == 0 ]]; then