Skip to content

Commit

Permalink
GPG check: do not raise an error when TargetUserSpaceInfo is missing
Browse files Browse the repository at this point in the history
Previously, if the upgrade has been inhibited during
    TargetTransactionFactsCollectionPhase
usually because we could not create (for whatever reason) the target
userspace container, the actor checking rpm gpg keys failed with
the `Could not check for valid GPG keys` error. This has confused
many users as they couldn't know that this is impacted by the
problem described in an inhibitor that is below this error.

As it's for sure that the upgrade cannot continue when the target user
space container has not been created (the TargetUserSpaceInfo msg
is missing), we consider it safe to stop the gpg check here silently
just with a warning msg instead of raising the error - as this check
is important only in case we could actually upgrade.

All other possible raised errors are presereved.

jira: https://issues.redhat.com/browse/RHEL-30573

Signed-off-by: Petr Stodulka <[email protected]>
Signed-off-by: Jakub Jelen <[email protected]>
  • Loading branch information
pirat89 authored and Rezney committed Jul 22, 2024
1 parent 7cd469b commit caff3ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from six.moves import urllib

from leapp import reporting
from leapp.exceptions import StopActorExecutionError
from leapp.exceptions import StopActorExecution, StopActorExecutionError
from leapp.libraries.common.config.version import get_target_major_version
from leapp.libraries.common.gpg import get_gpg_fp_from_file, get_path_to_gpg_certs, is_nogpgcheck_set
from leapp.libraries.stdlib import api
Expand Down Expand Up @@ -61,6 +61,15 @@ def _get_abs_file_path(target_userspace, file_url):


def _consume_data():
try:
target_userspace = next(api.consume(TargetUserSpaceInfo))
except StopIteration:
api.current_logger().warning(
'Missing TargetUserSpaceInfo data. The upgrade cannot continue'
' without this data, so skipping any other actions.'
)
raise StopActorExecution()

try:
used_target_repos = next(api.consume(UsedTargetRepositories)).repos
except StopIteration:
Expand All @@ -83,12 +92,6 @@ def _consume_data():
raise StopActorExecutionError(
'Could not check for valid GPG keys', details={'details': 'No TrustedGpgKeys facts'}
)
try:
target_userspace = next(api.consume(TargetUserSpaceInfo))
except StopIteration:
raise StopActorExecutionError(
'Could not check for valid GPG keys', details={'details': 'No TargetUserSpaceInfo facts'}
)

return used_target_repos, target_repos, trusted_gpg_keys, target_userspace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from six.moves.urllib.error import URLError

from leapp import reporting
from leapp.exceptions import StopActorExecutionError
from leapp.exceptions import StopActorExecution, StopActorExecutionError
from leapp.libraries.actor.missinggpgkey import process
from leapp.libraries.common.gpg import get_pubkeys_from_rpms
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, logger_mocked, produce_mocked
Expand Down Expand Up @@ -191,12 +191,13 @@ def test_perform_missing_facts(monkeypatch, msgs):
monkeypatch.setattr(api, 'current_logger', logger_mocked())
# TODO: the gpg call should be mocked

with pytest.raises(StopActorExecutionError):
with pytest.raises(StopActorExecution):
process()
# nothing produced
assert api.produce.called == 0
# not skipped by --nogpgcheck
assert not api.current_logger.warnmsg
assert len(api.current_logger.warnmsg) == 1
assert "Missing TargetUserSpaceInfo data" in api.current_logger.warnmsg[0]


@suppress_deprecation(TMPTargetRepositoriesFacts)
Expand Down Expand Up @@ -280,7 +281,7 @@ def test_perform_missing_some_repo_facts(monkeypatch):
monkeypatch.setattr(reporting, 'create_report', create_report_mocked())
monkeypatch.setattr('leapp.libraries.common.gpg._gpg_show_keys', _gpg_show_keys_mocked)

with pytest.raises(StopActorExecutionError):
with pytest.raises(StopActorExecution):
process()
assert api.produce.called == 0
assert reporting.create_report.called == 0
Expand Down

0 comments on commit caff3ac

Please sign in to comment.