Skip to content

Commit

Permalink
Fix the enabled repository check after the conversion
Browse files Browse the repository at this point in the history
We found several problems with the enabled repository check.
This PR should fix those plus some minor code improvement changes.
Reference ticket: https://issues.redhat.com/browse/RHELC-1515
  • Loading branch information
kokesak committed Apr 24, 2024
1 parent 21a763e commit 9d9e03b
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 136 deletions.
4 changes: 2 additions & 2 deletions plans/tier0.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ description+: |

/basic_conversion_methods:

/rhsm_non_eus_conversion:
/rhsm_eus_conversion:
enabled: false
adjust+:
- enabled: true
when: >
distro == alma-8.8, rocky-8.8
discover+:
test+<:
- conversion-method/rhsm_non_eus_account_conversion
- conversion-method/rhsm_eus_account_conversion

/custom_repositories_conversion:
environment+:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,44 @@

import pytest


def _check_enabled_repos_rhel8(enabled_repos):
"""Helper function to assert RHEL repositories."""
baseos_repo = "rhel-8-for-x86_64-baseos-rpms"
appstream_repo = "rhel-8-for-x86_64-appstream-rpms"

assert baseos_repo in enabled_repos
assert appstream_repo in enabled_repos
from conftest import SystemInformationRelease


def _check_eus_enabled_repos_rhel8(enabled_repos):
"""Helper function to assert EUS repositories."""
baseos_repo = "rhel-8-for-x86_64-baseos-eus-rpms"
appstream_repo = "rhel-8-for-x86_64-appstream-eus-rpms"
def _check_enabled_repos_rhel8(enabled_repos: str = None, eus: bool = False):
"""Helper function to assert RHEL repositories."""
baseos_repo = None
appstream_repo = None
if eus:
baseos_repo = "rhel-8-for-x86_64-baseos-rpms"
appstream_repo = "rhel-8-for-x86_64-appstream-rpms"
else:
baseos_repo = "rhel-8-for-x86_64-baseos-eus-rpms"
appstream_repo = "rhel-8-for-x86_64-appstream-eus-rpms"

assert baseos_repo in enabled_repos
assert appstream_repo in enabled_repos


@pytest.mark.test_enabled_repositories
def test_enabled_repositories(shell, system_release):
def test_enabled_repositories(shell):
"""
Verify that the correct repositories (including EUS if applies) are enabled after the conversion.
"""

enabled_repos = shell("yum repolist").output

try:
# Using system_release fixture here, to read live data from /etc/os-release or /etc/system-release.
# Usage of hardcoded environment variable SYSTEM_RELEASE_ENV is not feasible.
if re.match(r"redhat-8\.8", system_release):
enabled_repos = shell("yum repolist").output
system_release = SystemInformationRelease()
assert "redhat" in system_release.distribution

if system_release.version.major == 7 and system_release.version.minor == 9:
assert "rhel-7-server-rpms/7Server/x86_64" in enabled_repos
elif system_release.version.major == 8:
# Handle the special test case scenario where we do not use the
# premium account with EUS repositories
if os.path.exists("/non_eus_repos_used"):
_check_enabled_repos_rhel8(enabled_repos)
if os.path.exists("/eus_repos_used"):
_check_enabled_repos_rhel8(enabled_repos, eus=True)
else:
_check_eus_enabled_repos_rhel8(enabled_repos)
elif "redhat-8.5" in system_release:
_check_enabled_repos_rhel8(enabled_repos)
elif "redhat-7.9" in system_release:
assert "rhel-7-server-rpms/7Server/x86_64" in enabled_repos
_check_enabled_repos_rhel8(enabled_repos)
finally:
# We need to unregister the system after the conversion
shell("subscription-manager unregister")
29 changes: 28 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,35 @@ def c2r_config(os_release):
return ConfigUtils(config_path)


class SystemInformationRelease:
"""
Helper class.
Assign a namedtuple with major and minor elements, both of an int type.
Assign a distribution (e.g. centos, oracle, rocky, alma)
Assign a system release.
Examples:
Oracle Linux Server release 7.8
CentOS Linux release 7.6.1810 (Core)
CentOS Linux release 8.1.1911 (Core)
"""

with open("/etc/system-release", "r") as file:
system_release_content = file.read()
match_version = re.search(r".+?(\d+)\.(\d+)\D?", system_release_content)
if not match_version:
print("not match")
version = namedtuple("Version", ["major", "minor"])(int(match_version.group(1)), int(match_version.group(2)))
distribution = system_release_content.split()[0].lower()
if distribution == "ol":
distribution = "oracle"
elif distribution == "red":
distribution = "redhat"
system_release = "{}-{}.{}".format(distribution, version.major, version.minor)


@pytest.fixture
def system_release(shell):
def system_release():
"""
This fixture returns a string of ID and VERSION_ID from /etc/os-release.
If /etc/os-release is not available, /etc/system-release is read instead.
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/tier0/destructive/conversion-method/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ order: 49
- rhsm-conversion
test: pytest -m test_rhsm_conversion

/rhsm_non_eus_account_conversion:
/rhsm_eus_account_conversion:
summary: |
RHSM non-EUS conversion method
RHSM EUS conversion method
description: |
Conversion of EUS system using an RHSM account without available EUS repositories.
Conversion of EUS system using an RHSM account with available EUS repositories.
Verify, that the conversion finishes and suitable repositories are enabled after the conversion.
tag+:
- rhsm-non-eus-account-conversion
test: pytest -m test_rhsm_non_eus_account_conversion
- rhsm-eus-account-conversion
test: pytest -m test_rhsm_eus_account_conversion

/satellite_conversion:
summary: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
import re

from collections import namedtuple

import pytest


def get_system_version(system_release_content=None):
"""Return a namedtuple with major and minor elements, both of an int type.
Examples:
Oracle Linux Server release 7.8
CentOS Linux release 7.6.1810 (Core)
CentOS Linux release 8.1.1911 (Core)
"""
match = re.search(r".+?(\d+)\.(\d+)\D?", system_release_content)
if not match:
return "not match"
version = namedtuple("Version", ["major", "minor"])(int(match.group(1)), int(match.group(2)))

return version
from conftest import SystemInformationRelease


@pytest.mark.test_custom_repos_conversion
Expand All @@ -31,8 +14,7 @@ def test_run_conversion_using_custom_repos(shell, convert2rhel):
"""

with open("/etc/system-release", "r") as file:
system_release = file.read()
system_version = get_system_version(system_release_content=system_release)
system_version = SystemInformationRelease.version
enable_repo_opt = "--enablerepo rhel-7-server-rpms --enablerepo rhel-7-server-optional-rpms --enablerepo rhel-7-server-extras-rpms"

if system_version.major == 8:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest

from conftest import TEST_VARS


@pytest.mark.test_rhsm_eus_account_conversion
def test_rhsm_eus_account(convert2rhel, shell):
"""
Verify that Convert2RHEL is working properly when EUS repositories are used during the conversion.
Only on EUS versions (8.6, 8.8, ...) it is possible to do EUS conversion.
Verify that the correct repositories are enabled after the conversion.
"""

# Mark the system so the check for the enabled repos after the conversion handles this special case
shell("touch /eus_repos_used")

with convert2rhel(
"-y --serverurl {} --username {} --password {} --debug --eus".format(
TEST_VARS["RHSM_SERVER_URL"],
TEST_VARS["RHSM_USERNAME"],
TEST_VARS["RHSM_PASSWORD"],
)
) as c2r:
# c2r.expect_exact("Error: 'rhel-8-for-x86_64-baseos-eus-rpms' does not match a valid repository ID.")
# c2r.expect_exact("Error: 'rhel-8-for-x86_64-appstream-eus-rpms' does not match a valid repository ID.")
# c2r.expect_exact("The RHEL EUS repositories are not possible to enable.")
c2r.expect("Conversion successful!")
assert c2r.exitstatus == 0

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import re

from collections import namedtuple

from conftest import SYSTEM_RELEASE_ENV


def get_system_version(system_release_content=None):
"""
Return a namedtuple with major and minor elements, both of an int type.
Examples:
Oracle Linux Server release 7.8
CentOS Linux release 7.6.1810 (Core)
CentOS Linux release 8.1.1911 (Core)
"""
match = re.search(r".+?(\d+)\.(\d+)\D?", system_release_content)
if not match:
return "not match"
version = namedtuple("Version", ["major", "minor"])(int(match.group(1)), int(match.group(2)))

return version
from conftest import SYSTEM_RELEASE_ENV, SystemInformationRelease


def test_install_dependency_packages(shell):
Expand All @@ -30,8 +9,6 @@ def test_install_dependency_packages(shell):
"""

with open("/etc/system-release", "r") as file:
system_rls = file.read()
system_version = get_system_version(system_release_content=system_rls)
dependency_pkgs = [
"abrt-retrace-client", # OAMG-4447
"libreport-cli", # OAMG-4447
Expand All @@ -43,7 +20,7 @@ def test_install_dependency_packages(shell):
"gcc-c++", # OAMG-6136
"python-requests", # OAMG-4936
]
if system_version.major == 8:
if SystemInformationRelease.version.major == 8:
if "oracle-8" in SYSTEM_RELEASE_ENV:
dependency_pkgs = [
"iwl7260-firmware", # RHELC-567
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
import re

from collections import namedtuple

import pytest


# TODO(danmyway) move to conftest
class GetSystemInformation:
"""
Helper class.
Assign a namedtuple with major and minor elements, both of an int type.
Assign a distribution (e.g. centos, oracle, rocky, alma)
Assign a system release.
Examples:
Oracle Linux Server release 7.8
CentOS Linux release 7.6.1810 (Core)
CentOS Linux release 8.1.1911 (Core)
"""

with open("/etc/system-release", "r") as file:
system_release_content = file.read()
match_version = re.search(r".+?(\d+)\.(\d+)\D?", system_release_content)
if not match_version:
print("not match")
version = namedtuple("Version", ["major", "minor"])(int(match_version.group(1)), int(match_version.group(2)))
distribution = system_release_content.split()[0].lower()
system_release = "{}-{}.{}".format(distribution, version.major, version.minor)
from conftest import SystemInformationRelease


class AssignRepositoryVariables:
Expand All @@ -49,7 +23,7 @@ class AssignRepositoryVariables:

with open("/etc/system-release", "r") as file:
system_release = file.read()
system_version = GetSystemInformation.version
system_version = SystemInformationRelease.version

if system_version.major == 7:
repofile = repofile_epel7
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/tier0/non-destructive/eus/test_eus_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,24 @@ def test_eus_support(
)
c2r.expect("Repositories enabled through subscription-manager", timeout=120)
c2r.sendcontrol("c")


@pytest.mark.test_rhsm_eus_account_conversion
def test_rhsm_non_eus_account(convert2rhel):
"""
Verify that Convert2RHEL is working properly when EUS repositories are not available for conversions
to RHEL EUS minor versions (8.6, ...) and the --eus option is provided. The regular repositories
should be enabled.
"""

with convert2rhel(
"analyze -y --serverurl {} --username {} --password {} --debug --eus".format(
TEST_VARS["RHSM_SERVER_URL"],
TEST_VARS["RHSM_SINGLE_SUB_USERNAME"],
TEST_VARS["RHSM_SINGLE_SUB_PASSWORD"],
)
) as c2r:
c2r.expect_exact("Error: 'rhel-8-for-x86_64-baseos-eus-rpms' does not match a valid repository ID.")
c2r.expect_exact("Error: 'rhel-8-for-x86_64-appstream-eus-rpms' does not match a valid repository ID.")
c2r.expect_exact("The RHEL EUS repositories are not possible to enable.")
assert c2r.exitstatus == 0

0 comments on commit 9d9e03b

Please sign in to comment.