Skip to content

Commit

Permalink
Movement to system_upgrades/common - follow-up
Browse files Browse the repository at this point in the history
    - set static Key in checkosrelease report msg
    - test discovery fix
    - make SUPPORTED_VERSIONS and dynamic target release lazy evaluated
  • Loading branch information
Rezney authored and pirat89 committed Jun 25, 2021
1 parent 0eca81c commit 2206142
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 70 deletions.
44 changes: 32 additions & 12 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions repos/system_upgrade/common/actors/checkskipphase/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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),
])
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}

Expand All @@ -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:'
)


Expand Down Expand Up @@ -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."
),
)

Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
])
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''

Expand All @@ -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
Expand All @@ -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.')
Original file line number Diff line number Diff line change
@@ -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'
Loading

0 comments on commit 2206142

Please sign in to comment.