diff --git a/conftest.py b/conftest.py index 300415ff1f..f0db0c375c 100644 --- a/conftest.py +++ b/conftest.py @@ -1,28 +1,48 @@ import logging import os +from leapp.repository.manager import RepositoryManager from leapp.repository.scan import find_and_scan_repositories -from leapp.utils.repository import find_repository_basedir +from leapp.utils.repository import find_repository_basedir, get_repository_id logger = logging.getLogger(__name__) logging.getLogger("asyncio").setLevel(logging.INFO) logging.getLogger("parso").setLevel(logging.INFO) +def _load_and_add_repo(manager, repo_path): + repo = find_and_scan_repositories( + repo_path, + include_locals=True + ) + unloaded = set() + loaded = {r.repo_id for r in manager.repos} + if hasattr(repo, 'repos'): + for repo in repo.repos: + if not manager.repo_by_id(repo.repo_id): + manager.add_repo(repo) + unloaded.add(repo.repo_id) + else: + manager.add_repo(repo) + if not loaded: + manager.load(skip_actors_discovery=True) + else: + for repo_id in unloaded: + manager.repo_by_id(repo_id).load(skip_actors_discovery=True) + + def pytest_collectstart(collector): if collector.nodeid: - current_repo_basedir = find_repository_basedir(collector.nodeid) - # loading the current repo - if ( - not hasattr(collector.session, "leapp_repository") - or current_repo_basedir != collector.session.repo_base_dir - ): - repo = find_and_scan_repositories( - find_repository_basedir(collector.nodeid), include_locals=True - ) - repo.load(skip_actors_discovery=True) - collector.session.leapp_repository = repo + current_repo_basedir = find_repository_basedir(str(collector.fspath)) + if not hasattr(collector.session, "leapp_repository"): + collector.session.leapp_repository = RepositoryManager() collector.session.repo_base_dir = current_repo_basedir + _load_and_add_repo(collector.session.leapp_repository, current_repo_basedir) + else: + if not collector.session.leapp_repository.repo_by_id( + get_repository_id(current_repo_basedir) + ): + _load_and_add_repo(collector.session.leapp_repository, current_repo_basedir) # we're forcing the actor context switch only when traversing new # actor diff --git a/repos/system_upgrade/common/actors/checkosrelease/libraries/checkosrelease.py b/repos/system_upgrade/common/actors/checkosrelease/libraries/checkosrelease.py index 24aa04351a..8dd4e4b3ae 100644 --- a/repos/system_upgrade/common/actors/checkosrelease/libraries/checkosrelease.py +++ b/repos/system_upgrade/common/actors/checkosrelease/libraries/checkosrelease.py @@ -31,12 +31,16 @@ def check_os_version(): for ver in version.SUPPORTED_VERSIONS[rel]: supported_releases.append(rel.upper() + ' ' + ver) reporting.create_report([ - reporting.Title('The installed OS version is not supported for the in-place upgrade to RHEL 8'), + reporting.Title( + 'The installed OS version is not supported for the in-place upgrade to the target RHEL version' + ), reporting.Summary( 'The supported OS releases for the upgrade process:\n' ' {}'.format('\n'.join(supported_releases)) ), reporting.Severity(reporting.Severity.HIGH), reporting.Tags(COMMON_REPORT_TAGS), - reporting.Flags([reporting.Flags.INHIBITOR]) + reporting.Flags([reporting.Flags.INHIBITOR]), + # we want to set a static Key here because of different Title per path + reporting.Key('1c7a98849a747ec9890f04bf4321de7280970715') ] + related) diff --git a/repos/system_upgrade/common/actors/checkosrelease/tests/test_checkosrelease.py b/repos/system_upgrade/common/actors/checkosrelease/tests/test_checkosrelease.py index 046f1accf6..13183b6bc1 100644 --- a/repos/system_upgrade/common/actors/checkosrelease/tests/test_checkosrelease.py +++ b/repos/system_upgrade/common/actors/checkosrelease/tests/test_checkosrelease.py @@ -30,6 +30,7 @@ def test_no_skip_check(monkeypatch): def test_not_supported_release(monkeypatch): monkeypatch.setattr(version, "is_supported_version", lambda: False) + monkeypatch.setattr(version, "get_source_major_version", lambda: '7') monkeypatch.setattr(reporting, "create_report", create_report_mocked()) checkosrelease.check_os_version() diff --git a/repos/system_upgrade/common/actors/checkskipphase/actor.py b/repos/system_upgrade/common/actors/checkskipphase/actor.py index be4da3e7f3..91b4371022 100644 --- a/repos/system_upgrade/common/actors/checkskipphase/actor.py +++ b/repos/system_upgrade/common/actors/checkskipphase/actor.py @@ -8,13 +8,13 @@ class CheckSkipPhase(Actor): """ Skip all the subsequent phases until the report phase. - The phases that follow after the Checks phase work with the target (RHEL 8) - user space - stuff around preparing and checking the rpm transaction. - We do not want to process those phases in case of inhibition - e.g. for - a specific HW unsupported by the target system we cannot do anything - we - can just see some unclear errors in such case. So we want to instead skip - to the Reports phase to provide clear report to user without confusing - errors. + The phases that follow after the Checks phase work with the target + RHEL major version user space - stuff around preparing and checking + the rpm transaction. We do not want to process those phases in case of + inhibition - e.g. for a specific HW unsupported by the target system we + cannot do anything - we can just see some unclear errors in such case. + So we want to instead skip to the Reports phase to provide clear report + to user without confusing errors. The actor is processed after all actors in the phase (that provides Report messages) are processed. diff --git a/repos/system_upgrade/common/actors/checktargetrepos/libraries/checktargetrepos.py b/repos/system_upgrade/common/actors/checktargetrepos/libraries/checktargetrepos.py index 7613ece881..094e63d4bf 100644 --- a/repos/system_upgrade/common/actors/checktargetrepos/libraries/checktargetrepos.py +++ b/repos/system_upgrade/common/actors/checktargetrepos/libraries/checktargetrepos.py @@ -4,8 +4,6 @@ from leapp.libraries.common import config, rhsm -_IPU_DOC_URL = ('https://access.redhat.com/documentation/en-us/' - 'red_hat_enterprise_linux/8/html-single/upgrading_to_rhel_8/index') # TODO: we need to provide this path in a shared library CUSTOM_REPO_PATH = '/etc/leapp/files/leapp_upgrade_repositories.repo' @@ -28,7 +26,20 @@ def _the_enablerepo_option_used(): return config.get_env('LEAPP_ENABLE_REPOS', None) is not None +def _get_target_major_version(): + return api.current_actor().configuration.version.target.split('.')[0] + + def process(): + target_major_version = _get_target_major_version() + + if target_major_version == '8': + ipu_doc_url = ( + 'https://access.redhat.com/documentation/en-us/' + 'red_hat_enterprise_linux/8/html-single/upgrading_to_rhel_8/index' + ) + elif target_major_version == '9': + ipu_doc_url = ('TBA') rhui_info = next(api.consume(RHUIInfo), None) @@ -72,7 +83,7 @@ def process(): reporting.Severity(reporting.Severity.HIGH), reporting.Tags([reporting.Tags.SANITY]), reporting.Flags([reporting.Flags.INHIBITOR]), - reporting.ExternalLink(url=_IPU_DOC_URL, title='UPGRADING TO RHEL 8'), + reporting.ExternalLink(url=ipu_doc_url, title='UPGRADING TO RHEL {}'.format(target_major_version)), reporting.RelatedResource('file', CUSTOM_REPO_PATH), ]) elif not (is_ctrf or is_re): @@ -95,6 +106,6 @@ def process(): ' message.' )), reporting.Severity(reporting.Severity.INFO), - reporting.ExternalLink(url=_IPU_DOC_URL, title='UPGRADING TO RHEL 8'), + reporting.ExternalLink(url=ipu_doc_url, title='UPGRADING TO RHEL {}'.format(target_major_version)), reporting.RelatedResource('file', CUSTOM_REPO_PATH), ]) diff --git a/repos/system_upgrade/common/actors/checktargetrepos/tests/test_checktargetrepos.py b/repos/system_upgrade/common/actors/checktargetrepos/tests/test_checktargetrepos.py index cbd953a2d7..47623a4289 100644 --- a/repos/system_upgrade/common/actors/checktargetrepos/tests/test_checktargetrepos.py +++ b/repos/system_upgrade/common/actors/checktargetrepos/tests/test_checktargetrepos.py @@ -54,6 +54,7 @@ def test_checktargetrepos_rhsm(monkeypatch): monkeypatch.setattr(reporting, 'create_report', create_report_mocked()) monkeypatch.setattr(rhsm, 'skip_rhsm', lambda: False) monkeypatch.setattr(api, 'consume', MockedConsume()) + monkeypatch.setattr(checktargetrepos, '_get_target_major_version', lambda: '8') checktargetrepos.process() assert reporting.create_report.called == 0 @@ -71,6 +72,7 @@ def test_checktargetrepos_no_rhsm(monkeypatch, enable_repos, custom_target_repos monkeypatch.setattr(reporting, 'create_report', create_report_mocked()) monkeypatch.setattr(rhsm, 'skip_rhsm', lambda: True) monkeypatch.setattr(api, 'consume', mocked_consume) + monkeypatch.setattr(checktargetrepos, '_get_target_major_version', lambda: '8') checktargetrepos.process() diff --git a/repos/system_upgrade/common/actors/initramfs/targetinitramfsgenerator/actor.py b/repos/system_upgrade/common/actors/initramfs/targetinitramfsgenerator/actor.py index 580202222c..2aa2a4f83e 100644 --- a/repos/system_upgrade/common/actors/initramfs/targetinitramfsgenerator/actor.py +++ b/repos/system_upgrade/common/actors/initramfs/targetinitramfsgenerator/actor.py @@ -12,7 +12,7 @@ @suppress_deprecation(InitrdIncludes) class TargetInitramfsGenerator(Actor): """ - Regenerate RHEL-8 initrd and include files produced by other actors + Regenerate the target RHEL major version initrd and include files produced by other actors """ name = 'target_initramfs_generator' diff --git a/repos/system_upgrade/common/actors/kernelcmdlineconfig/actor.py b/repos/system_upgrade/common/actors/kernelcmdlineconfig/actor.py index 5d34220a98..d438381670 100644 --- a/repos/system_upgrade/common/actors/kernelcmdlineconfig/actor.py +++ b/repos/system_upgrade/common/actors/kernelcmdlineconfig/actor.py @@ -9,7 +9,7 @@ class KernelCmdlineConfig(Actor): """ - Append extra arguments to RHEL-8 kernel command line + Append extra arguments to the target RHEL kernel command line """ name = 'kernelcmdlineconfig' diff --git a/repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner.py b/repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner.py index ecb083880f..7a121c2def 100644 --- a/repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner.py +++ b/repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner.py @@ -337,23 +337,26 @@ def process_events(releases, events, installed_pkgs): for event in release_events: if is_event_relevant(event, installed_pkgs, tasks): if event.action in [Action.DEPRECATED, Action.PRESENT]: - # Keep these packages to make sure the repo they're in on RHEL 8 gets enabled + # Keep these packages to make sure the repo they're in on the target RHEL system + # gets enabled add_packages_to_tasks(current, event.in_pkgs, Task.KEEP) if event.action == Action.MOVED: - # Keep these packages to make sure the repo they're in on RHEL 8 gets enabled + # Keep these packages to make sure the repo they're in on the target RHEL system + # gets enabled # We don't care about the "in_pkgs" as it contains always just one pkg - the same as the "out" pkg add_packages_to_tasks(current, event.out_pkgs, Task.KEEP) if event.action in [Action.SPLIT, Action.MERGED, Action.RENAMED, Action.REPLACED]: non_installed_out_pkgs = filter_out_installed_pkgs(event.out_pkgs, installed_pkgs) add_packages_to_tasks(current, non_installed_out_pkgs, Task.INSTALL) - # Keep already installed "out" pkgs to ensure the repo they're in on RHEL 8 gets enabled + # Keep already installed "out" pkgs to ensure the repo they're in on the target RHEL system + # gets enabled installed_out_pkgs = get_installed_event_pkgs(event.out_pkgs, installed_pkgs) add_packages_to_tasks(current, installed_out_pkgs, Task.KEEP) if event.action in [Action.SPLIT, Action.MERGED]: - # Remove those RHEL 7 pkgs that are no longer on RHEL 8 + # Remove the previous RHEL version pkgs that are no longer on the target RHEL system in_pkgs_without_out_pkgs = filter_out_out_pkgs(event.in_pkgs, event.out_pkgs) add_packages_to_tasks(current, in_pkgs_without_out_pkgs, Task.REMOVE) @@ -420,8 +423,8 @@ def get_installed_event_pkgs(event_pkgs, installed_pkgs): """ Get those event's "in" or "out" packages which are already installed. - Even though we don't want to install the already installed pkgs, to be able to upgrade them to their RHEL 8 version - we need to know in which repos they are and enable such repos. + Even though we don't want to install the already installed pkgs, to be able to upgrade them to + their target RHEL major version. We need to know in which repos they are and enable such repos. """ return {k: v for k, v in event_pkgs.items() if k in installed_pkgs} @@ -438,11 +441,10 @@ def filter_out_out_pkgs(event_in_pkgs, event_out_pkgs): SKIPPED_PKGS_MSG = ( - 'packages will be skipped because they are available only in ' - 'RHEL 8 repositories that are intentionally excluded from the ' - 'list of repositories used during the upgrade. ' - 'See the report message titled "Excluded RHEL 8 repositories" ' - 'for details.\nThe list of these packages:' + 'packages will be skipped because they are available only in the target RHEL major version ' + 'repositories that are intentionally excluded from the list of repositories used during the upgrade. ' + 'See the report message titled "Excluded target RHEL major version repositories" for ' + 'details.\nThe list of these packages:' ) @@ -522,7 +524,7 @@ def map_repositories(packages): package_repo_pairs=pkg_with_repo_without_mapping, remediation=( "Please file a bug in http://bugzilla.redhat.com/ for leapp-repository component of " - "the Red Hat Enterprise Linux 7 product." + "the Red Hat Enterprise Linux product." ), ) @@ -562,7 +564,7 @@ def add_output_pkgs_to_transaction_conf(transaction_configuration, events): on the user configuration files :param events: List of Event tuples, where each event contains event type and input/output pkgs """ - message = 'The following RHEL 8 packages will not be installed:\n' + message = 'The following target RHEL major version packages will not be installed:\n' for event in events: if event.action in (Action.SPLIT, Action.MERGED, Action.REPLACED, Action.RENAMED): diff --git a/repos/system_upgrade/common/actors/reportsettargetrelease/actor.py b/repos/system_upgrade/common/actors/reportsettargetrelease/actor.py index c1aa6814e5..83f489da19 100644 --- a/repos/system_upgrade/common/actors/reportsettargetrelease/actor.py +++ b/repos/system_upgrade/common/actors/reportsettargetrelease/actor.py @@ -10,8 +10,8 @@ class ReportSetTargetRelease(Actor): When using Red Hat subscription-manager (RHSM), the release is set by default to the target version release. In case of skip of the RHSM (--no-rhsm), the - release stay as it is on the RHEL 7 and user has to handle it manually after - the upgrade. + release stay as it was on the source RHEL major version and user has to handle + it manually aftervthe upgrade. """ name = 'report_set_target_release' diff --git a/repos/system_upgrade/common/actors/reportsettargetrelease/libraries/reportsettargetrelease.py b/repos/system_upgrade/common/actors/reportsettargetrelease/libraries/reportsettargetrelease.py index 815fe7d402..057fabd920 100644 --- a/repos/system_upgrade/common/actors/reportsettargetrelease/libraries/reportsettargetrelease.py +++ b/repos/system_upgrade/common/actors/reportsettargetrelease/libraries/reportsettargetrelease.py @@ -15,8 +15,9 @@ def _report_set_release(): ), reporting.Severity(reporting.Severity.LOW), reporting.Remediation( - hint='If you wish to receive updates for the latest released version of RHEL 8, run `subscription-manager' - ' release --unset` after the upgrade.'), + hint='If you wish to receive updates for the latest released version of the target system, ' + 'run `subscription-manager release --unset` after the upgrade.' + ), reporting.Tags([reporting.Tags.UPGRADE_PROCESS]), reporting.RelatedResource('package', 'subscription-manager') ]) @@ -36,7 +37,7 @@ def _report_unhandled_release(): 'The upgrade is executed with the --no-rhsm option (or with' ' the LEAPP_NO_RHSM environment variable). In this case, the subscription-manager' ' will not be configured during the upgrade. If the system is subscribed and release' - ' is set already, you could encounter issues to get RHEL 8 content using DNF/YUM' + ' is set already, you could encounter issues to get RHEL content using DNF/YUM' ' after the upgrade.' ), reporting.Severity(reporting.Severity.LOW), diff --git a/repos/system_upgrade/common/actors/rpmscanner/libraries/rpmscanner.py b/repos/system_upgrade/common/actors/rpmscanner/libraries/rpmscanner.py index 585916964d..0951b01ccd 100644 --- a/repos/system_upgrade/common/actors/rpmscanner/libraries/rpmscanner.py +++ b/repos/system_upgrade/common/actors/rpmscanner/libraries/rpmscanner.py @@ -66,7 +66,7 @@ def _get_package_repository_data_dnf(): def get_package_repository_data(): """ Return dictionary mapping package name with repository from which it was installed. Note: - There's no yum module for py3. The dnf module can be used only on RHEL 8, + There's no yum module for py3. The dnf module can be used only on RHEL 8+, on RHEL 7 there's a bug in dnf preventing us to do so: https://bugzilla.redhat.com/show_bug.cgi?id=1789840 """ diff --git a/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/actor.py b/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/actor.py index 2c57f0f965..580b727c3c 100644 --- a/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/actor.py +++ b/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/actor.py @@ -9,7 +9,7 @@ class ScanInstalledTargetKernelVersion(Actor): Scan for the version of the newly installed kernel This actor will query rpm for all kernel packages and reports the first - matching el8 kernel RPM. In case the RHEL Real Time has been detected on + matching target system kernel RPM. In case the RHEL Real Time has been detected on the original system, the kernel-rt rpm is searched. If the rpm is missing, fallback for standard kernel RPM. """ diff --git a/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/libraries/scankernel.py b/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/libraries/scankernel.py index 954f250cda..119e20a336 100644 --- a/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/libraries/scankernel.py +++ b/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/libraries/scankernel.py @@ -9,10 +9,12 @@ def _get_kernel_version(kernel_name): except CalledProcessError: return '' + target_major_version = api.current_actor().configuration.version.target.split('.')[0] + for kernel in kernels: # name-version-release - we want the last two fields only version = '-'.join(kernel.split('-')[-2:]) - if 'el8' in version: + if 'el{}'.format(target_major_version) in version: return version return '' @@ -31,7 +33,9 @@ def process(): return else: api.current_logger().warning( - 'The kernel-rt rpm from RHEL 8 has not been detected. Switching to non-preemptive kernel.') + 'The kernel-rt rpm from the target RHEL has not been detected. ' + 'Switching to non-preemptive kernel.' + ) # TODO: create report with instructions to install kernel-rt manually # - attach link to article if any # - this possibly happens just in case the repository with kernel-rt @@ -48,4 +52,4 @@ def process(): # behaviour in this case, but at least the let me log the error msg # api.current_logger().error('Cannot detect any kernel RPM') - # StopActorExecutionError('Cannot detect any RHEL 8 kernel RPM.') + # StopActorExecutionError('Cannot detect any target RHEL kernel RPM.') diff --git a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/constants.py b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/constants.py index 157fa6c611..74399124a7 100644 --- a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/constants.py +++ b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/constants.py @@ -1,5 +1,6 @@ import os + SCRATCH_DIR = os.getenv('LEAPP_CONTAINER_ROOT', '/var/lib/leapp/scratch') MOUNTS_DIR = os.path.join(SCRATCH_DIR, 'mounts') -TARGET_USERSPACE = '/var/lib/leapp/el8userspace' +TARGET_USERSPACE = '/var/lib/leapp/el{}userspace' diff --git a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py index b3d2d997db..e695bad754 100644 --- a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py +++ b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py @@ -103,7 +103,7 @@ def _update_files(copy_files): for message in api.consume(RequiredTargetUserspacePackages): self.packages.update(message.packages) - # Get the RHSM information (available repos, attached SKUs, etc.) of the source (RHEL 7) system + # Get the RHSM information (available repos, attached SKUs, etc.) of the source system self.rhsm_info = next(api.consume(RHSMInfo), None) self.rhui_info = next(api.consume(RHUIInfo), None) if not self.rhsm_info and not rhsm.skip_rhsm(): @@ -125,19 +125,22 @@ def prepare_target_userspace(context, userspace_dir, enabled_repos, packages): """ Implement the creation of the target userspace. """ + target_major_version = api.current_actor().configuration.version.target.split('.')[0] run(['rm', '-rf', userspace_dir]) _create_target_userspace_directories(userspace_dir) - with mounting.BindMount(source=userspace_dir, target=os.path.join(context.base_dir, 'el8target')): + with mounting.BindMount( + source=userspace_dir, target=os.path.join(context.base_dir, 'el{}target'.format(target_major_version)) + ): repos_opt = [['--enablerepo', repo] for repo in enabled_repos] repos_opt = list(itertools.chain(*repos_opt)) cmd = ['dnf', 'install', '-y', '--nogpgcheck', - '--setopt=module_platform_id=platform:el8', + '--setopt=module_platform_id=platform:el{}'.format(target_major_version), '--setopt=keepcache=1', '--releasever', api.current_actor().configuration.version.target, - '--installroot', '/el8target', + '--installroot', '/el{}target'.format(target_major_version), '--disablerepo', '*' ] + repos_opt + packages if config.is_verbose(): @@ -148,7 +151,7 @@ def prepare_target_userspace(context, userspace_dir, enabled_repos, packages): context.call(cmd, callback_raw=utils.logging_handler) except CalledProcessError as exc: raise StopActorExecutionError( - message='Unable to install RHEL 8 userspace packages.', + message='Unable to install RHEL {} userspace packages.'.format(target_major_version), details={'details': str(exc), 'stderr': exc.stderr} ) @@ -295,26 +298,27 @@ def _get_all_available_repoids(context): def _get_rhsm_available_repoids(context): + target_major_version = api.current_actor().configuration.version.target.split('.')[0] # FIXME: check that required repo IDs (baseos, appstream) # + or check that all required RHEL repo IDs are available. if rhsm.skip_rhsm(): return set() - # Get the RHSM repos available in the RHEL 8 container + # Get the RHSM repos available in the target RHEL container # TODO: very similar thing should happens for all other repofiles in container # repoids = rhsm.get_available_repo_ids(context) if not repoids or len(repoids) < 2: raise StopActorExecutionError( - message='Cannot find required basic RHEL 8 repositories.', + message='Cannot find required basic RHEL {} repositories.'.format(target_major_version), details={ 'hint': ('It is required to have RHEL repositories on the system' ' provided by the subscription-manager unless the --no-rhsm' ' options is specified. Possibly you' ' are missing a valid SKU for the target system or network' ' connection failed. Check whether your system is attached' - ' to a valid SKU providing RHEL 8 repositories.' + ' to a valid SKU providing RHEL {} repositories.' ' In case the Satellite is used, read the upgrade documentation' - ' to setup the satellite and the system properly.') + ' to setup the satellite and the system properly.'.format(target_major_version)) } ) return set(repoids) @@ -489,15 +493,20 @@ def _copy_files(context, files): context.copy_to(file_task.src, file_task.dst) +def _get_target_userspace(): + target_major_version = api.current_actor().configuration.version.target.split('.')[0] + return constants.TARGET_USERSPACE.format(target_major_version) + + def _create_target_userspace(context, packages, files, target_repoids): """Create the target userspace.""" - prepare_target_userspace(context, constants.TARGET_USERSPACE, target_repoids, list(packages)) - _prep_repository_access(context, constants.TARGET_USERSPACE) + prepare_target_userspace(context, _get_target_userspace(), target_repoids, list(packages)) + _prep_repository_access(context, _get_target_userspace()) _copy_files(context, files) - dnfplugin.install(constants.TARGET_USERSPACE) + dnfplugin.install(_get_target_userspace()) # and do not forget to set the rhsm into the container mode again - with mounting.NspawnActions(constants.TARGET_USERSPACE) as target_context: + with mounting.NspawnActions(_get_target_userspace()) as target_context: rhsm.set_container_mode(target_context) @@ -524,6 +533,6 @@ def perform(): api.produce(UsedTargetRepositories( repos=[UsedTargetRepository(repoid=repo) for repo in target_repoids])) api.produce(TargetUserSpaceInfo( - path=constants.TARGET_USERSPACE, + path=_get_target_userspace(), scratch=constants.SCRATCH_DIR, mounts=constants.MOUNTS_DIR)) diff --git a/repos/system_upgrade/common/libraries/config/version.py b/repos/system_upgrade/common/libraries/config/version.py index 271f985be4..191ba901fd 100644 --- a/repos/system_upgrade/common/libraries/config/version.py +++ b/repos/system_upgrade/common/libraries/config/version.py @@ -11,8 +11,63 @@ '<=': operator.le } -# Note: 'rhel-alt' is detected when on 'rhel' with kernel 4.x -SUPPORTED_VERSIONS = {'rhel': ['7.9'], 'rhel-alt': ['7.6'], 'rhel-saphana': ['7.7']} +_SUPPORTED_VERSIONS = { + # Note: 'rhel-alt' is detected when on 'rhel' with kernel 4.x + '7': {'rhel': ['7.9'], 'rhel-alt': ['7.6'], 'rhel-saphana': ['7.7']}, + '8': {'rhel': ['8.5', '8.6']}, +} + + +def get_source_major_version(): + return api.current_actor().configuration.version.source.split('.')[0] + + +def get_target_major_version(): + return api.current_actor().configuration.version.target.split('.')[0] + + +class _SupportedVersionsDict(dict): + """ + Class for _SUPPORTED_VERSIONS lazy evaluation until ipuworkflowconfig actor data + is ready. + """ + + def __init__(self): # pylint: disable=W0231 + self.data = {} + + def _feed_supported_versions(self): + major = get_source_major_version() + if major not in _SUPPORTED_VERSIONS.keys(): # pylint: disable=W1655 + raise KeyError('{} is not a supported source version of RHEL'.format(major)) + self.data = _SUPPORTED_VERSIONS[major] + + def __getitem__(self, key): + self._feed_supported_versions() + return self.data[key] + + def __iter__(self): + self._feed_supported_versions() + for d in self.data: + yield d + + def __repr__(self): + self._feed_supported_versions() + return repr(self.data) + + def __contains__(self, x): + self._feed_supported_versions() + return x in self.data + + def __len__(self): + self._feed_supported_versions() + return len(self.data) + + def __str__(self): + self._feed_supported_versions() + return str(self.data) + + +SUPPORTED_VERSIONS = _SupportedVersionsDict() def _version_to_tuple(version): diff --git a/repos/system_upgrade/common/libraries/dnfplugin.py b/repos/system_upgrade/common/libraries/dnfplugin.py index 719e916b76..f25f2cf091 100644 --- a/repos/system_upgrade/common/libraries/dnfplugin.py +++ b/repos/system_upgrade/common/libraries/dnfplugin.py @@ -6,10 +6,44 @@ from leapp.exceptions import StopActorExecutionError from leapp.libraries.common import guards, mounting, overlaygen, rhsm, utils +from leapp.libraries.common.config.version import get_target_major_version from leapp.libraries.stdlib import CalledProcessError, api, config + DNF_PLUGIN_NAME = 'rhel_upgrade.py' -DNF_PLUGIN_PATH = os.path.join('/lib/python3.6/site-packages/dnf-plugins', DNF_PLUGIN_NAME) + + +class _DnfPluginPathStr(str): + _PATHS = { + "8": os.path.join('/lib/python3.6/site-packages/dnf-plugins', DNF_PLUGIN_NAME), + "9": os.path.join('/lib/python3.9/site-packages/dnf-plugins', DNF_PLUGIN_NAME), + } + + def __init__(self): # noqa: W0231; pylint: disable=super-init-not-called + self.data = "" + + def _feed(self): + major = get_target_major_version() + if major not in _DnfPluginPathStr._PATHS.keys(): # pylint: disable=W1655 + raise KeyError('{} is not a supported target version of RHEL'.format(major)) + self.data = _DnfPluginPathStr._PATHS[major] + + def __str__(self): + self._feed() + return str(self.data) + + def __repr__(self): + self._feed() + return repr(self.data) + + def lstrip(self, chars=None): + self._feed() + return self.data.lstrip(chars) + + +# Deprecated +DNF_PLUGIN_PATH = _DnfPluginPathStr() + DNF_PLUGIN_DATA_NAME = 'dnf-plugin-data.txt' DNF_PLUGIN_DATA_PATH = os.path.join('/var/lib/leapp', DNF_PLUGIN_DATA_NAME) DNF_PLUGIN_DATA_LOG_PATH = os.path.join('/var/log/leapp', DNF_PLUGIN_DATA_NAME) @@ -50,7 +84,7 @@ def build_plugin_data(target_repoids, debug, test, tasks, on_aws): 'disable_repos': True, 'enable_repos': target_repoids, 'gpgcheck': False, - 'platform_id': 'platform:el8', + 'platform_id': 'platform:el{}'.format(get_target_major_version()), 'releasever': api.current_actor().configuration.version.target, 'installroot': '/installroot', 'test_flag': test @@ -175,7 +209,7 @@ def install_initramdisk_requirements(packages, target_userspace_info, used_repos 'install', '-y', '--nogpgcheck', - '--setopt=module_platform_id=platform:el8', + '--setopt=module_platform_id=platform:el{}'.format(get_target_major_version()), '--setopt=keepcache=1', '--releasever', api.current_actor().configuration.version.target, '--disablerepo', '*' diff --git a/repos/system_upgrade/common/libraries/rhui.py b/repos/system_upgrade/common/libraries/rhui.py index 94479594e9..45ef6bcff8 100644 --- a/repos/system_upgrade/common/libraries/rhui.py +++ b/repos/system_upgrade/common/libraries/rhui.py @@ -43,6 +43,7 @@ # when on AWS, we need also Python2 version of "Amazon-id" dnf plugin which is served by # "leapp-rhui-aws" rpm package (please note this package is not in any RH official repository # but only in "rhui-client-config-*" repo) +# IMPORTANT: Deprecated DNF_PLUGIN_PATH DNF_PLUGIN_PATH = '/usr/lib/python2.7/site-packages/dnf-plugins/' YUM_REPOS_PATH = '/etc/yum.repos.d' diff --git a/setup.cfg b/setup.cfg index 1b6c3daffd..d4bca3f6de 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,6 +6,7 @@ max-line-length = 119 # 'leapp.snactor.fixture.current_actor_libraries' imported but unused per-file-ignores = repos/system_upgrade/el7toel8/actors/*/tests/*.py:F811,F401 + repos/system_upgrade/common/actors/*/tests/*.py:F811,F401 application-import-names = leapp # check only for correct group type and abc sorting without group import-order-style = pep8