-
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 8850c2f
Showing
6 changed files
with
219 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,32 @@ | ||
# Test name: post_install_with_logging_test | ||
%ksappend repos/default.ks | ||
%ksappend common/common_no_payload.ks | ||
%ksappend payload/default_packages.ks | ||
|
||
# System configuration for automatic installation | ||
text | ||
|
||
# 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="ksscript" | ||
|
||
. ${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,27 @@ | ||
# Test name: pre_install_interpreter_and_error_test | ||
|
||
%ksappend repos/default.ks | ||
%ksappend common/common_no_payload.ks | ||
%ksappend payload/default_packages.ks | ||
|
||
# First pre-install script using Python interpreter | ||
%pre-install --interpreter=/usr/bin/python3 --log=/mnt/sysroot/root/preinstall_python.log | ||
print("SUCCESS") | ||
with open("/mnt/sysroot/root/preinstall_python.log", "a") as log_file: | ||
log_file.write("Pre-install script running with Python\n") | ||
%end | ||
|
||
# Second pre-install script with intentional error | ||
%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 |
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,48 @@ | ||
#!/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="ksscript" | ||
|
||
. ${KSTESTDIR}/functions.sh | ||
|
||
validate() { | ||
local disksdir=$1 | ||
local status=0 | ||
|
||
# Check for exactly two "SUCCESS" messages in the log file | ||
local success_count | ||
success_count=$(grep -c "SUCCESS" "${disksdir}/virt-install.log") | ||
|
||
if [[ $success_count -ne 2 ]]; then | ||
echo "*** ERROR: Expected 2 SUCCESS messages, but found ${success_count}." | ||
status=1 | ||
fi | ||
|
||
# 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 | ||
|
||
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,19 @@ | ||
#test name: pre_install_interpreter_test | ||
|
||
%ksappend repos/default.ks | ||
|
||
# Pre-install script using Bash interpreter | ||
%pre --interpreter=/bin/bash | ||
echo "SUCCESS from Bash" | ||
%end | ||
|
||
# Pre-install script using Python interpreter | ||
%pre --interpreter=/usr/bin/python3 | ||
print("SUCCESS from Python") | ||
%end | ||
|
||
# Pre script just for confirmation | ||
%pre | ||
echo "SUCCESS Pre" | ||
shutdown +1 | ||
%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,41 @@ | ||
#!/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="ksscript" | ||
|
||
. ${KSTESTDIR}/functions.sh | ||
|
||
validate() { | ||
local disksdir=$1 | ||
local status=0 | ||
|
||
# Check for exactly two "SUCCESS" messages in the log file | ||
local success_count | ||
success_count=$(grep -c "SUCCESS" "${disksdir}/virt-install.log") | ||
|
||
if [[ $success_count -ne 3 ]]; then | ||
echo "*** ERROR: Expected 2 SUCCESS messages, but found ${success_count}." | ||
status=1 | ||
fi | ||
|
||
return ${status} | ||
} |