Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RHELC-1687] - conftest.py refactor - custom repos #1370

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plans/tier1.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ adjust+:
adjust+:
- enabled: true
when: distro == centos-7, oracle-7
because: |
This scenario uses a lot of unsupported environment variables
thus making it unsupported. We are OK with running it only on EL7 system.
environment+:
# Bypass the kernel check, since the installed kernel is an older version
CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK: 1
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,11 @@ class SystemInformationRelease:
distribution = "oracle"
elif distribution == "red":
distribution = "redhat"

match_version = re.search(r".+?(\d+)\.?(\d+)?\D?", system_release_content)
if not match_version:
pytest.fail("Something is wrong with the /etc/system-release, cowardly refusing to continue.")

if is_stream:
distribution = "stream"
version = namedtuple("Version", ["major", "minor"])(int(match_version.group(1)), "latest")
Expand All @@ -416,6 +418,16 @@ class SystemInformationRelease:
)
system_release = "{}-{}.{}".format(distribution, version.major, version.minor)

# Check if the release is a EUS candidate
is_eus = False
if (
version.major in (8, 9)
and version.minor in (2, 4, 6, 8)
and distribution != "oracle"
and "latest" not in SYSTEM_RELEASE_ENV
):
is_eus = True


@pytest.fixture()
def log_file_data():
Expand Down Expand Up @@ -864,6 +876,30 @@ def get_full_kernel_title(shell, kernel=None):
return full_title


def get_custom_repos_names():
"""
Helper function.
Returns a list of correct repo names used on RHEL respecting major/eus system version.
"""
system_version = SystemInformationRelease.version

# Default RHEL-7 repositories
repos = ["rhel-7-server-rpms", "rhel-7-server-optional-rpms", "rhel-7-server-extras-rpms"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is rhel-7-server-supplementary-rpms repo needed to test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have never used this repository for testing. It can be added. Have you seen it specified somewhere in the documentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge this PR, we can enable another repository in the following PRs


if system_version.major >= 8:
if SystemInformationRelease.is_eus:
repos = [
f"rhel-{system_version.major}-for-x86_64-baseos-eus-rpms",
f"rhel-{system_version.major}-for-x86_64-appstream-eus-rpms",
]
else:
repos = [
f"rhel-{system_version.major}-for-x86_64-baseos-rpms",
f"rhel-{system_version.major}-for-x86_64-appstream-rpms",
]
return repos


#### Workaround fixtures ####
@pytest.fixture(autouse=True)
def workaround_missing_os_release_package(shell):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
from conftest import SYSTEM_RELEASE_ENV, SystemInformationRelease


def _assign_enable_repo_opt(shell):
"""
Helper function.
Assigns correct repositories to be enabled.
Builds the full string with --enabelrepo/--enable <repo>
:returns: enable_repo_opt_c2r, enable_repo_opt_yum
:rtype: tuple(str,str)
"""
system_version = SystemInformationRelease.version
system_distribution = SystemInformationRelease.distribution
repos = ("rhel-7-server-rpms", "rhel-7-server-optional-rpms", "rhel-7-server-extras-rpms")
enable_opt_c2r = "--enablerepo"
enable_opt_yum = "--enable"

if system_version.major in (8, 9):
# We want to go for EUS repositories only where really applicable
# 1/ minor version matches EUS eligible version
# 2/ the system distribution does snapshots of said versions
# 3/ the current version is not the latest one available (i.e. not in the EUS phase yet)
if (
system_version.minor in (2, 4, 6, 8)
and system_distribution != "oracle"
and "latest" not in SYSTEM_RELEASE_ENV
):
repos = (
f"rhel-{system_version.major}-for-x86_64-baseos-eus-rpms",
f"rhel-{system_version.major}-for-x86_64-appstream-eus-rpms",
)
# Mark the system so the check for the enabled repos after the conversion handles this special case
shell("touch /eus_repos_used")
else:
repos = (
f"rhel-{system_version.major}-for-x86_64-baseos-rpms",
f"rhel-{system_version.major}-for-x86_64-appstream-rpms",
)

enable_repo_opt_c2r = " ".join(f"{enable_opt_c2r} {repo}" for repo in repos)
enable_repo_opt_yum = " ".join(f"{enable_opt_yum} {repo}" for repo in repos)

return enable_repo_opt_c2r, enable_repo_opt_yum
from conftest import SystemInformationRelease, get_custom_repos_names


def test_system_conversion_using_custom_repositories(shell, convert2rhel):
Expand All @@ -51,11 +9,15 @@ def test_system_conversion_using_custom_repositories(shell, convert2rhel):
The repositories enabled in this scenario are
{rhel7: [server rpms, extras rpms, optional rpms], rhel8: [[eus-]?baseos], [eus-]?appstream}.
"""
# Join the --enablerepo <repo> on whitespace
enable_repo_opt_c2r = " ".join(f"--enablerepo {repo}" for repo in get_custom_repos_names())

enable_repo_opt_c2r, enable_repo_opt_yum = _assign_enable_repo_opt(shell)
if SystemInformationRelease.is_eus:
shell("touch /eus_repos_used")

with convert2rhel("-y --no-rhsm {} --debug".format(enable_repo_opt_c2r)) as c2r:
c2r.expect("Conversion successful!")
assert c2r.exitstatus == 0

enable_repo_opt_yum = " ".join(f"--enable {repo}" for repo in get_custom_repos_names())
shell("yum-config-manager {}".format(enable_repo_opt_yum))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from conftest import TEST_VARS
from conftest import TEST_VARS, SystemInformationRelease


def test_rhsm_with_eus_system_conversion(convert2rhel, shell):
Expand All @@ -19,7 +19,7 @@ def test_rhsm_with_eus_system_conversion(convert2rhel, shell):
)
) as c2r:
c2r.expect_exact("Enabling RHEL repositories:")
c2r.expect_exact("rhel-8-for-x86_64-baseos-eus-rpms")
c2r.expect_exact("rhel-8-for-x86_64-appstream-eus-rpms")
c2r.expect_exact(f"rhel-{SystemInformationRelease.version.major}-for-x86_64-baseos-eus-rpms")
c2r.expect_exact(f"rhel-{SystemInformationRelease.version.major}-for-x86_64-appstream-eus-rpms")
c2r.expect_exact("Conversion successful!")
assert c2r.exitstatus == 0
Original file line number Diff line number Diff line change
@@ -1,73 +1,42 @@
import pytest

from conftest import SYSTEM_RELEASE_ENV, SystemInformationRelease


def _assign_enable_repo_opt():
"""
Helper function.
Assign correct repofile content, name and enable_repo_opt to their respective major/eus system version.
"""
system_version = SystemInformationRelease.version
system_distribution = SystemInformationRelease.distribution
repos = ("rhel-7-server-rpms", "rhel-7-server-optional-rpms", "rhel-7-server-extras-rpms")
enable_opt = "--enablerepo"
repofile = f"rhel{system_version.major}"

if system_version.major in (8, 9):
# We want to go for EUS repositories only where really applicable
# 1/ minor version matches EUS eligible version
# 2/ the system distribution does snapshots of said versions
# 3/ the current version is not the latest one available (i.e. not in the EUS phase yet)
if system_version.minor in (4, 6, 8) and system_distribution != "oracle" and "latest" not in SYSTEM_RELEASE_ENV:
repos = (
f"rhel-{system_version.major}-for-x86_64-baseos-eus-rpms",
f"rhel-{system_version.major}-for-x86_64-appstream-eus-rpms",
)
# Append '-eus' to the name of the repofile
repofile += "-eus"
else:
repos = (
f"rhel-{system_version.major}-for-x86_64-baseos-rpms",
f"rhel-{system_version.major}-for-x86_64-appstream-rpms",
)

# Join the --enablerepo <repo> on whitespace
enable_repo_opt = " ".join(f"{enable_opt} {repo}" for repo in repos)

return repofile, enable_repo_opt


REPOFILE, ENABLE_REPO_OPT = _assign_enable_repo_opt()
from conftest import SystemInformationRelease, get_custom_repos_names


@pytest.fixture(scope="function")
def custom_repository(shell):
def set_custom_repository_files(shell):
"""
Fixture.
Set up custom repositories.
Tear down after the test.
"""
assert shell(f"cp files/{REPOFILE}.repo /etc/yum.repos.d/")
repo_file_name = f"rhel{SystemInformationRelease.version.major}"
if SystemInformationRelease.is_eus:
repo_file_name += "-eus"

assert shell(f"cp files/{repo_file_name}.repo /etc/yum.repos.d/").returncode == 0

yield

assert shell(f"rm -f /etc/yum.repos.d/{REPOFILE}.repo").returncode == 0
assert shell(f"rm -f /etc/yum.repos.d/{repo_file_name}.repo").returncode == 0


def test_custom_valid_repo_without_rhsm(shell, convert2rhel, custom_repository):
def test_custom_valid_repo_without_rhsm(convert2rhel, set_custom_repository_files):
"""
Verify that --enablerepo is not skipped when subscription-manager is disabled.
Verify that the passed repositories are accessible.
"""
with convert2rhel("-y --no-rhsm {} --debug".format(ENABLE_REPO_OPT), unregister=True) as c2r:
# Join the --enablerepo <repo> on whitespace
enable_repo_opt = " ".join(f"--enablerepo {repo}" for repo in get_custom_repos_names())

with convert2rhel(f"-y --no-rhsm {enable_repo_opt} --debug", unregister=True) as c2r:
c2r.expect("The repositories passed through the --enablerepo option are all accessible.")
c2r.sendcontrol("c")

assert c2r.exitstatus == 1


def test_custom_invalid_repo_without_rhsm(shell, convert2rhel, custom_repository):
def test_custom_invalid_repo_without_rhsm(shell, convert2rhel):
"""
Verify that --enablerepo is not skipped when subscription-manager is disabled.
Verify the conversion will raise CUSTOM_REPOSITORIES_ARE_VALID.UNABLE_TO_ACCESS_REPOSITORIES
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import re

from conftest import SYSTEM_RELEASE_ENV, TEST_VARS
from conftest import SYSTEM_RELEASE_ENV, TEST_VARS, SystemInformationRelease


def test_latest_kernel_check_skip(shell, convert2rhel, backup_directory):
Expand All @@ -25,7 +25,7 @@ def test_latest_kernel_check_skip(shell, convert2rhel, backup_directory):
os.rename(old_filepath, new_filepath)

# EUS version use hardcoded repos from c2r as well
if re.match(r"^(alma|rocky)-8\.8$", SYSTEM_RELEASE_ENV) or "centos-8-latest" in SYSTEM_RELEASE_ENV:
if SystemInformationRelease.is_eus:
assert shell(f"mkdir {eus_backup_dir}").returncode == 0
assert shell(f"mv /usr/share/convert2rhel/repos/* {eus_backup_dir}").returncode == 0

Expand Down
Loading