-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b75de4b
commit 96bf92b
Showing
6 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#test name: onerror_script_test | ||
%ksappend repos/default.ks | ||
|
||
# Simulate error in pre-install to trigger onerror | ||
%pre --erroronfail | ||
shutdown +1 | ||
exit 1 | ||
%end | ||
|
||
# On-error script | ||
%onerror | ||
# Write 'SUCCESS' to /root/RESULT because onerror was triggered | ||
echo "SUCCESS" | ||
%end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2024 Red Hat, Inc. | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# the GNU General Public License v.2, or (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY expressed or implied, including the implied warranties of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. You should have received a copy of the | ||
# GNU General Public License along with this program; if not, write to the | ||
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the | ||
# source code or documentation are not subject to the GNU General Public | ||
# License and may only be used or replicated with the express permission of | ||
# Red Hat, Inc. | ||
# | ||
# Red Hat Author(s): Adam Kankovsky<[email protected]> | ||
|
||
# Ignore unused variable parsed out by tooling scripts as test tags metadata | ||
# shellcheck disable=SC2034 | ||
TESTTYPE="error-on-install" | ||
|
||
. ${KSTESTDIR}/functions.sh | ||
|
||
validate() { | ||
# The test is looking for two conditions: | ||
# 1. SUCCESS must be found in the logs to confirm that the pre-script executed until exit 1. | ||
# 2. Ensure that no code after exit 1 was executed by checking if the "ERROR" message was written. | ||
|
||
local disksdir=$1 | ||
local status=0 | ||
|
||
# Look for the "SUCCESS" message in the logs to confirm pre-script started correctly. | ||
cat "${disksdir}/virt-install.log" | grep -q "SUCCESS" | ||
if [[ $? != 0 ]]; then | ||
echo '*** The pre-install script did not write "SUCCESS" as expected.' | ||
status=1 | ||
fi | ||
|
||
# Return the final status | ||
return ${status} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Test name: post_install_with_logging_test | ||
%ksappend repos/default.ks | ||
|
||
# System configuration for automatic installation | ||
text | ||
bootloader --timeout=1 | ||
zerombr | ||
clearpart --all --initlabel | ||
autopart | ||
rootpw --plaintext testpasswords | ||
reboot | ||
|
||
# Post-install script (nochroot) | ||
%post --nochroot --log=/mnt/sysroot/root/post-nochroot.log | ||
# Log to the nochroot log file | ||
echo "Post-install (nochroot) script started" | ||
# Write 'SUCCESS' to the RESULT file | ||
echo "SUCCESS" > /mnt/sysroot/root/RESULT | ||
# Log completion | ||
echo "Post-install (nochroot) script finished" | ||
%end | ||
|
||
# Post-install script (chroot) | ||
%post --log=/root/post-chroot.log | ||
# Log to the chroot log file | ||
echo "Post-install (chroot) script started" | ||
# Check if the RESULT file contains 'SUCCESS' | ||
if grep -q "SUCCESS" /root/RESULT; then | ||
echo "SUCCESS found in /root/RESULT, everything is good!" | ||
else | ||
echo "ERROR: SUCCESS not found in /root/RESULT" > /root/RESULT | ||
echo "ERROR: SUCCESS not found in /root/RESULT" | ||
fi | ||
# Log completion | ||
echo "Post-install (chroot) script finished" | ||
%end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2024 Red Hat, Inc. | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# the GNU General Public License v.2, or (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY expressed or implied, including the implied warranties of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. You should have received a copy of the | ||
# GNU General Public License along with this program; if not, write to the | ||
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the | ||
# source code or documentation are not subject to the GNU General Public | ||
# License and may only be used or replicated with the express permission of | ||
# Red Hat, Inc. | ||
# | ||
# Red Hat Author(s): Adam Kankovsky<[email protected]> | ||
|
||
# Ignore unused variable parsed out by tooling scripts as test tags metadata | ||
# shellcheck disable=SC2034 | ||
TESTTYPE="post-install" | ||
|
||
. ${KSTESTDIR}/functions.sh | ||
|
||
validate() { | ||
local disksdir=$1 | ||
local status=0 | ||
|
||
# Check if the nochroot log file exists and contains expected output | ||
if [[ ! -f "${disksdir}/root/post-nochroot.log" ]]; then | ||
echo "*** ERROR: nochroot log file does not exist" | ||
status=1 | ||
elif ! grep -q "Post-install (nochroot) script finished" "${disksdir}/root/post-nochroot.log"; then | ||
echo "*** ERROR: nochroot log does not contain expected 'finished' message" | ||
status=1 | ||
fi | ||
|
||
# Check if the chroot log file exists and contains expected output | ||
if [[ ! -f "${disksdir}/root/post-chroot.log" ]]; then | ||
echo "*** ERROR: chroot log file does not exist" | ||
status=1 | ||
elif ! grep -q "Post-install (chroot) script finished" "${disksdir}/root/post-chroot.log"; then | ||
echo "*** ERROR: chroot log does not contain expected 'finished' message" | ||
status=1 | ||
fi | ||
|
||
validate_RESULT $1 | ||
return $? || status | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#test name: pre_erroronfail_test | ||
|
||
%ksappend repos/default.ks | ||
|
||
# Pre-install script with intentional error and --erroronfail | ||
%pre --erroronfail | ||
echo "SUCCESS" | ||
|
||
echo "Pre-install script started" | ||
|
||
shutdown +1 | ||
|
||
# raise error | ||
exit 1 | ||
|
||
# Write error because this code is unreachable | ||
echo "ERROR: Pre-install script did not fail as expected." | ||
%end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2024 Red Hat, Inc. | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# the GNU General Public License v.2, or (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY expressed or implied, including the implied warranties of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. You should have received a copy of the | ||
# GNU General Public License along with this program; if not, write to the | ||
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the | ||
# source code or documentation are not subject to the GNU General Public | ||
# License and may only be used or replicated with the express permission of | ||
# Red Hat, Inc. | ||
# | ||
# Red Hat Author(s): Adam Kankovsky<[email protected]> | ||
|
||
# Ignore unused variable parsed out by tooling scripts as test tags metadata | ||
# shellcheck disable=SC2034 | ||
TESTTYPE="pre" | ||
|
||
. ${KSTESTDIR}/functions.sh | ||
|
||
validate() { | ||
# The test is looking for two conditions: | ||
# 1. SUCCESS must be found in the logs to confirm that the pre-script executed until exit 1. | ||
# 2. Ensure that no code after exit 1 was executed by checking if the "ERROR" message was written. | ||
|
||
local disksdir=$1 | ||
local status=0 | ||
|
||
# Look for the "SUCCESS" message in the logs to confirm pre-script started correctly. | ||
cat "${disksdir}/virt-install.log" | grep -q "SUCCESS" | ||
if [[ $? != 0 ]]; then | ||
echo '*** The pre-install script did not write "SUCCESS" as expected.' | ||
status=1 | ||
fi | ||
|
||
# Ensure that the "ERROR: Pre-install script did not fail as expected." message is NOT present. | ||
cat "${disksdir}/virt-install.log" | grep -q "ERROR: Pre-install script did not fail as expected." | ||
if [[ $? == 0 ]]; then | ||
echo '*** The test has failed because code after "exit 1" was executed.' | ||
status=1 | ||
fi | ||
|
||
# Return the final status | ||
return ${status} | ||
} | ||
|