Skip to content

Commit

Permalink
Merge pull request #166 from locriandev/improve-brew-list
Browse files Browse the repository at this point in the history
Improve brew list
  • Loading branch information
locriandev authored Jan 8, 2024
2 parents b8b5cdb + 75af0f9 commit fa62ef0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
26 changes: 18 additions & 8 deletions artbotlib/brew_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,14 @@ def _index_rpms_in_images(image_nvrs, rpms_search, rpms_for_image, rpms_seen):
rpms_for_image.setdefault(image_nvr, set()).add(rpm_nvr)


def _index_rpms_in_rhcos(rpm_nvrs, rpms_search, rpms_for_image, rpms_seen):
def _index_rpms_in_rhcos(rhcos_build_rpms, rpms_search, rpms_for_image, rpms_seen):
rhcos_build = rhcos_build_rpms.get('build-id')
rpm_nvrs = rhcos_build_rpms.get('rpms', [])
for rpm_nvr in rpm_nvrs:
name = rpm_nvr.rsplit("-", 2)[0].lower()
if name in rpms_search:
rpms_seen.add(name)
rpms_for_image.setdefault("RHCOS", set()).add(rpm_nvr)
rpms_for_image.setdefault(f"RHCOS {rhcos_build}", set()).add(rpm_nvr)


def _find_rpms_in_packages(koji_api, name_list, major_minor):
Expand Down Expand Up @@ -376,25 +378,33 @@ def _find_rpms_in_packages(koji_api, name_list, major_minor):
return rpms_for_package


def _find_rhcos_build_rpms(so, major_minor, arch="x86_64", build_id=None):
# returns a set of RPMs used in the specified or most recent build for release major_minor
def _find_rhcos_build_rpms(so, major_minor, arch="x86_64", build_id=None) -> dict:
"""
Returns a dict that includes following keys:
'build-id': the ID of the RHCOS build, e.g. 416.92.202401041100-0
'rpms': set of RPMs used in the specified or most recent build for release major_minor
"""

try:
rhcos_build_info = RHCOSBuildInfo(major_minor)
build_id = build_id or rhcos_build_info.latest_build_id(arch)
if not build_id:
return set()
return dict()
metadata = rhcos_build_info.build_metadata(build_id, arch)
if metadata == {}:
return set()
return dict()
rpms = metadata["rpmostree.rpmdb.pkglist"]
logger.info('Found %s rpms', len(rpms))
return set(f"{n}-{v}-{r}" for n, e, v, r, a in rpms)
return {
'build-id': build_id,
'rpms': set(f"{n}-{v}-{r}" for n, e, v, r, a in rpms)
}

except Exception as ex:
logger.error('Encountered error looking up latest RHCOS build RPMs in %s: %s', major_minor, ex)
so.say("Encountered error looking up the latest RHCOS build RPMs.")
so.monitoring_say(f"Encountered error looking up the latest RHCOS build RPMs: {ex}")
return set()
return dict()


def _get_raw_group_config(group):
Expand Down
24 changes: 13 additions & 11 deletions tests/test_brew_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_rhcos_latest_build_id(mock_urlopen, content, expected):
@patch('urllib.request.urlopen')
@pytest.mark.parametrize("content, expected",
[
[b'{ }', set()],
[b'{ }', dict()],
[
b'''{
"rpmostree.rpmdb.pkglist" : [
Expand All @@ -104,7 +104,8 @@ def test_rhcos_latest_build_id(mock_urlopen, content, expected):
]
]
}''',
{"NetworkManager-1.20.0-5.el8_1", "NetworkManager-libnm-1.20.0-5.el8_1"},
{"build-id": "dummy",
"rpms": {"NetworkManager-1.20.0-5.el8_1", "NetworkManager-libnm-1.20.0-5.el8_1"}}
],
]
)
Expand Down Expand Up @@ -144,20 +145,21 @@ def test_find_rpms_in_packages(pkg_name, tag1_builds, tag2_builds, tag1_rpms, ta
assert expected == brew_list._find_rpms_in_packages(koji_api, [pkg_name], "4.3")


@pytest.mark.parametrize("rpm_nvrs, rpms_search, expected_rpms4img, expected_rpms",
@pytest.mark.parametrize("rhcos_rpms, rpms_search, expected_rpms4img, expected_rpms",
[
(
["spam-1.0-1.el8", "bacon-eggs-2.3-4.el7"], # rpms from rhcos build
{"build-id": "dummy",
"rpms": ["spam-1.0-1.el8", "bacon-eggs-2.3-4.el7"]}, # rpms from rhcos build}
{"spam", "bacon"}, # rpms we're looking for
dict(RHCOS={"spam-1.0-1.el8"}), # filtered first by second
{"RHCOS dummy": {"spam-1.0-1.el8"}}, # filtered first by second
{"spam"}, # rpms we saw
),
]
)
def test_index_rpms_in_rhcos(rpm_nvrs, rpms_search, expected_rpms4img, expected_rpms):
def test_index_rpms_in_rhcos(rhcos_rpms, rpms_search, expected_rpms4img, expected_rpms):
rpms_for_image = {}
rpms_seen = set()
brew_list._index_rpms_in_rhcos(rpm_nvrs, rpms_search, rpms_for_image, rpms_seen)
brew_list._index_rpms_in_rhcos(rhcos_rpms, rpms_search, rpms_for_image, rpms_seen)
assert expected_rpms4img == rpms_for_image
assert expected_rpms == rpms_seen

Expand Down Expand Up @@ -239,7 +241,7 @@ def test_list_uses_of_rpms_unknown_packages(so):
dict(spam=["spam-eggs", "spam-sausage"], eggs=["eggs"]),
# rpms built for pkgs (for a package search)
dict(imgspam=["sausage-4.0-1.el8.noarch"]), # images containing rpms
["sausage-4.0-1.el8.noarch"], # rpms in rhcos
{"build-id": "dummy", "rpms": {"sausage-4.0-1.el8.noarch"}}, # rpms in rhcos
["nothing in 4.0 uses that"],
# should see this (none of the search rpms were present)
["sausage"], # should not see
Expand All @@ -249,7 +251,7 @@ def test_list_uses_of_rpms_unknown_packages(so):
dict(spam=["spam-eggs", "spam-sausage"], bacon=["bacon"]),
# rpms built for pkgs (for a package search)
dict(imgspam=["spam-eggs-4.0-1.el8.noarch"]), # images containing rpms
["sausage-4.0-1.el8.noarch"], # rpms in rhcos
{"build-id": "dummy", "rpms": {"sausage-4.0-1.el8.noarch"}}, # rpms in rhcos
[ # should see
"Could not find package(s) ['eggs'] in brew",
"package spam includes rpm(s): {'spam-eggs'}",
Expand All @@ -261,8 +263,8 @@ def test_list_uses_of_rpms_unknown_packages(so):
"spam,eggs", # names the user is searching for
None, # not a pkg search, names are rpm names
dict(imgspam=["spam-4.0-1.el8.noarch"]), # images containing rpms
["eggs-4.0-1.el8", "baked-beans-4-1.el8"], # rpms in rhcos
["imgspam uses {'spam-4.0-1.el8'}", "RHCOS uses {'eggs-4.0-1.el8'}"],
{"build-id": "dummy", "rpms": {"eggs-4.0-1.el8", "baked-beans-4-1.el8"}}, # rpms in rhcos
["imgspam uses {'spam-4.0-1.el8'}", "RHCOS dummy uses {'eggs-4.0-1.el8'}"],
# should see these
["baked-beans"], # should not see
),
Expand Down

0 comments on commit fa62ef0

Please sign in to comment.