Skip to content

Commit

Permalink
Include el9 in more tests, remove unnecessary code
Browse files Browse the repository at this point in the history
* include the EL9 in more tests
* remove the install-submgr ansible role as it was not used anymore
  anywhere
* don't use yum_conf_exclude to exclude the rhn-client-tools packages,
use a no obsolete flag in yum calls installing sub-man
* fix booting to RHCK on OL9 for real this time

Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway committed Jun 12, 2024
1 parent c155701 commit ee7c7db
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 195 deletions.
4 changes: 2 additions & 2 deletions plans/tier0.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ description+: |
/resolve_dependency:
adjust+:
- enabled: true
when: distro == centos, oracle
because: We do not have any tracked packages with Rocky and Alma for this test case
when: distro == centos, oracle and distro != oracle-9
because: We do not have any tracked packages for Alma, Rocky or Oracle Linux 9 for this test case
summary+: |
Handle dependency packages
description+: |
Expand Down
4 changes: 4 additions & 0 deletions plans/tier1.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ description+: |
- changed-grub-file/valid_changes_to_grub_file

/changed_grub_invalid:
adjust+:
- enabled: false
when: distro == alma-8-latest and boot_method == uefi or distro == alma-9
because: The changes to the grub file result in a unbootable system.
discover+:
test+<:
- changed-grub-file/invalid_changes_to_grub_file
Expand Down

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions tests/ansible_collections/roles/install-submgr/main.yml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
- name: Set default kernel to Red Hat compatible kernel
shell: "grubby --set-default /boot/vmlinuz-{{ kernel_ver.stdout }}"

# On OL9 the grubby call is not recognized for some reason
# Set the entry manually just as a safety measure
- name: Set the default kernel manually for OL9
shell: 'grub2-set-default "Oracle Linux Server ({{ kernel_ver.stdout }}) {{ ansible_distribution_version }}"'
# On OL9 the /etc/default/grub might be configured in a way, that it's not possible to boot
# into the RHCK (Red Hat Compatible Kernel), fix that here
- name: Set the /etc/grub/default
lineinfile:
path: /etc/default/grub
line: '{{ item }}'
insertafter: EOF
loop:
- 'GRUB_ENABLE_BLSCFG=true'
- 'GRUB_TERMINAL_OUTPUT="console"'
when: ansible_distribution == "OracleLinux" and ansible_distribution_major_version == "9"

- name: Run grub2-mkconfig
shell: grub2-mkconfig -o /boot/grub2/grub.cfg
80 changes: 36 additions & 44 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@

SAT_REG_COMMAND = {
"alma-8-latest": SAT_REG_FILE["ALMA8_SAT_REG"],
"alma-9-latest": SAT_REG_FILE["ALMA9_SAT_REG"],
"alma-8.8": SAT_REG_FILE["ALMA88_SAT_REG"],
"rocky-8-latest": SAT_REG_FILE["ROCKY8_SAT_REG"],
"rocky-8.8": SAT_REG_FILE["ROCKY88_SAT_REG"],
"rocky-9-latest": SAT_REG_FILE["ROCKY9_SAT_REG"],
"oracle-8-latest": SAT_REG_FILE["ORACLE8_SAT_REG"],
"oracle-9-latest": SAT_REG_FILE["ORACLE9_SAT_REG"],
"centos-8-latest": SAT_REG_FILE["CENTOS8_SAT_REG"],
"oracle-7": SAT_REG_FILE["ORACLE7_SAT_REG"],
"centos-7": SAT_REG_FILE["CENTOS7_SAT_REG"],
"stream-8-latest": SAT_REG_FILE["STREAM8_SAT_REG"],
"stream-9-latest": SAT_REG_FILE["STREAM9_SAT_REG"],
}


Expand Down Expand Up @@ -476,13 +481,13 @@ def _load_json_schema(path):


@pytest.fixture
def pre_registered(shell, request, yum_conf_exclude):
def pre_registered(shell, request):
"""
A fixture to install subscription manager and pre-register the system prior to the convert2rhel run.
For Oracle Linux we're using the _add_client_tools_repo_oracle to enable the client-tools repository
to install the subscription-manager package from.
We also exclude the rhn-client* packages for the same reason.
On Oracle Linux subscription-manger is obsolete and replaced by rhn-client* packages when installing subman.
We call the subman installation with the no obsolete flag to be able to install the package even on Oracle Linux
where the subscription-manger is obsolete and replaced by rhn-client* packages when installing subman.
By default, the RHSM_USERNAME and RHSM_PASSWORD is passed to the subman registration.
Can be parametrized by requesting a different KEY from the TEST_VARS file.
@pytest.mark.parametrize("pre_registered", [("DIFFERENT_USERNAME", "DIFFERENT_PASSWORD")], indirect=True)
Expand All @@ -497,13 +502,10 @@ def pre_registered(shell, request, yum_conf_exclude):
print(">>> Using parametrized username and password requested in the fixture.")

if "oracle" in SYSTEM_RELEASE_ENV:
# Remove the rhn-client-tools package to make way for subscription-manager installation
# given subman is obsoleted by the rhn-client-tools on Oracle
shell("yum remove -y rhn-client-tools")
# Add the client-tools repository for Oracle linux to install subscription-manager from
_add_client_tools_repo(shell)

assert shell("yum install -y subscription-manager").returncode == 0
assert shell("yum install --setopt=obsoletes=0 -y subscription-manager").returncode == 0
# The SSL certificate for accessing cdn.redhat.com is intentionally missing from
# the subscription-manager-rhsm-certificates package on CentOS Linux 7
shell(
Expand Down Expand Up @@ -733,38 +735,32 @@ def yum_conf_exclude(shell, backup_directory, request):
def test_function(yum_conf_exclude):
"""
# We need to do this only for Oracle Linux
# rhn* is one of the excluded packages in convert2rhel configs
# so if the package is present on the system, is excluded in yum.conf
# and convert2rhel tries to back it up by calling yumdownloader
# it fails to do so because the call conflicts with the exclude option
if "oracle" in SYSTEM_RELEASE_ENV:
exclude = ["rhn-client*"]
if hasattr(request, "param"):
exclude = request.param
print(">>> Using parametrized packages requested in the fixture.")
yum_config = "/etc/yum.conf"
backup_dir = os.path.join(backup_directory, "yumconf")
shell(f"mkdir -v {backup_dir}")
config_bak = os.path.join(backup_dir, os.path.basename(yum_config))
config = configparser.ConfigParser()
config.read(yum_config)

assert shell(f"cp -v {yum_config} {config_bak}").returncode == 0

pkgs_to_exclude = " ".join(exclude)
# If there is already an `exclude` section, append to the existing value
if config.has_option("main", "exclude"):
pre_existing_value = config.get("main", "exclude")
config.set("main", "exclude", f"{pre_existing_value} {pkgs_to_exclude}")
else:
config.set("main", "exclude", pkgs_to_exclude)
exclude = [""]
if hasattr(request, "param"):
exclude = request.param
print(">>> Using parametrized packages requested in the fixture.")
yum_config = "/etc/yum.conf"
backup_dir = os.path.join(backup_directory, "yumconf")
shell(f"mkdir -v {backup_dir}")
config_bak = os.path.join(backup_dir, os.path.basename(yum_config))
config = configparser.ConfigParser()
config.read(yum_config)

assert shell(f"cp -v {yum_config} {config_bak}").returncode == 0

pkgs_to_exclude = " ".join(exclude)
# If there is already an `exclude` section, append to the existing value
if config.has_option("main", "exclude"):
pre_existing_value = config.get("main", "exclude")
config.set("main", "exclude", f"{pre_existing_value} {pkgs_to_exclude}")
else:
config.set("main", "exclude", pkgs_to_exclude)

with open(yum_config, "w") as configfile:
config.write(configfile, space_around_delimiters=False)
with open(yum_config, "w") as configfile:
config.write(configfile, space_around_delimiters=False)

assert config.has_option("main", "exclude")
assert all(pkg in config.get("main", "exclude") for pkg in exclude)
assert config.has_option("main", "exclude")
assert all(pkg in config.get("main", "exclude") for pkg in exclude)

yield

Expand Down Expand Up @@ -809,7 +805,7 @@ def _remove_client_tools_repo(shell):


@pytest.fixture
def satellite_registration(shell, yum_conf_exclude, request):
def satellite_registration(shell, request):
"""
Fixture
Register the system to the Satellite server
Expand Down Expand Up @@ -879,7 +875,7 @@ def backup_directory(shell, request):


@pytest.fixture()
def install_and_set_up_subman_to_stagecdn(shell, yum_conf_exclude):
def install_and_set_up_subman_to_stagecdn(shell):
""" "
A fixture to install subscription-manager and set up to point to a testing environments.
rhsm.baseurl and server.hostname to be changed.
Expand All @@ -888,11 +884,7 @@ def install_and_set_up_subman_to_stagecdn(shell, yum_conf_exclude):
# Add the client tools repository to install the subscription-manager from
# This is mainly for Oracle Linux but does not hurt to do the same for CentOS as well
_add_client_tools_repo(shell)
# Since we're using the yum_conf_exclude fixture, which excludes rhn-client*
# by default, we need to remove the pacakge to prevent issues during the yum transaction
if SystemInformationRelease.distribution == "oracle":
shell("yum remove -y rhn-client*")
shell(f"yum install subscription-manager -y")
shell(f"yum install --setopt=obsoletes=0 subscription-manager -y")

# Point the server hostname to the staging environment,
# so we don't need to pass it to convert2rhel explicitly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ description+: |

/duplicate-pkgs:
link: https://issues.redhat.com/browse/RHELC-1070
enabled: false
adjust+:
- enabled: false
when: distro == centos-8, alma-8, rocky-8, oracle-8
- enabled: true
when: distro == centos-7, oracle-7
because: |
The bug is reproducible only on EL7 distros.
On EL8 the issue is handled by the DNF itself.
Expand Down
117 changes: 66 additions & 51 deletions tests/integration/tier0/non-destructive/kernel/test_custom_kernel.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,70 @@
import os
import re

import pexpect.exceptions
import pytest

from conftest import SYSTEM_RELEASE_ENV


ORIGINAL_KERNEL = os.popen("rpm -q --last kernel | head -1 | cut -d ' ' -f1").read()

DISTRO_KERNEL_MAPPING = {
"centos-7": {
"original_kernel": f"{ORIGINAL_KERNEL}",
"custom_kernel": "https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/kernel-3.10.0-1160.76.1.0.1.el7.x86_64.rpm",
"grub_substring": "CentOS Linux (3.10.0-1160.76.1.0.1.el7.x86_64) 7 (Core)",
},
# We hardcode original kernel for CentOS 8.5 as it won't receive any updates anymore
"centos-8-latest": {
"original_kernel": "kernel-core-4.18.0-348.7.1.el8_5.x86_64",
"custom_kernel": "https://yum.oracle.com/repo/OracleLinux/OL8/5/baseos/base/x86_64/getPackage/kernel-core-4.18.0-348.el8.x86_64.rpm",
"grub_substring": "Oracle Linux Server (4.18.0-348.el8.x86_64) 8.5",
},
"oracle-7": {
"original_kernel": f"{ORIGINAL_KERNEL}",
"custom_kernel": "http://mirror.centos.org/centos/7/os/x86_64/Packages/kernel-3.10.0-1160.el7.x86_64.rpm",
"grub_substring": "Oracle Linux Server 7.9, with Linux 3.10.0-1160.el7.x86_64",
},
# Install CentOS 8.5 kernel
"oracle-8-latest": {
"original_kernel": f"{ORIGINAL_KERNEL}",
"custom_kernel": "https://vault.centos.org/centos/8.5.2111/BaseOS/x86_64/os/Packages/kernel-core-4.18.0-348.7.1.el8_5.x86_64.rpm",
"grub_substring": "CentOS Linux (4.18.0-348.7.1.el8_5.x86_64) 8",
},
"alma-8": {
"original_kernel": f"{ORIGINAL_KERNEL}",
"custom_kernel": "https://yum.oracle.com/repo/OracleLinux/OL8/5/baseos/base/x86_64/getPackage/kernel-core-4.18.0-348.el8.x86_64.rpm",
"grub_substring": "Oracle Linux Server (4.18.0-348.el8.x86_64) 8.5",
},
"rocky-8": {
"original_kernel": f"{ORIGINAL_KERNEL}",
"custom_kernel": "https://yum.oracle.com/repo/OracleLinux/OL8/5/baseos/base/x86_64/getPackage/kernel-core-4.18.0-348.el8.x86_64.rpm",
"grub_substring": "Oracle Linux Server (4.18.0-348.el8.x86_64) 8.5",
},
}

if "alma-8" in SYSTEM_RELEASE_ENV:
distro = "alma-8"
elif "rocky" in SYSTEM_RELEASE_ENV:
distro = "rocky-8"
else:
distro = SYSTEM_RELEASE_ENV

_, CUSTOM_KERNEL, GRUB_SUBSTRING = DISTRO_KERNEL_MAPPING[distro].values()
from conftest import SYSTEM_RELEASE_ENV, SystemInformationRelease


def _cross_vendor_kernel():
"""
Helper function to assign a cross vendor kernel.
Example:
Running on CentOS 7, we install the Oracle Linux 7 signed kernel.
distro == centos-7
install_what = oracle-7-kernel
"""

# This mapping includes cross vendor kernels and their respective grub substrings to set for boot
INSTALL_WHAT_KERNEL_MAPPING = {
"oracle-7-kernel": {
"custom_kernel": "https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/kernel-3.10.0-1160.76.1.0.1.el7.x86_64.rpm",
"grub_substring": "CentOS Linux (3.10.0-1160.76.1.0.1.el7.x86_64) 7 (Core)",
},
"centos-7-kernel": {
"custom_kernel": "http://mirror.centos.org/centos/7/os/x86_64/Packages/kernel-3.10.0-1160.el7.x86_64.rpm",
"grub_substring": "Oracle Linux Server 7.9, with Linux 3.10.0-1160.el7.x86_64",
},
"oracle-8-kernel": {
"custom_kernel": "https://yum.oracle.com/repo/OracleLinux/OL8/5/baseos/base/x86_64/getPackage/kernel-core-4.18.0-348.el8.x86_64.rpm",
"grub_substring": "Oracle Linux Server (4.18.0-348.el8.x86_64) 8.5",
},
"centos-8-kernel": {
"custom_kernel": "https://vault.centos.org/centos/8.5.2111/BaseOS/x86_64/os/Packages/kernel-core-4.18.0-348.7.1.el8_5.x86_64.rpm",
"grub_substring": "CentOS Linux (4.18.0-348.7.1.el8_5.x86_64) 8",
},
"stream-9-kernel": {
"custom_kernel": "https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/kernel-5.14.0-457.el9.x86_64.rpm",
"grub_substring": "CentOS Stream (5.14.0-457.el9.x86_64.rpm) 9",
},
"alma-9-kernel": {
"custom_kernel": "https://repo.almalinux.org/almalinux/9.4/BaseOS/x86_64/os/Packages/kernel-5.14.0-427.20.1.el9_4.x86_64.rpm",
"grub_substring": "AlmaLinux (5.14.0-427.20.1.el9_4.x86_64) 9.4 (Seafoam Ocelot)",
},
}

distro = f"{SystemInformationRelease.distribution}-{SystemInformationRelease.version.major}"

install_what = ""
# Based on a current OS we decide which cross vendor kernel to install
# install_what variable indicates that
if distro == "oracle-7":
install_what = "centos-7-kernel"
elif distro == "centos-7":
install_what = "oracle-7-kernel"
elif re.match(r"^(alma|rocky|centos|stream)-8", distro):
install_what = "oracle-8-kernel"
elif distro == "oracle-8":
install_what = "centos-8-kernel"
elif re.match(r"^(alma|rocky|centos|oracle)-9", distro):
install_what = "stream-9-kernel"
elif distro == "stream-9":
install_what = "alma-9-kernel"

custom_kernel, grub_substring = INSTALL_WHAT_KERNEL_MAPPING[install_what].values()

return custom_kernel, grub_substring


@pytest.fixture(scope="function")
Expand All @@ -62,19 +76,20 @@ def custom_kernel(shell, hybrid_rocky_image):
Remove the current installed kernel and install the machine default kernel
after the test.
"""
custom_kernel, grub_substring = _cross_vendor_kernel()
if os.environ["TMT_REBOOT_COUNT"] == "0":

assert shell("yum install %s -y" % CUSTOM_KERNEL).returncode == 0
assert shell("yum install %s -y" % custom_kernel).returncode == 0

assert shell("grub2-set-default '%s'" % GRUB_SUBSTRING).returncode == 0
assert shell("grub2-set-default '%s'" % grub_substring).returncode == 0

shell("tmt-reboot -t 600")

yield

if os.environ["TMT_REBOOT_COUNT"] == "1":
# Remove the current installed kernel and install the machine default kernel.
custom_kernel_release = CUSTOM_KERNEL.rsplit("/", 1)[-1].replace(".rpm", "")
custom_kernel_release = custom_kernel.rsplit("/", 1)[-1].replace(".rpm", "")
assert shell("rpm -e %s" % custom_kernel_release).returncode == 0

original_kernel = os.popen("rpm -q --last kernel | head -1 | cut -d ' ' -f1").read()
Expand Down
Loading

0 comments on commit ee7c7db

Please sign in to comment.