Skip to content

Commit

Permalink
Merge pull request #3652 from PaulYuuu/ks-required-pkgs
Browse files Browse the repository at this point in the history
ks: Support install specific packages in the "%packages" step
  • Loading branch information
YongxueHong authored May 10, 2023
2 parents c0f4e1c + 4ee51fc commit 2859166
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
15 changes: 11 additions & 4 deletions virttest/shared/unattended/RHEL-8-devel.ks
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dmidecode
alsa-utils
sg3_utils
-gnome-initial-setup
KVM_TEST_PACKAGES_PKGS
%end

%post
Expand Down Expand Up @@ -108,22 +109,28 @@ EOF
cat >> '/home/test/.bashrc' << EOF
alias shutdown='sudo shutdown'
EOF
# Install and lock packages specified via 'kickstart_instlock_pkgs' parameter
install_and_lock()
# Install packages specified via 'kickstart_post_pkgs' parameter
install_pkgs()
{
for PKG in KVM_TEST_PKGS; do
for PKG in KVM_TEST_POST_PKGS; do
ECHO "dnf install $PKG -y --nogpgcheck"
dnf install $PKG -y --nogpgcheck
if [ $? -ne 0 ]; then
ECHO "$PKG installation failed."
fi
}
# Lock packages specified via 'kickstart_lock_pkgs' parameter
lock_pkgs()
{
for PKG in KVM_TEST_LOCK_PKGS; do
ECHO "dnf versionlock add $PKG"
dnf versionlock add $PKG
if [ $? -ne 0 ]; then
ECHO "$PKG version lock failed."
fi
done
}
install_and_lock
install_pkgs
lock_pkgs
ECHO 'Post set up finished'
%end
28 changes: 23 additions & 5 deletions virttest/tests/unattended_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,30 @@ def answer_kickstart(self, answer_path):
content = "\n".join(lines)
contents = re.sub(dummy_repos_re, content, contents)

dummy_pkgs_re = r'\bKVM_TEST_PKGS\b'
if re.search(dummy_pkgs_re, contents):
# Extra packages to be installed and locked
# NOTE: This is an experimental feature to install extra packages
# during %packages step, even it supports kickstart syntax rules, we
# should only use it for add packages.
dummy_packages_pkgs_re = r'\bKVM_TEST_PACKAGES_PKGS\b'
if re.search(dummy_packages_pkgs_re, contents):
# Extra packages to be installed at "%packages" step
# Use space as a separator for multiple pkgs
pkgs = self.params.get("kickstart_instlock_pkgs", "")
contents = re.sub(dummy_pkgs_re, pkgs, contents)
pkgs = self.params.get("kickstart_packages_pkgs", "").split()
content = "\n".join(pkgs)
contents = re.sub(dummy_packages_pkgs_re, content, contents)

dummy_post_pkgs_re = r'\bKVM_TEST_POST_PKGS\b'
if re.search(dummy_post_pkgs_re, contents):
# Extra packages to be installed at "%post" step
# Use space as a separator for multiple pkgs
pkgs = self.params.get("kickstart_post_pkgs", "")
contents = re.sub(dummy_post_pkgs_re, pkgs, contents)

dummy_lock_pkgs_re = r'\bKVM_TEST_LOCK_PKGS\b'
if re.search(dummy_lock_pkgs_re, contents):
# Packages to be locked
# Use space as a separator for multiple pkgs
pkgs = self.params.get("kickstart_lock_pkgs", "")
contents = re.sub(dummy_lock_pkgs_re, pkgs, contents)

dummy_logging_re = r'\bKVM_TEST_LOGGING\b'
if re.search(dummy_logging_re, contents):
Expand Down

0 comments on commit 2859166

Please sign in to comment.