Skip to content

Commit

Permalink
[RHELC-1282] Override yum config exclude list (#1030)
Browse files Browse the repository at this point in the history
* Override yum config exclude list

Override the exclude list from the yum config file to avoid dependency
problems during the transaction process.

This method is temporary as it will only override the config file while
running the transaction, no modifications to the config file physically
will be done.

Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>

* Add basic integration test to validate override

* Update outdated docstring

---------

Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
Co-authored-by: Freya Gustavsson <eric@spytec.se>
  • Loading branch information
r0x0d and Venefilyn authored Mar 14, 2024
1 parent cdd621f commit 8fc6300
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 88 deletions.
3 changes: 3 additions & 0 deletions convert2rhel/pkgmanager/handlers/yum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def _set_up_base(self):
"""
pkgmanager.misc.setup_locale(override_time=True)
self._base = pkgmanager.YumBase()
# Empty out the exclude list to avoid dependency problems during the
# transaction validation.
self._base.conf.exclude = []
self._base.conf.yumvar["releasever"] = system_info.releasever

def _enable_repos(self):
Expand Down
84 changes: 84 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,87 @@ def remediation_out_of_date_packages(shell):

for package in problematic_packages:
shell(f"yum update -y {package}")


@pytest.fixture(scope="function")
def kernel_check_envar():
"""
Fixture.
Set CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK environment variable
to skip the kernel currency check.
"""
# Since we are moving all repos away, we need to bypass kernel check
os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1"

yield

# Remove the envar skipping the kernel check
del os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"]


@pytest.fixture(scope="function")
def kernel(shell):
"""
Install specific kernel version and configure
the system to boot to it. The kernel version is not the
latest one available in repositories.
"""

if os.environ["TMT_REBOOT_COUNT"] == "0":
# Set default kernel
if "centos-7" in SYSTEM_RELEASE_ENV:
assert shell("yum install kernel-3.10.0-1160.el7.x86_64 -y").returncode == 0
shell("grub2-set-default 'CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)'")
elif "oracle-7" in SYSTEM_RELEASE_ENV:
assert shell("yum install kernel-3.10.0-1160.el7.x86_64 -y").returncode == 0
shell("grub2-set-default 'Oracle Linux Server 7.9, with Linux 3.10.0-1160.el7.x86_64'")
elif "centos-8" in SYSTEM_RELEASE_ENV:
assert shell("yum install kernel-4.18.0-348.el8 -y").returncode == 0
shell("grub2-set-default 'CentOS Stream (4.18.0-348.el8.x86_64) 8'")
# Test is being run only for the latest released oracle-linux
elif "oracle-8" in SYSTEM_RELEASE_ENV:
assert shell("yum install kernel-4.18.0-80.el8.x86_64 -y").returncode == 0
shell("grub2-set-default 'Oracle Linux Server (4.18.0-80.el8.x86_64) 8.0'")
elif "alma-8" in SYSTEM_RELEASE_ENV:
mock_repo = "alma_old"
shell(f"cp files/{mock_repo}.repo /etc/yum.repos.d/")
assert shell(f"yum install kernel-4.18.0-372.13.1.el8_6.x86_64 -y --enablerepo {mock_repo}")
shell("grub2-set-default 'AlmaLinux (4.18.0-372.13.1.el8_6.x86_64) 8.6 (Sky Tiger)'")
elif "rocky-8" in SYSTEM_RELEASE_ENV:
mock_repo = "rocky_old"
shell(f"cp files/{mock_repo}.repo /etc/yum.repos.d/")
assert shell(f"yum install kernel-4.18.0-372.13.1.el8_6.x86_64 -y --enablerepo {mock_repo}")
shell("grub2-set-default 'Rocky Linux (4.18.0-372.13.1.el8_6.x86_64) 8.6 (Green Obsidian)'")

shell("tmt-reboot -t 600")

yield

if os.environ["TMT_REBOOT_COUNT"] == "1":
# We need to get the name of the latest kernel
# present in the repositories

# Install 'yum-utils' required by the repoquery command
shell("yum install yum-utils -y")

# Get the name of the latest kernel
latest_kernel = shell(
"repoquery --quiet --qf '%{BUILDTIME}\t%{VERSION}-%{RELEASE}' kernel 2>/dev/null | tail -n 1 | awk '{printf $NF}'"
).output

# Get the full name of the kernel
full_name = shell(
"grubby --info ALL | grep \"title=.*{}\" | tr -d '\"' | sed 's/title=//'".format(latest_kernel)
).output

# Set the latest kernel as the one we want to reboot to
shell("grub2-set-default '{}'".format(full_name.strip()))

# Remove the mocked repofile
if "alma-8" in SYSTEM_RELEASE_ENV:
shell(f"rm -f /etc/yum.repos.d/alma_old.repo")
elif "rocky-8" in SYSTEM_RELEASE_ENV:
shell(f"rm -f /etc/yum.repos.d/rocky_old.repo")

# Reboot after clean-up
shell("tmt-reboot -t 600")
Original file line number Diff line number Diff line change
Expand Up @@ -119,74 +119,6 @@ def test_latest_kernel_check_with_exclude_kernel_option(convert2rhel, yum_conf_e
assert c2r.exitstatus != 0


@pytest.fixture(scope="function")
def kernel(shell):
"""
Install specific kernel version and configure
the system to boot to it. The kernel version is not the
latest one available in repositories.
"""

if os.environ["TMT_REBOOT_COUNT"] == "0":
# Set default kernel
if "centos-7" in SYSTEM_RELEASE_ENV:
assert shell("yum install kernel-3.10.0-1160.el7.x86_64 -y").returncode == 0
shell("grub2-set-default 'CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)'")
elif "oracle-7" in SYSTEM_RELEASE_ENV:
assert shell("yum install kernel-3.10.0-1160.el7.x86_64 -y").returncode == 0
shell("grub2-set-default 'Oracle Linux Server 7.9, with Linux 3.10.0-1160.el7.x86_64'")
elif "centos-8" in SYSTEM_RELEASE_ENV:
assert shell("yum install kernel-4.18.0-348.el8 -y").returncode == 0
shell("grub2-set-default 'CentOS Stream (4.18.0-348.el8.x86_64) 8'")
# Test is being run only for the latest released oracle-linux
elif "oracle-8" in SYSTEM_RELEASE_ENV:
assert shell("yum install kernel-4.18.0-80.el8.x86_64 -y").returncode == 0
shell("grub2-set-default 'Oracle Linux Server (4.18.0-80.el8.x86_64) 8.0'")
elif "alma-8" in SYSTEM_RELEASE_ENV:
mock_repo = "alma_old"
shell(f"cp files/{mock_repo}.repo /etc/yum.repos.d/")
assert shell(f"yum install kernel-4.18.0-372.13.1.el8_6.x86_64 -y --enablerepo {mock_repo}")
shell("grub2-set-default 'AlmaLinux (4.18.0-372.13.1.el8_6.x86_64) 8.6 (Sky Tiger)'")
elif "rocky-8" in SYSTEM_RELEASE_ENV:
mock_repo = "rocky_old"
shell(f"cp files/{mock_repo}.repo /etc/yum.repos.d/")
assert shell(f"yum install kernel-4.18.0-372.13.1.el8_6.x86_64 -y --enablerepo {mock_repo}")
shell("grub2-set-default 'Rocky Linux (4.18.0-372.13.1.el8_6.x86_64) 8.6 (Green Obsidian)'")

shell("tmt-reboot -t 600")

yield

if os.environ["TMT_REBOOT_COUNT"] == "1":
# We need to get the name of the latest kernel
# present in the repositories

# Install 'yum-utils' required by the repoquery command
shell("yum install yum-utils -y")

# Get the name of the latest kernel
latest_kernel = shell(
"repoquery --quiet --qf '%{BUILDTIME}\t%{VERSION}-%{RELEASE}' kernel 2>/dev/null | tail -n 1 | awk '{printf $NF}'"
).output

# Get the full name of the kernel
full_name = shell(
"grubby --info ALL | grep \"title=.*{}\" | tr -d '\"' | sed 's/title=//'".format(latest_kernel)
).output

# Set the latest kernel as the one we want to reboot to
shell("grub2-set-default '{}'".format(full_name.strip()))

# Remove the mocked repofile
if "alma-8" in SYSTEM_RELEASE_ENV:
shell(f"rm -f /etc/yum.repos.d/alma_old.repo")
elif "rocky-8" in SYSTEM_RELEASE_ENV:
shell(f"rm -f /etc/yum.repos.d/rocky_old.repo")

# Reboot after clean-up
shell("tmt-reboot -t 600")


@pytest.mark.test_non_latest_kernel_error
def test_non_latest_kernel_error(kernel, shell, convert2rhel):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,30 @@ tag+:
- sanity
test: |
pytest -svv -m test_validation_packages_with_in_name_period

/override_exclude_list_in_yum_config:
enabled: false
adjust+:
- enabled: true
when: >
distro == oracle-7, centos-7
summary+: |
Override exclude in yum config to avoid dependency problems
description+: |
This test verifies that packages that are defined in the exclude
section in the /etc/yum.conf file are ignored during the analysis and
conversion.
The reason for us to ignore those packages, is that a user could
specify something like 'redhat-release-server' in the exclude list, and
that would cause dependency problems in the transaction.

1/ Add the exclude section to /etc/yum.conf with the
redhat-release-server package specified
2/ Set the environment variable to skip kernel check
3/ Boot into an older kernel
4/ Run the analysis and check that the transaction was successful.
tag+:
- validation-packages-with-in-name-period
- sanity
test: |
pytest -svv -m test_validation_packages_with_in_name_period
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@
if "8" in SYSTEM_RELEASE_ENV:
PKGMANAGER = "dnf"

YUM_CONF_PATH = "/etc/yum.conf"


@pytest.fixture()
def override_yum_conf(shell):
"""
Override yum conf to add exclude option and ignore redhat-release-server
package.
"""
content = "exclude=redhat-release-server"
with open(YUM_CONF_PATH, mode="a") as handler:
handler.write("exclude=redhat-release-server")

assert shell("grep -Fxq %s %s" % (content, YUM_CONF_PATH)).returncode == 0
yield

# Remove last line added
with open(YUM_CONF_PATH, mode="w") as handler:
lines = handler.readlines()
lines = lines[:-1]
handler.writelines(lines)

assert shell("grep -Fxq %s %s" % (content, YUM_CONF_PATH)).returncode == 1


@pytest.fixture()
def yum_cache(shell):
Expand Down Expand Up @@ -177,7 +201,7 @@ def test_validation_packages_with_in_name_period(shell, convert2rhel, packages_w
"""

with convert2rhel(
"--serverurl {} --username {} --password {} --pool {} --debug".format(
"analyze --serverurl {} --username {} --password {} --pool {} --debug".format(
env.str("RHSM_SERVER_URL"),
env.str("RHSM_USERNAME"),
env.str("RHSM_PASSWORD"),
Expand All @@ -197,8 +221,37 @@ def test_validation_packages_with_in_name_period(shell, convert2rhel, packages_w
c2r.sendline("y")

c2r.expect("VALIDATE_PACKAGE_MANAGER_TRANSACTION has succeeded")
# Exit at PONR
c2r.expect("Continue with the system conversion?")
c2r.sendline("n")

assert c2r.exitstatus != 0


@pytest.mark.test_override_exclude_list_in_yum_config
def test_override_exclude_list_in_yum_config(convert2rhel, kernel, kernel_check_envar, override_yum_conf):
"""
This test verifies that packages that are defined in the exclude
section in the /etc/yum.conf file are ignored during the analysis and
conversion.
The reason for us to ignore those packages, is that a user could
specify something like 'redhat-release-server' in the exclude list, and
that would cause dependency problems in the transaction.
1/ Add the exclude section to /etc/yum.conf with the
redhat-release-server package specified
2/ Set the environment variable to skip kernel check
3/ Boot into an older kernel
4/ Run the analysis and check that the transaction was successful.
"""
with convert2rhel(
"analyze --serverurl {} --username {} --password {} --pool {} --debug".format(
env.str("RHSM_SERVER_URL"),
env.str("RHSM_USERNAME"),
env.str("RHSM_PASSWORD"),
env.str("RHSM_POOL"),
)
) as c2r:
c2r.expect("Continue with the system conversion", timeout=300)
c2r.sendline("y")

c2r.expect("VALIDATE_PACKAGE_MANAGER_TRANSACTION has succeeded")

assert c2r.exitstatus != 0
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,6 @@ def katello_package(shell):
assert shell(f"rm -f {SATELLITE_PKG_DST}").returncode == 0


@pytest.fixture(scope="function")
def kernel_check_envar(shell):
"""
Fixture.
Set CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK environment variable
to skip the kernel currency check.
"""
# Since we are moving all repos away, we need to bypass kernel check
os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1"

yield

# Remove the envar skipping the kernel check
del os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"]


@pytest.mark.test_unsuccessful_satellite_registration
def test_backup_os_release_wrong_registration(shell, convert2rhel, custom_subman):
"""
Expand Down

0 comments on commit 8fc6300

Please sign in to comment.