leapp-repository/SOURCES/0061-Split-get_distro_id-into-variants-for-source-and-tar.patch
2025-12-01 09:14:24 +00:00

1095 lines
56 KiB
Diff

From b4cb48b52dc3bbef828cd97b4879963ac49cebe7 Mon Sep 17 00:00:00 2001
From: Matej Matuska <mmatuska@redhat.com>
Date: Tue, 23 Sep 2025 19:23:55 +0200
Subject: [PATCH 61/69] Split get_distro_id into variants for source and target
distros
The leapp.libraries.common.config.get_distro_id() function is deprecated
and replaced by the variants for source and target distros -
leapp.libraries.common.config.get_source_distro_id() and
leapp.libraries.common.config.get_target_distro_id().
Upstream deprecation documentation has been also updated.
Notable changes:
- removeobsoletegpgkeys - actor needs to handle RPM GPG key removal
differently during converting, for now it just returns early.
- RepoMapDataHandler is modified to accept source and target distro
independently and therefore perform mapping across different distros.
Jira: RHEL-110563
---
.../libraries-and-api/deprecations-list.md | 4 +-
.../libraries/checktargetrepos.py | 2 +-
.../libraries/distributionsignedrpmscanner.py | 6 +-
.../test_distributionsignedrpmscanner.py | 4 +
.../libraries/pes_events_scanner.py | 4 +-
.../libraries/peseventsscanner_repomap.py | 54 ++++++++-----
.../libraries/removeobsoleterpmgpgkeys.py | 8 +-
.../libraries/reportsettargetrelease.py | 6 +-
.../libraries/setuptargetrepos.py | 22 ++---
.../libraries/setuptargetrepos_repomap.py | 54 ++++++++-----
.../tests/test_repomapping.py | 27 ++++---
.../tests/test_setuptargetrepos.py | 81 ++++++++++---------
.../libraries/userspacegen.py | 20 +++--
.../tests/unit_test_targetuserspacecreator.py | 20 +++--
.../common/libraries/config/__init__.py | 33 +++++++-
.../system_upgrade/common/libraries/distro.py | 4 +-
repos/system_upgrade/common/libraries/gpg.py | 4 +-
repos/system_upgrade/common/libraries/rhsm.py | 6 +-
.../common/libraries/tests/test_gpg.py | 2 +-
.../common/libraries/tests/test_rhsm.py | 4 +-
20 files changed, 224 insertions(+), 141 deletions(-)
diff --git a/docs/source/libraries-and-api/deprecations-list.md b/docs/source/libraries-and-api/deprecations-list.md
index 7d6bef18..e620d70d 100644
--- a/docs/source/libraries-and-api/deprecations-list.md
+++ b/docs/source/libraries-and-api/deprecations-list.md
@@ -13,8 +13,8 @@ framework, see {ref}`deprecation:list of the deprecated functionality in leapp`.
Only the versions in which a deprecation has been made are listed.
## Next release <span style="font-size:0.5em; font-weight:normal">(till TODO date)</span>
-
-- Note: nothing new deprecated yet
+- Shared libraries
+ - **`leapp.libraries.common.config.get_distro_id()`** - The function has been replaced by variants for source and target distros - `leapp.libraries.common.config.get_source_distro_id()` and `leapp.libraries.common.config.get_target_distro_id()`.
## v0.23.0 <span style="font-size:0.5em; font-weight:normal">(till March 2026)</span>
diff --git a/repos/system_upgrade/common/actors/checktargetrepos/libraries/checktargetrepos.py b/repos/system_upgrade/common/actors/checktargetrepos/libraries/checktargetrepos.py
index ea21e1de..556b41a2 100644
--- a/repos/system_upgrade/common/actors/checktargetrepos/libraries/checktargetrepos.py
+++ b/repos/system_upgrade/common/actors/checktargetrepos/libraries/checktargetrepos.py
@@ -40,7 +40,7 @@ def process():
rhui_info = next(api.consume(RHUIInfo), None)
- if config.get_distro_id() != 'rhel' or (not rhsm.skip_rhsm() or rhui_info):
+ if config.get_target_distro_id() != 'rhel' or (not rhsm.skip_rhsm() or rhui_info):
# RHEL: getting RH repositories through RHSM or RHUI;
# resolved by seatbelts in other actors
# other: distro repos provided by the distro directly, seatbelts elsewhere
diff --git a/repos/system_upgrade/common/actors/distributionsignedrpmscanner/libraries/distributionsignedrpmscanner.py b/repos/system_upgrade/common/actors/distributionsignedrpmscanner/libraries/distributionsignedrpmscanner.py
index 18c859e2..a6ce16ac 100644
--- a/repos/system_upgrade/common/actors/distributionsignedrpmscanner/libraries/distributionsignedrpmscanner.py
+++ b/repos/system_upgrade/common/actors/distributionsignedrpmscanner/libraries/distributionsignedrpmscanner.py
@@ -1,5 +1,5 @@
from leapp.libraries.common import rhui
-from leapp.libraries.common.config import get_env
+from leapp.libraries.common.config import get_env, get_source_distro_id
from leapp.libraries.common.distro import get_distribution_data
from leapp.libraries.stdlib import api
from leapp.models import DistributionSignedRPM, InstalledRPM, InstalledUnsignedRPM, ThirdPartyRPM
@@ -32,8 +32,8 @@ def is_exceptional(pkg, allowlist):
@suppress_deprecation(InstalledUnsignedRPM)
def process():
- distribution = api.current_actor().configuration.os_release.release_id
- distro_keys = get_distribution_data(distribution).get('keys', [])
+ distro = get_source_distro_id()
+ distro_keys = get_distribution_data(distro).get('keys', [])
all_signed = get_env('LEAPP_DEVEL_RPMS_ALL_SIGNED', '0') == '1'
rhui_pkgs = rhui.get_all_known_rhui_pkgs_for_current_upg()
diff --git a/repos/system_upgrade/common/actors/distributionsignedrpmscanner/tests/test_distributionsignedrpmscanner.py b/repos/system_upgrade/common/actors/distributionsignedrpmscanner/tests/test_distributionsignedrpmscanner.py
index f55a2295..b0c616cb 100644
--- a/repos/system_upgrade/common/actors/distributionsignedrpmscanner/tests/test_distributionsignedrpmscanner.py
+++ b/repos/system_upgrade/common/actors/distributionsignedrpmscanner/tests/test_distributionsignedrpmscanner.py
@@ -4,6 +4,7 @@ from leapp.libraries.common import rpms
from leapp.libraries.common.config import mock_configs
from leapp.models import (
DistributionSignedRPM,
+ Distro,
fields,
InstalledRPM,
InstalledUnsignedRPM,
@@ -79,6 +80,7 @@ def test_actor_execution_with_signed_and_third_party_pkgs_centos(current_actor_c
version='7 (Core)',
version_id='7'
)
+ config.distro = Distro(source='centos', target='centos')
installed_rpm = [
RPM(name='sample01', version='0.1', release='1.sm01', epoch='1', packager=CENTOS_PACKAGER, arch='noarch',
@@ -121,6 +123,7 @@ def test_actor_execution_with_signed_unsigned_data_almalinux(current_actor_conte
version='8.10 (Cerulean Leopard)',
version_id='8.10'
)
+ config.distro = Distro(source='almalinux', target='almalinux')
installed_rpm = [
RPM(name='sample01', version='0.1', release='1.sm01', epoch='1', packager=ALMALINUX_PACKAGER, arch='noarch',
@@ -151,6 +154,7 @@ def test_actor_execution_with_unknown_distro(current_actor_context):
version='7 (Core)',
version_id='7'
)
+ config.distro = Distro(source='myos', target='myos')
current_actor_context.feed(InstalledRPM(items=[]))
current_actor_context.run(config_model=config)
diff --git a/repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_events_scanner.py b/repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_events_scanner.py
index e6741293..67e517d1 100644
--- a/repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_events_scanner.py
+++ b/repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_events_scanner.py
@@ -6,7 +6,7 @@ from leapp.exceptions import StopActorExecutionError
from leapp.libraries.actor import peseventsscanner_repomap
from leapp.libraries.actor.pes_event_parsing import Action, get_pes_events, Package
from leapp.libraries.common import rpms
-from leapp.libraries.common.config import version
+from leapp.libraries.common.config import get_target_distro_id, version
from leapp.libraries.stdlib import api
from leapp.libraries.stdlib.config import is_verbose
from leapp.models import (
@@ -400,7 +400,7 @@ def get_pesid_to_repoid_map(target_pesids):
repo_type='rpm',
channel='ga',
rhui='',
- distro=api.current_actor().configuration.os_release.release_id,
+ distro=get_target_distro_id(),
)
for pesid in target_pesids:
diff --git a/repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner_repomap.py b/repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner_repomap.py
index b3f35d99..abd35e0b 100644
--- a/repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner_repomap.py
+++ b/repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner_repomap.py
@@ -1,4 +1,4 @@
-from leapp.libraries.common.config import get_target_product_channel
+from leapp.libraries.common.config import get_source_distro_id, get_target_distro_id, get_target_product_channel
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version
from leapp.libraries.stdlib import api
@@ -23,7 +23,14 @@ class RepoMapDataHandler:
Provide the basic functionality to work with the repository data easily.
"""
- def __init__(self, repo_map, distro='', cloud_provider='', default_channels=None):
+ def __init__(
+ self,
+ repo_map,
+ source_distro='',
+ target_distro='',
+ cloud_provider='',
+ default_channels=None,
+ ):
"""
Initialize the object based on the given RepositoriesMapping msg.
@@ -32,8 +39,10 @@ class RepoMapDataHandler:
:param repo_map: A valid RepositoryMapping message.
:type repo_map: RepositoryMapping
- :param distro: Which distribution's mappings to use, default to current
- :type distro: str
+ :param source_distro: The distribution to map repos from, default to current
+ :type source_distro: str
+ :param target_distro: The distribution to map repos to, default to current
+ :type target_distro: str
:param default_channels: A list of default channels to use when a target repository
equivalent exactly matching a source repository was not found.
:type default_channels: List[str]
@@ -44,7 +53,9 @@ class RepoMapDataHandler:
# ideal for work, but there is not any significant impact..
self.repositories = repo_map.repositories
self.mapping = repo_map.mapping
- self.distro = distro or api.current_actor().configuration.os_release.release_id
+
+ self.source_distro = source_distro or get_source_distro_id()
+ self.target_distro = target_distro or get_target_distro_id()
# FIXME(pstodulk): what about default_channel -> fallback_channel
# hardcoded always as ga? instead of list of channels..
# it'd be possibly confusing naming now...
@@ -89,19 +100,19 @@ class RepoMapDataHandler:
"""
self.default_channels = default_channels
- def get_pesid_repo_entry(self, repoid, major_version):
+ def get_pesid_repo_entry(self, repoid, major_version, distro):
"""
- Retrieve the PESIDRepositoryEntry that matches the given repoid and OS major version.
+ Retrieve the PESIDRepositoryEntry that matches the given repoid, distro and OS major version
If multiple pesid repo entries with the same repoid were found, the entry with rhui matching the source
system's rhui info will be returned. If no entry with matching rhui exists, the CDN one is returned if any.
- Note that repositories are automatically filtered based on the specified OS release ID (self.distro).
-
- :param repoid: RepoID that should the PESIDRepositoryEntry match.
+ :param repoid: RepoID that the PESIDRepositoryEntry should match.
:type repoid: str
- :param major_version: RepoID that should the PESIDRepositoryEntry match.
+ :param major_version: Major version that the PESIDRepositoryEntry should match.
:type major_version: str
+ :param distro: Distro that the PESIDRepositoryEntry should match.
+ :type distro: str
:return: The PESIDRepositoryEntry matching the given repoid and major_version or None if no such
entry could be found.
:rtype: Optional[PESIDRepositoryEntry]
@@ -109,8 +120,8 @@ class RepoMapDataHandler:
matching_pesid_repos = []
for pesid_repo in self.repositories:
# FIXME(pstodulk): Why we do not check actually architecture here?
- # It seems obvious we should check it but the fixme comment below
- # suggests that it's expected - for not obvious reason.
+ # It seems obvious we should check it, but it's not clear why we
+ # don't and investigation might be required.
# For the investigation:
# # check repoids matching various architectures
# # check repoids without $arch in substring on how many architectures they are present
@@ -119,12 +130,13 @@ class RepoMapDataHandler:
if (
pesid_repo.repoid == repoid
and pesid_repo.major_version == major_version
- and pesid_repo.distro == self.distro
+ and pesid_repo.distro == distro
):
matching_pesid_repos.append(pesid_repo)
# FIXME: when a PESID is present for multiple architectures, there
- # multiple matching repos even though there should really be just one
+ # are multiple matching repos even though there should really be just
+ # one, the condition below fails even though it shouldn't
if len(matching_pesid_repos) == 1:
# Perform no heuristics if only a single pesid repository with matching repoid found
return matching_pesid_repos[0]
@@ -190,7 +202,7 @@ class RepoMapDataHandler:
the OS Major version same as the source OS.
:rtype: List[PESIDRepositoryEntry]
"""
- return self.get_pesid_repos(pesid, get_source_major_version(), self.distro)
+ return self.get_pesid_repos(pesid, get_source_major_version(), self.source_distro)
def get_target_pesid_repos(self, pesid):
"""
@@ -203,7 +215,7 @@ class RepoMapDataHandler:
the OS Major version same as the target OS.
:rtype: List[PESIDRepositoryEntry]
"""
- return self.get_pesid_repos(pesid, get_target_major_version(), self.distro)
+ return self.get_pesid_repos(pesid, get_target_major_version(), self.target_distro)
def _find_repository_target_equivalent(self, src_pesidrepo, target_pesid):
"""
@@ -223,7 +235,7 @@ class RepoMapDataHandler:
matches_rhui = candidate.rhui == src_pesidrepo.rhui
matches_repo_type = candidate.repo_type == 'rpm'
matches_arch = candidate.arch == api.current_actor().configuration.architecture
- matches_distro = candidate.distro == self.distro
+ matches_distro = candidate.distro == self.target_distro
if matches_rhui and matches_arch and matches_distro and matches_repo_type:
# user can specify in future the specific channel should be
@@ -295,7 +307,7 @@ class RepoMapDataHandler:
# {pesid: target_repo}
target_repos_best_candidates = {}
for src_repoid in src_repoids:
- src_pesidrepo = self.get_pesid_repo_entry(src_repoid, get_source_major_version())
+ src_pesidrepo = self.get_pesid_repo_entry(src_repoid, get_source_major_version(), self.source_distro)
if not src_pesidrepo:
# unmapped or custom repo -> skip this one
continue
@@ -340,7 +352,9 @@ def get_default_repository_channels(repomap, src_repoids):
default_pesid = DEFAULT_PESID[get_source_major_version()]
top_prio_pesid_repo = None
for repoid in src_repoids:
- pesid_repo = repomap.get_pesid_repo_entry(repoid, get_source_major_version())
+ pesid_repo = repomap.get_pesid_repo_entry(
+ repoid, get_source_major_version(), get_source_distro_id()
+ )
if not pesid_repo or pesid_repo.pesid != default_pesid:
continue
if not top_prio_pesid_repo or _get_channel_prio(pesid_repo) > _get_channel_prio(top_prio_pesid_repo):
diff --git a/repos/system_upgrade/common/actors/removeobsoletegpgkeys/libraries/removeobsoleterpmgpgkeys.py b/repos/system_upgrade/common/actors/removeobsoletegpgkeys/libraries/removeobsoleterpmgpgkeys.py
index 198c4368..df08e6fa 100644
--- a/repos/system_upgrade/common/actors/removeobsoletegpgkeys/libraries/removeobsoleterpmgpgkeys.py
+++ b/repos/system_upgrade/common/actors/removeobsoletegpgkeys/libraries/removeobsoleterpmgpgkeys.py
@@ -1,3 +1,4 @@
+from leapp.libraries.common.config import get_source_distro_id, get_target_distro_id
from leapp.libraries.common.config.version import get_target_major_version
from leapp.libraries.common.distro import get_distribution_data
from leapp.libraries.common.rpms import has_package
@@ -9,7 +10,7 @@ def _get_obsolete_keys():
"""
Return keys obsoleted in target and previous versions
"""
- distribution = api.current_actor().configuration.os_release.release_id
+ distribution = get_target_distro_id()
obsoleted_keys_map = get_distribution_data(distribution).get('obsoleted-keys', {})
keys = []
for version in range(7, int(get_target_major_version()) + 1):
@@ -35,6 +36,11 @@ def register_dnfworkaround(keys):
def process():
+ if get_source_distro_id() != get_target_distro_id():
+ # TODO adjust for conversions, in the current state it would not have
+ # any effect, just skip it
+ return
+
keys = _get_obsolete_keys()
if not keys:
return
diff --git a/repos/system_upgrade/common/actors/reportsettargetrelease/libraries/reportsettargetrelease.py b/repos/system_upgrade/common/actors/reportsettargetrelease/libraries/reportsettargetrelease.py
index 37f60179..56dc15f0 100644
--- a/repos/system_upgrade/common/actors/reportsettargetrelease/libraries/reportsettargetrelease.py
+++ b/repos/system_upgrade/common/actors/reportsettargetrelease/libraries/reportsettargetrelease.py
@@ -1,6 +1,5 @@
from leapp import reporting
-from leapp.libraries.common import rhsm
-from leapp.libraries.common.config import get_distro_id
+from leapp.libraries.common import config, rhsm
from leapp.libraries.stdlib import api
@@ -49,8 +48,9 @@ def _report_unhandled_release():
def process():
+ # TODO this might need a better handling during conversions
if rhsm.skip_rhsm():
- if get_distro_id() == 'rhel':
+ if config.get_source_distro_id() == config.get_target_distro_id() == 'rhel':
_report_unhandled_release()
else:
_report_set_release()
diff --git a/repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos.py b/repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos.py
index 9e5b1334..df17a217 100644
--- a/repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos.py
+++ b/repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos.py
@@ -1,6 +1,6 @@
from leapp.libraries.actor import setuptargetrepos_repomap
-from leapp.libraries.common.config import get_distro_id
-from leapp.libraries.common.config.version import get_source_major_version, get_source_version, get_target_version
+from leapp.libraries.common.config import get_source_distro_id, get_target_distro_id
+from leapp.libraries.common.config.version import get_source_major_version, get_source_version
from leapp.libraries.stdlib import api
from leapp.models import (
CustomTargetRepository,
@@ -76,8 +76,9 @@ def _get_used_repo_dict():
def _get_mapped_repoids(repomap, src_repoids):
mapped_repoids = set()
src_maj_ver = get_source_major_version()
+ src_distro = get_source_distro_id()
for repoid in src_repoids:
- if repomap.get_pesid_repo_entry(repoid, src_maj_ver):
+ if repomap.get_pesid_repo_entry(repoid, src_maj_ver, src_distro):
mapped_repoids.add(repoid)
return mapped_repoids
@@ -106,11 +107,10 @@ def process():
# installed packages that have mapping to prevent missing repositories that are disabled during the upgrade, but
# can be used to upgrade installed packages.
repoids_to_map = enabled_repoids.union(repoids_from_installed_packages_with_mapping)
- is_rhel = get_distro_id() == 'rhel'
# RHEL8.10 use a different repoid for client repository, but the repomapping mechanism cannot distinguish these
# as it does not use minor versions. Therefore, we have to hardcode these changes.
- if is_rhel and get_source_version() == '8.10':
+ if get_source_distro_id() == 'rhel' and get_source_version() == '8.10':
for rhel88_rhui_client_repoid, rhel810_rhui_client_repoid in RHUI_CLIENT_REPOIDS_RHEL88_TO_RHEL810.items():
if rhel810_rhui_client_repoid in repoids_to_map:
# Replace RHEL8.10 rhui client repoids with RHEL8.8 repoids,
@@ -157,18 +157,8 @@ def process():
continue
target_distro_repoids.add(repo)
- # On 8.10, some RHUI setups have different names than the one computed by repomapping.
- # Although such situation could be avoided (having another client repo when a single
- # repo can hold more than one RPM), we have to deal with it here. This is not a proper
- # solution.
- if get_target_version() == '8.10':
- for pre_810_repoid, post_810_repoid in RHUI_CLIENT_REPOIDS_RHEL88_TO_RHEL810.items():
- if pre_810_repoid in target_distro_repoids:
- target_distro_repoids.remove(pre_810_repoid)
- target_distro_repoids.add(post_810_repoid)
-
# create the final lists and sort them (for easier testing)
- if is_rhel:
+ if get_target_distro_id() == 'rhel':
rhel_repos = [RHELTargetRepository(repoid=repoid) for repoid in sorted(target_distro_repoids)]
else:
rhel_repos = []
diff --git a/repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos_repomap.py b/repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos_repomap.py
index 9613da9e..3286609d 100644
--- a/repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos_repomap.py
+++ b/repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos_repomap.py
@@ -1,4 +1,4 @@
-from leapp.libraries.common.config import get_distro_id, get_target_product_channel
+from leapp.libraries.common.config import get_source_distro_id, get_target_distro_id, get_target_product_channel
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version
from leapp.libraries.stdlib import api
@@ -23,7 +23,14 @@ class RepoMapDataHandler:
Provide the basic functionality to work with the repository data easily.
"""
- def __init__(self, repo_map, distro='', cloud_provider='', default_channels=None):
+ def __init__(
+ self,
+ repo_map,
+ source_distro="",
+ target_distro="",
+ cloud_provider="",
+ default_channels=None,
+ ):
"""
Initialize the object based on the given RepositoriesMapping msg.
@@ -32,8 +39,10 @@ class RepoMapDataHandler:
:param repo_map: A valid RepositoryMapping message.
:type repo_map: RepositoryMapping
- :param distro: Which distribution's mappings to use, default to current
- :type distro: str
+ :param source_distro: The distribution to map repos from, default to current
+ :type source_distro: str
+ :param target_distro: The distribution to map repos to, default to current target distro
+ :type target_distro: str
:param default_channels: A list of default channels to use when a target repository
equivalent exactly matching a source repository was not found.
:type default_channels: List[str]
@@ -44,7 +53,9 @@ class RepoMapDataHandler:
# ideal for work, but there is not any significant impact..
self.repositories = repo_map.repositories
self.mapping = repo_map.mapping
- self.distro = distro or get_distro_id()
+
+ self.source_distro = source_distro or get_source_distro_id()
+ self.target_distro = target_distro or get_target_distro_id()
# FIXME(pstodulk): what about default_channel -> fallback_channel
# hardcoded always as ga? instead of list of channels..
# it'd be possibly confusing naming now...
@@ -89,19 +100,19 @@ class RepoMapDataHandler:
"""
self.default_channels = default_channels
- def get_pesid_repo_entry(self, repoid, major_version):
+ def get_pesid_repo_entry(self, repoid, major_version, distro):
"""
- Retrieve the PESIDRepositoryEntry that matches the given repoid and OS major version.
+ Retrieve the PESIDRepositoryEntry that matches the given repoid, distro and OS major version
If multiple pesid repo entries with the same repoid were found, the entry with rhui matching the source
system's rhui info will be returned. If no entry with matching rhui exists, the CDN one is returned if any.
- Note that repositories are automatically filtered based on the specified OS release ID (self.distro).
-
- :param repoid: RepoID that should the PESIDRepositoryEntry match.
+ :param repoid: RepoID that the PESIDRepositoryEntry should match.
:type repoid: str
- :param major_version: RepoID that should the PESIDRepositoryEntry match.
+ :param major_version: Major version that the PESIDRepositoryEntry should match.
:type major_version: str
+ :param distro: Distro that the PESIDRepositoryEntry should match.
+ :type distro: str
:return: The PESIDRepositoryEntry matching the given repoid and major_version or None if no such
entry could be found.
:rtype: Optional[PESIDRepositoryEntry]
@@ -109,8 +120,8 @@ class RepoMapDataHandler:
matching_pesid_repos = []
for pesid_repo in self.repositories:
# FIXME(pstodulk): Why we do not check actually architecture here?
- # It seems obvious we should check it but the fixme comment below
- # suggests that it's expected - for not obvious reason.
+ # It seems obvious we should check it, but it's not clear why we
+ # don't and investigation might be required.
# For the investigation:
# # check repoids matching various architectures
# # check repoids without $arch in substring on how many architectures they are present
@@ -119,12 +130,13 @@ class RepoMapDataHandler:
if (
pesid_repo.repoid == repoid
and pesid_repo.major_version == major_version
- and pesid_repo.distro == self.distro
+ and pesid_repo.distro == distro
):
matching_pesid_repos.append(pesid_repo)
# FIXME: when a PESID is present for multiple architectures, there
- # multiple matching repos even though there should really be just one
+ # are multiple matching repos even though there should really be just
+ # one, the condition below fails even though it shouldn't
if len(matching_pesid_repos) == 1:
# Perform no heuristics if only a single pesid repository with matching repoid found
return matching_pesid_repos[0]
@@ -190,7 +202,7 @@ class RepoMapDataHandler:
the OS Major version same as the source OS.
:rtype: List[PESIDRepositoryEntry]
"""
- return self.get_pesid_repos(pesid, get_source_major_version(), self.distro)
+ return self.get_pesid_repos(pesid, get_source_major_version(), self.source_distro)
def get_target_pesid_repos(self, pesid):
"""
@@ -203,7 +215,7 @@ class RepoMapDataHandler:
the OS Major version same as the target OS.
:rtype: List[PESIDRepositoryEntry]
"""
- return self.get_pesid_repos(pesid, get_target_major_version(), self.distro)
+ return self.get_pesid_repos(pesid, get_target_major_version(), self.target_distro)
def _find_repository_target_equivalent(self, src_pesidrepo, target_pesid):
"""
@@ -223,7 +235,7 @@ class RepoMapDataHandler:
matches_rhui = candidate.rhui == src_pesidrepo.rhui
matches_repo_type = candidate.repo_type == 'rpm'
matches_arch = candidate.arch == api.current_actor().configuration.architecture
- matches_distro = candidate.distro == self.distro
+ matches_distro = candidate.distro == self.target_distro
if matches_rhui and matches_arch and matches_distro and matches_repo_type:
# user can specify in future the specific channel should be
@@ -295,7 +307,7 @@ class RepoMapDataHandler:
# {pesid: target_repo}
target_repos_best_candidates = {}
for src_repoid in src_repoids:
- src_pesidrepo = self.get_pesid_repo_entry(src_repoid, get_source_major_version())
+ src_pesidrepo = self.get_pesid_repo_entry(src_repoid, get_source_major_version(), self.source_distro)
if not src_pesidrepo:
# unmapped or custom repo -> skip this one
continue
@@ -340,7 +352,9 @@ def get_default_repository_channels(repomap, src_repoids):
default_pesid = DEFAULT_PESID[get_source_major_version()]
top_prio_pesid_repo = None
for repoid in src_repoids:
- pesid_repo = repomap.get_pesid_repo_entry(repoid, get_source_major_version())
+ pesid_repo = repomap.get_pesid_repo_entry(
+ repoid, get_source_major_version(), get_source_distro_id()
+ )
if not pesid_repo or pesid_repo.pesid != default_pesid:
continue
if not top_prio_pesid_repo or _get_channel_prio(pesid_repo) > _get_channel_prio(top_prio_pesid_repo):
diff --git a/repos/system_upgrade/common/actors/setuptargetrepos/tests/test_repomapping.py b/repos/system_upgrade/common/actors/setuptargetrepos/tests/test_repomapping.py
index 1b0a3122..30c415c0 100644
--- a/repos/system_upgrade/common/actors/setuptargetrepos/tests/test_repomapping.py
+++ b/repos/system_upgrade/common/actors/setuptargetrepos/tests/test_repomapping.py
@@ -98,15 +98,15 @@ def test_get_pesid_repo_entry(monkeypatch, repomap_data_for_pesid_repo_retrieval
fail_description = (
'get_pesid_repo_entry method failed to find correct pesid repository that matches given parameters.')
for exp_repo in repositories:
- result_repo = handler.get_pesid_repo_entry(exp_repo.repoid, exp_repo.major_version)
+ result_repo = handler.get_pesid_repo_entry(exp_repo.repoid, exp_repo.major_version, exp_repo.distro)
assert result_repo == exp_repo, fail_description
fail_description = (
'get_pesid_repo_entry method found a pesid repository, but no repository should match given parameters.')
- assert handler.get_pesid_repo_entry('pesid1-repoid', '6') is None, fail_description
- assert handler.get_pesid_repo_entry('pesid1-repoid', '8') is None, fail_description
- assert handler.get_pesid_repo_entry('pesid1-repoid', '9') is None, fail_description
- assert handler.get_pesid_repo_entry('nonexisting-repo', '7') is None, fail_description
+ assert handler.get_pesid_repo_entry('pesid1-repoid', '6', 'rhel') is None, fail_description
+ assert handler.get_pesid_repo_entry('pesid1-repoid', '8', 'rhel') is None, fail_description
+ assert handler.get_pesid_repo_entry('pesid1-repoid', '9', 'rhel') is None, fail_description
+ assert handler.get_pesid_repo_entry('nonexisting-repo', '7', 'rhel') is None, fail_description
@pytest.mark.parametrize('distro', ('rhel', 'centos', 'almalinux'))
@@ -117,13 +117,18 @@ def test_get_pesid_repo_entry_distro(
Test for the RepoMapDataHandler.get_pesid_repo_entry method.
Verifies that the method correctly retrieves PESIDRepositoryEntry that are
- matching the OS major version, repoid and the distro.
+ matching the OS major version, repoid and the distro, regardless of the
+ actual distro.
"""
monkeypatch.setattr(
api,
"current_actor",
CurrentActorMocked(
- arch="x86_64", src_ver="9.6", dst_ver="10.2", release_id=distro
+ arch="x86_64",
+ src_ver="9.6",
+ dst_ver="10.2",
+ src_distro=distro,
+ dst_distro=distro,
),
)
handler = RepoMapDataHandler(repomap_data_multiple_distros)
@@ -138,7 +143,7 @@ def test_get_pesid_repo_entry_distro(
)
for exp_repo in repositories:
result_repo = handler.get_pesid_repo_entry(
- exp_repo.repoid, exp_repo.major_version
+ exp_repo.repoid, exp_repo.major_version, exp_repo.distro
)
assert result_repo == exp_repo, fail_description
@@ -307,7 +312,7 @@ def test_get_target_pesid_repos(monkeypatch, repomap_data_for_pesid_repo_retriev
have the same major version and distro as the source system.
"""
monkeypatch.setattr(api, 'current_actor',
- CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4', release_id=distro))
+ CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4', dst_distro=distro))
handler = RepoMapDataHandler(repomap_data_for_pesid_repo_retrieval)
repositories = repomap_data_for_pesid_repo_retrieval.repositories
@@ -324,7 +329,7 @@ def test_get_target_pesid_repos(monkeypatch, repomap_data_for_pesid_repo_retriev
'The get_target_pesid_repos method doesn\'t take into account the target system version correctly.'
)
monkeypatch.setattr(api, 'current_actor',
- CurrentActorMocked(arch='x86_64', src_ver='9.4', dst_ver='10.0', release_id=distro))
+ CurrentActorMocked(arch='x86_64', src_ver='9.4', dst_ver='10.0', dst_distro=distro))
# Repeat the same test as above to make sure it respects the target OS major version
assert [] == handler.get_target_pesid_repos('pesid3'), fail_description
@@ -372,7 +377,7 @@ def test_find_repository_target_equivalent_fullmatch(
pesid repo parameters exactly when such repository is available in the repository mapping data.
"""
monkeypatch.setattr(api, 'current_actor',
- CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4', release_id=distro))
+ CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4', dst_distro=distro))
handler = RepoMapDataHandler(mapping_data_for_find_repository_equiv)
diff --git a/repos/system_upgrade/common/actors/setuptargetrepos/tests/test_setuptargetrepos.py b/repos/system_upgrade/common/actors/setuptargetrepos/tests/test_setuptargetrepos.py
index ce7f01c0..c3ff5f49 100644
--- a/repos/system_upgrade/common/actors/setuptargetrepos/tests/test_setuptargetrepos.py
+++ b/repos/system_upgrade/common/actors/setuptargetrepos/tests/test_setuptargetrepos.py
@@ -98,99 +98,104 @@ def test_repositories_setup_tasks(monkeypatch):
assert rhel_repos[0].repoid == 'rhel-8-server-rpms'
-@pytest.mark.parametrize('distro_id', ['rhel', 'centos', 'almalinux'])
-def test_repos_mapping_for_distro(monkeypatch, distro_id):
+@pytest.mark.parametrize('src_distro', ['rhel', 'centos', 'almalinux'])
+@pytest.mark.parametrize('dst_distro', ['rhel', 'centos', 'almalinux'])
+def test_repos_mapping_for_distro(monkeypatch, src_distro, dst_distro):
"""
Tests whether actor correctly determines what repositories should be enabled on target based
on the information about what repositories are enabled on the source system using
- the RepositoriesMapping information for a specific distro.
+ the RepositoriesMapping information for a specific source and target distro pair.
"""
repos_data = [
- RepositoryData(repoid='{}-8-server-rpms'.format(distro_id), name='{} 8 Server'.format(distro_id)),
- RepositoryData(repoid='{}-8-blacklisted-rpms'.format(distro_id), name='{} 8 Blacklisted'.format(distro_id))]
+ RepositoryData(repoid='{}-8-server-rpms'.format(src_distro), name='{} 8 Server'.format(src_distro)),
+ RepositoryData(repoid='{}-8-blacklisted-rpms'.format(src_distro), name='{} 8 Blacklisted'.format(src_distro))]
repos_files = [RepositoryFile(file='/etc/yum.repos.d/redhat.repo', data=repos_data)]
facts = RepositoriesFacts(repositories=repos_files)
installed_rpms = InstalledRPM(
- items=[mock_package('foreman', '{}-8-for-x86_64-satellite-extras-rpms'.format(distro_id)),
- mock_package('foreman-proxy', 'nosuch-{}-8-for-x86_64-satellite-extras-rpms'.format(distro_id))])
+ items=[mock_package('foreman', '{}-8-for-x86_64-satellite-extras-rpms'.format(src_distro)),
+ mock_package('foreman-proxy', 'nosuch-{}-8-for-x86_64-satellite-extras-rpms'.format(src_distro))])
repomap = RepositoriesMapping(
- mapping=[RepoMapEntry(source='{0}8-base'.format(distro_id),
- target=['{0}9-baseos'.format(distro_id),
- '{0}9-appstream'.format(distro_id),
- '{0}9-blacklist'.format(distro_id)]),
- RepoMapEntry(source='{0}8-satellite-extras'.format(distro_id),
- target=['{0}9-satellite-extras'.format(distro_id)])],
+ mapping=[RepoMapEntry(source='{0}8-base'.format(src_distro),
+ target=['{0}9-baseos'.format(dst_distro),
+ '{0}9-appstream'.format(dst_distro),
+ '{0}9-blacklist'.format(dst_distro)]),
+ RepoMapEntry(source='{0}8-satellite-extras'.format(src_distro),
+ target=['{0}9-satellite-extras'.format(dst_distro)])],
repositories=[
PESIDRepositoryEntry(
- pesid='{0}8-base'.format(distro_id),
- repoid='{0}-8-server-rpms'.format(distro_id),
+ pesid='{0}8-base'.format(src_distro),
+ repoid='{0}-8-server-rpms'.format(src_distro),
major_version='8',
arch='x86_64',
repo_type='rpm',
channel='ga',
rhui='',
- distro=distro_id,
+ distro=src_distro,
),
PESIDRepositoryEntry(
- pesid='{0}9-baseos'.format(distro_id),
- repoid='{0}-9-for-x86_64-baseos-htb-rpms'.format(distro_id),
+ pesid='{0}9-baseos'.format(dst_distro),
+ repoid='{0}-9-for-x86_64-baseos-htb-rpms'.format(dst_distro),
major_version='9',
arch='x86_64',
repo_type='rpm',
channel='ga',
rhui='',
- distro=distro_id,
+ distro=dst_distro,
),
PESIDRepositoryEntry(
- pesid='{0}9-appstream'.format(distro_id),
- repoid='{0}-9-for-x86_64-appstream-htb-rpms'.format(distro_id),
+ pesid='{0}9-appstream'.format(dst_distro),
+ repoid='{0}-9-for-x86_64-appstream-htb-rpms'.format(dst_distro),
major_version='9',
arch='x86_64',
repo_type='rpm',
channel='ga',
rhui='',
- distro=distro_id,
+ distro=dst_distro,
),
PESIDRepositoryEntry(
- pesid='{0}9-blacklist'.format(distro_id),
- repoid='{0}-9-blacklisted-rpms'.format(distro_id),
+ pesid='{0}9-blacklist'.format(dst_distro),
+ repoid='{0}-9-blacklisted-rpms'.format(dst_distro),
major_version='9',
arch='x86_64',
repo_type='rpm',
channel='ga',
rhui='',
- distro=distro_id,
+ distro=dst_distro,
),
PESIDRepositoryEntry(
- pesid='{0}8-satellite-extras'.format(distro_id),
- repoid='{0}-8-for-x86_64-satellite-extras-rpms'.format(distro_id),
+ pesid='{0}8-satellite-extras'.format(src_distro),
+ repoid='{0}-8-for-x86_64-satellite-extras-rpms'.format(src_distro),
major_version='8',
arch='x86_64',
repo_type='rpm',
channel='ga',
rhui='',
- distro=distro_id,
+ distro=src_distro,
),
PESIDRepositoryEntry(
- pesid='{0}9-satellite-extras'.format(distro_id),
- repoid='{0}-9-for-x86_64-satellite-extras-rpms'.format(distro_id),
+ pesid='{0}9-satellite-extras'.format(dst_distro),
+ repoid='{0}-9-for-x86_64-satellite-extras-rpms'.format(dst_distro),
major_version='9',
arch='x86_64',
repo_type='rpm',
channel='ga',
rhui='',
- distro=distro_id,
+ distro=dst_distro,
),
]
)
- repos_blacklisted = RepositoriesBlacklisted(repoids=['{}-9-blacklisted-rpms'.format(distro_id)])
+ repos_blacklisted = RepositoriesBlacklisted(repoids=['{}-9-blacklisted-rpms'.format(dst_distro)])
msgs = [facts, repomap, repos_blacklisted, installed_rpms]
- monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=msgs, release_id=distro_id))
+ monkeypatch.setattr(
+ api,
+ 'current_actor',
+ CurrentActorMocked(msgs=msgs, src_distro=src_distro, dst_distro=dst_distro),
+ )
monkeypatch.setattr(api, 'produce', produce_mocked())
setuptargetrepos.process()
@@ -205,14 +210,14 @@ def test_repos_mapping_for_distro(monkeypatch, distro_id):
produced_rhel_repoids = {repo.repoid for repo in rhel_repos}
expected_repoids = {
- "{0}-9-for-x86_64-baseos-htb-rpms".format(distro_id),
- "{0}-9-for-x86_64-appstream-htb-rpms".format(distro_id),
- "{0}-9-for-x86_64-satellite-extras-rpms".format(distro_id),
+ "{0}-9-for-x86_64-baseos-htb-rpms".format(dst_distro),
+ "{0}-9-for-x86_64-appstream-htb-rpms".format(dst_distro),
+ "{0}-9-for-x86_64-satellite-extras-rpms".format(dst_distro),
}
assert produced_distro_repoids == expected_repoids
- if distro_id == 'rhel':
+ if dst_distro == 'rhel':
assert len(rhel_repos) == 3
assert produced_rhel_repoids == expected_repoids
else:
- assert len(rhel_repos) == 0
+ assert not rhel_repos
diff --git a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py
index 899d72f7..9df83ef8 100644
--- a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py
+++ b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py
@@ -7,7 +7,7 @@ from leapp import reporting
from leapp.exceptions import StopActorExecution, StopActorExecutionError
from leapp.libraries.actor import constants
from leapp.libraries.common import distro, dnfplugin, mounting, overlaygen, repofileutils, rhsm, utils
-from leapp.libraries.common.config import get_distro_id, get_env, get_product_type
+from leapp.libraries.common.config import get_env, get_product_type, get_target_distro_id
from leapp.libraries.common.config.version import get_target_major_version
from leapp.libraries.common.gpg import get_path_to_gpg_certs, is_nogpgcheck_set
from leapp.libraries.stdlib import api, CalledProcessError, config, run
@@ -151,7 +151,8 @@ def _backup_to_persistent_package_cache(userspace_dir):
def _import_gpg_keys(context, install_root_dir, target_major_version):
certs_path = get_path_to_gpg_certs()
- # Import the RHEL X+1 GPG key to be able to verify the installation of initial packages
+ # Import the target distro target version GPG key to be able to verify the
+ # installation of initial packages
try:
# Import also any other keys provided by the customer in the same directory
for certname in os.listdir(certs_path):
@@ -676,12 +677,13 @@ def _get_product_certificate_path():
"""
Retrieve the required / used product certificate for RHSM.
- Product certificates are only used on RHEL, on non-RHEL systems the function returns None.
+ Product certificates are only used for RHEL. Returns None if the target
+ distro is not RHEL.
:return: The path to the product certificate or None on non-RHEL systems
:raises: StopActorExecution if a certificate cannot be found
"""
- if get_distro_id() != 'rhel':
+ if get_target_distro_id() != 'rhel':
return None
architecture = api.current_actor().configuration.architecture
@@ -960,7 +962,7 @@ def _get_distro_available_repoids(context, indata):
:rtype: set[str]
"""
distro_repoids = distro.get_target_distro_repoids(context)
- distro_id = get_distro_id()
+ distro_id = get_target_distro_id()
rhel_and_rhsm = distro_id == 'rhel' and not rhsm.skip_rhsm()
if distro_id != 'rhel' or rhel_and_rhsm:
_inhibit_if_no_base_repos(distro_repoids)
@@ -997,14 +999,16 @@ def gather_target_repositories(context, indata):
if distro_repoids:
api.current_logger().info(
"The following repoids are considered as provided by the '{}' distribution:{}{}".format(
- get_distro_id(),
+ get_target_distro_id(),
FMT_LIST_SEPARATOR,
FMT_LIST_SEPARATOR.join(sorted(distro_repoids)),
)
)
else:
api.current_logger().warning(
- "No repoids provided by the {} distribution have been discovered".format(get_distro_id())
+ "No repoids provided by the {} distribution have been discovered".format(
+ get_target_distro_id()
+ )
)
all_repoids = _get_all_available_repoids(context)
@@ -1153,7 +1157,7 @@ def _gather_target_repositories(context, indata, prod_cert_path):
rhsm.set_container_mode(context)
rhsm.switch_certificate(context, indata.rhsm_info, prod_cert_path)
- if api.current_actor().configuration.os_release.release_id == 'centos':
+ if get_target_distro_id() == 'centos':
adjust_dnf_stream_variable(context)
_install_custom_repofiles(context, indata.custom_repofiles)
diff --git a/repos/system_upgrade/common/actors/targetuserspacecreator/tests/unit_test_targetuserspacecreator.py b/repos/system_upgrade/common/actors/targetuserspacecreator/tests/unit_test_targetuserspacecreator.py
index 0bb64f6f..d783843c 100644
--- a/repos/system_upgrade/common/actors/targetuserspacecreator/tests/unit_test_targetuserspacecreator.py
+++ b/repos/system_upgrade/common/actors/targetuserspacecreator/tests/unit_test_targetuserspacecreator.py
@@ -880,8 +880,9 @@ def test_get_product_certificate_path(monkeypatch, adjust_cwd, result, dst_ver,
assert userspacegen._get_product_certificate_path() in result
-def test_get_product_certificate_path_nonrhel(monkeypatch):
- actor = CurrentActorMocked(release_id='notrhel')
+@pytest.mark.parametrize('src_distro', ('rhel', 'centos'))
+def test_get_product_certificate_path_nonrhel(monkeypatch, src_distro):
+ actor = CurrentActorMocked(src_distro=src_distro, dst_distro='notrhel')
monkeypatch.setattr(userspacegen.api, 'current_actor', actor)
path = userspacegen._get_product_certificate_path()
assert path is None
@@ -1225,7 +1226,7 @@ def test__get_distro_available_repoids_nobaserepos_inhibit(
Test that get_distro_available repoids reports and raises if there are no base repos.
"""
monkeypatch.setattr(
- userspacegen.api, "current_actor", CurrentActorMocked(release_id=distro_id)
+ userspacegen.api, "current_actor", CurrentActorMocked(dst_distro=distro_id)
)
monkeypatch.setattr(userspacegen.api.current_actor(), 'produce', produce_mocked())
monkeypatch.setattr(reporting, "create_report", create_report_mocked())
@@ -1425,8 +1426,11 @@ def test_failing_stream_varfile_write(monkeypatch):
assert 'Failed to adjust dnf variable' in str(err.value)
-@pytest.mark.parametrize("distro,should_adjust", [('rhel', False), ('centos', True)])
-def test_if_adjust_dnf_stream_variable_only_for_centos(monkeypatch, distro, should_adjust):
+@pytest.mark.parametrize('src_distro', ('rhel', 'centos'))
+@pytest.mark.parametrize("dst_distro,should_adjust", [('rhel', False), ('centos', True)])
+def test_if_adjust_dnf_stream_variable_only_for_centos(
+ monkeypatch, src_distro, dst_distro, should_adjust
+):
def do_nothing(*args, **kwargs):
pass
@@ -1436,7 +1440,11 @@ def test_if_adjust_dnf_stream_variable_only_for_centos(monkeypatch, distro, shou
nonlocal adjust_called
adjust_called = True
- monkeypatch.setattr(userspacegen.api, 'current_actor', CurrentActorMocked(release_id=distro))
+ monkeypatch.setattr(
+ userspacegen.api,
+ "current_actor",
+ CurrentActorMocked(src_distro=src_distro, dst_distro=dst_distro),
+ )
monkeypatch.setattr(userspacegen, 'get_target_major_version', lambda: '10')
monkeypatch.setattr(rhsm, 'set_container_mode', do_nothing)
monkeypatch.setattr(rhsm, 'switch_certificate', do_nothing)
diff --git a/repos/system_upgrade/common/libraries/config/__init__.py b/repos/system_upgrade/common/libraries/config/__init__.py
index 11d26c0e..396c524a 100644
--- a/repos/system_upgrade/common/libraries/config/__init__.py
+++ b/repos/system_upgrade/common/libraries/config/__init__.py
@@ -1,5 +1,6 @@
from leapp.exceptions import StopActorExecutionError
from leapp.libraries.stdlib import api
+from leapp.utils.deprecation import deprecated
# The devel variable for target product channel can also contain 'beta'
SUPPORTED_TARGET_CHANNELS = {'ga', 'e4s', 'eus', 'aus'}
@@ -99,9 +100,13 @@ def get_consumed_data_stream_id():
return CONSUMED_DATA_STREAM_ID
+@deprecated(
+ since="2025-10-27",
+ message="Use get_source_distro_id or get_target_distro_id instead.",
+)
def get_distro_id():
"""
- Retrieve the distro ID.
+ Retrieve the distro ID of the source system.
This is the ID string from /etc/os_release.
E.g. "rhel" for Red Hat Enterprise Linux
@@ -110,3 +115,29 @@ def get_distro_id():
:rtype: str
"""
return api.current_actor().configuration.distro.source
+
+
+def get_source_distro_id():
+ """
+ Retrieve the distro ID of the source system.
+
+ This is the ID string from /etc/os_release.
+ E.g. "rhel" for Red Hat Enterprise Linux
+
+ :return: The ID string from /etc/os_release
+ :rtype: str
+ """
+ return api.current_actor().configuration.distro.source
+
+
+def get_target_distro_id():
+ """
+ Retrieve the distro ID for the target system.
+
+ The ID follows the naming convention that is used in /etc/os_release files.
+ E.g. "rhel" for Red Hat Enterprise Linux, "centos" for Centos (Stream), etc.
+
+ :return: The ID for the target system
+ :rtype: str
+ """
+ return api.current_actor().configuration.distro.target
diff --git a/repos/system_upgrade/common/libraries/distro.py b/repos/system_upgrade/common/libraries/distro.py
index d6a2381a..04e553ac 100644
--- a/repos/system_upgrade/common/libraries/distro.py
+++ b/repos/system_upgrade/common/libraries/distro.py
@@ -3,7 +3,7 @@ import os
from leapp.exceptions import StopActorExecutionError
from leapp.libraries.common import repofileutils, rhsm
-from leapp.libraries.common.config import get_distro_id
+from leapp.libraries.common.config import get_target_distro_id
from leapp.libraries.common.config.architecture import ARCH_ACCEPTED, ARCH_X86_64
from leapp.libraries.common.config.version import get_target_major_version
from leapp.libraries.stdlib import api
@@ -141,7 +141,7 @@ def get_target_distro_repoids(context):
return get_distro_repoids(
context,
- get_distro_id(),
+ get_target_distro_id(),
get_target_major_version(),
api.current_actor().configuration.architecture
)
diff --git a/repos/system_upgrade/common/libraries/gpg.py b/repos/system_upgrade/common/libraries/gpg.py
index c9c3f1fc..9990cdcf 100644
--- a/repos/system_upgrade/common/libraries/gpg.py
+++ b/repos/system_upgrade/common/libraries/gpg.py
@@ -105,6 +105,8 @@ def get_gpg_fp_from_file(key_path):
return fp
+# TODO when a need for the same function for source arises, or when there is
+# reason to deprecate this (re)name this to include "target"
def get_path_to_gpg_certs():
"""
Get path to the directory with trusted target gpg keys in the common leapp repository.
@@ -121,7 +123,7 @@ def get_path_to_gpg_certs():
# only beta is special in regards to the GPG signing keys
if target_product_type == 'beta':
certs_dir = '{}beta'.format(target_major_version)
- distro = api.current_actor().configuration.os_release.release_id
+ distro = config.get_target_distro_id()
return os.path.join(
api.get_common_folder_path('distro'),
distro,
diff --git a/repos/system_upgrade/common/libraries/rhsm.py b/repos/system_upgrade/common/libraries/rhsm.py
index 79164cca..2112ca3d 100644
--- a/repos/system_upgrade/common/libraries/rhsm.py
+++ b/repos/system_upgrade/common/libraries/rhsm.py
@@ -7,7 +7,7 @@ import time
from leapp import reporting
from leapp.exceptions import StopActorExecutionError
from leapp.libraries.common import repofileutils
-from leapp.libraries.common.config import get_distro_id, get_env
+from leapp.libraries.common.config import get_env, get_target_distro_id
from leapp.libraries.stdlib import api, CalledProcessError
from leapp.models import RHSMInfo
@@ -337,8 +337,8 @@ def set_container_mode(context):
:param context: An instance of a mounting.IsolatedActions class
:type context: mounting.IsolatedActions class
"""
- # this has to happen even with skip_rhsm, but only on RHEL
- if get_distro_id() != 'rhel':
+ # this has to happen even with skip_rhsm, but only on RHEL target
+ if get_target_distro_id() != 'rhel':
api.current_logger().info(
'Skipping setting RHSM into container mode on non-RHEL systems.'
)
diff --git a/repos/system_upgrade/common/libraries/tests/test_gpg.py b/repos/system_upgrade/common/libraries/tests/test_gpg.py
index 47617ad8..1394e60d 100644
--- a/repos/system_upgrade/common/libraries/tests/test_gpg.py
+++ b/repos/system_upgrade/common/libraries/tests/test_gpg.py
@@ -22,7 +22,7 @@ from leapp.models import GpgKey, InstalledRPM, RPM
('10.0', 'ga', 'almalinux', '../../files/distro/almalinux/rpm-gpg/10'),
])
def test_get_path_to_gpg_certs(monkeypatch, target, product_type, distro, exp):
- current_actor = CurrentActorMocked(dst_ver=target, release_id=distro,
+ current_actor = CurrentActorMocked(dst_ver=target, dst_distro=distro,
envars={'LEAPP_DEVEL_TARGET_PRODUCT_TYPE': product_type})
monkeypatch.setattr(api, 'current_actor', current_actor)
diff --git a/repos/system_upgrade/common/libraries/tests/test_rhsm.py b/repos/system_upgrade/common/libraries/tests/test_rhsm.py
index b118da29..b0b7df79 100644
--- a/repos/system_upgrade/common/libraries/tests/test_rhsm.py
+++ b/repos/system_upgrade/common/libraries/tests/test_rhsm.py
@@ -425,7 +425,7 @@ def test_is_registered_error(context_mocked):
def test_set_container_mode(monkeypatch, context_mocked):
- actor = CurrentActorMocked(release_id='rhel')
+ actor = CurrentActorMocked(dst_distro='rhel')
monkeypatch.setattr(api, 'current_actor', actor)
monkeypatch.setattr(
os.path, "exists", lambda path: path in ("/etc/rhsm", "/etc/pki/entitlement")
@@ -440,7 +440,7 @@ def test_set_container_mode(monkeypatch, context_mocked):
def test_set_container_mode_nonrhel_skip(monkeypatch, context_mocked):
- actor = CurrentActorMocked(release_id='notrhel')
+ actor = CurrentActorMocked(dst_distro='notrhel')
monkeypatch.setattr(api, 'current_actor', actor)
rhsm.set_container_mode(context_mocked)
--
2.51.1