Skip to content

Commit

Permalink
properly scope try/except when loading obsoleted keys
Browse files Browse the repository at this point in the history
We want to load all possible keys, even *after* a KeyError happenend

Fixes: 7e0fb44
  • Loading branch information
evgeni committed Aug 23, 2024
1 parent 7e0fb44 commit 5daf43f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def _get_obsolete_keys():
distribution = api.current_actor().configuration.os_release.release_id
obsoleted_keys_map = get_distribution_data(distribution).get('obsoleted-keys', {})
keys = []
try:
for version in range(7, int(get_target_major_version()) + 1):
for version in range(7, int(get_target_major_version()) + 1):
try:
for key in obsoleted_keys_map[str(version)]:
name, version, release = key.rsplit("-", 2)
if has_package(InstalledRPM, name, version=version, release=release):
keys.append(key)
except KeyError:
pass
except KeyError:
pass

return keys

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,46 @@ def get_target_major_version_mocked():
assert set(keys) == set(expected)


@pytest.mark.parametrize(
"version, data, expected",
[
(10, {"8": ["gpg-pubkey-888-abc"], "10": ["gpg-pubkey-10-10"]}, ["gpg-pubkey-888-abc", "gpg-pubkey-10-10"]),
(9, {"8": ["gpg-pubkey-888-abc"], "9": ["gpg-pubkey-999-def"]}, ["gpg-pubkey-999-def", "gpg-pubkey-888-abc"]),
(8, {"8": ["gpg-pubkey-888-abc"], "9": ["gpg-pubkey-999-def"]}, ["gpg-pubkey-888-abc"])
]
)
def test_get_obsolete_keys_incomplete_data(monkeypatch, version, data, expected):
def get_target_major_version_mocked():
return version

def get_distribution_data_mocked(_distro):
return {'obsoleted-keys': data}

def has_package_mocked(*args, **kwargs):
return True

monkeypatch.setattr(
removeobsoleterpmgpgkeys,
"get_target_major_version",
get_target_major_version_mocked,
)

monkeypatch.setattr(
removeobsoleterpmgpgkeys,
"get_distribution_data",
get_distribution_data_mocked,
)

monkeypatch.setattr(
removeobsoleterpmgpgkeys,
"has_package",
has_package_mocked,
)

keys = removeobsoleterpmgpgkeys._get_obsolete_keys()
assert set(keys) == set(expected)


@pytest.mark.parametrize(
"keys, should_register",
[
Expand Down

0 comments on commit 5daf43f

Please sign in to comment.