Skip to content

Commit

Permalink
Always search for completed builds
Browse files Browse the repository at this point in the history
  • Loading branch information
locriandev committed Jan 17, 2025
1 parent 5730f75 commit f19fd05
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions doozer/doozerlib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ async def get_pinned_konflux_build(self, el_target: int):
return await self.runtime.konflux_db.get_build_record_by_nvr(is_nvr, strict=True)

async def get_latest_konflux_build(self, assembly: Optional[str] = None,
outcome: KonfluxBuildOutcome = KonfluxBuildOutcome.SUCCESS,
el_target: Optional[int] = None,
honor_is: bool = True,
completed_before: Optional[datetime] = None,
Expand All @@ -449,7 +448,6 @@ async def get_latest_konflux_build(self, assembly: Optional[str] = None,
:param assembly: A non-default assembly name to search relative to. If not specified, runtime.assembly
will be used. If runtime.assembly is also None, the search will return true latest.
If the assembly parameter is set to '', this search will also return true latest.
:param outcome: one in KonfluxBuildOutcome[FAILURE, SUCCESS, PENDING]
:param el_target: specify 'el7', 'el8', etc.
For an RPM, leave as None if you want the true latest.
For an image, leaving as none will default to the RHEL version in the branch
Expand All @@ -464,16 +462,13 @@ async def get_latest_konflux_build(self, assembly: Optional[str] = None,

# Is the component pinned in config?
if honor_is and self.config['is']:
if outcome != KonfluxBuildOutcome.SUCCESS:
# If this component is defined by 'is', history failures, etc, do not matter.
return None
return await self.get_pinned_konflux_build(el_target=el_target)

# If it's not pinned, fetch the build from the Konflux DB
base_search_params = {
'name': self.distgit_key if self.meta_type == 'image' else self.rpm_name,
'group': self.runtime.group,
'outcome': outcome,
'outcome': KonfluxBuildOutcome.SUCCESS,
'completed_before': completed_before,
'engine': self.runtime.build_system,
'extra_patterns': extra_patterns,
Expand Down Expand Up @@ -521,8 +516,8 @@ async def get_latest_brew_build_async(self, **kwargs):
return await asyncio.to_thread(self.get_latest_brew_build, **kwargs)

def get_latest_brew_build(self, default: Optional[Any] = -1, assembly: Optional[str] = None, extra_pattern: str = '*',
build_state: BuildStates = BuildStates.COMPLETE, component_name: Optional[str] = None,
el_target: Optional[Union[str, int]] = None, honor_is: bool = True, complete_before_event: Optional[int] = None):
component_name: Optional[str] = None, el_target: Optional[Union[str, int]] = None,
honor_is: bool = True, complete_before_event: Optional[int] = None):
"""
:param default: A value to return if no latest is found (if not specified, an exception will be thrown)
:param assembly: A non-default assembly name to search relative to. If not specified, runtime.assembly
Expand All @@ -532,7 +527,6 @@ def get_latest_brew_build(self, default: Optional[Any] = -1, assembly: Optional[
build's release field. Pattern must match release timestamp and components
like p? and git commit (up to, but not including ".assembly.<name>" release
component). e.g. "*.g<commit>.* or '*.p1.*'
:param build_state: 0=BUILDING, 1=COMPLETE, 2=DELETED, 3=FAILED, 4=CANCELED
:param component_name: If not specified, looks up builds for self component.
:param el_target: In the case of an RPM, which can build for multiple targets, you can specify
'7' for el7, '8' for el8, etc. You can also pass in a brew target that
Expand Down Expand Up @@ -594,8 +588,8 @@ def get_latest_brew_build(self, default: Optional[Any] = -1, assembly: Optional[
list_builds_kwargs['completeBefore'] = complete_before_ts

def default_return():
msg = (f"No builds detected for using prefix: '{pattern_prefix}', extra_pattern: '{extra_pattern}', "
f"assembly: '{assembly}', build_state: '{build_state.name}', el_ver: '{el_ver}'")
msg = (f"No completed builds detected for using prefix: '{pattern_prefix}', extra_pattern: '{extra_pattern}', "
f"assembly: '{assembly}', el_ver: '{el_ver}'")
if default != -1:
self.logger.info(msg)
return default
Expand All @@ -611,7 +605,7 @@ def latest_build_list(assembly_suffix):
pattern = f"{pattern_prefix}{extra_pattern}{assembly_suffix}{el_suffix}"

builds = koji_api.listBuilds(packageID=package_id,
state=None if build_state is None else build_state.value,
state=BuildStates.COMPLETE.value,
pattern=pattern,
queryOpts={'limit': 1, 'order': '-creation_event_id'},
**list_builds_kwargs)
Expand All @@ -621,7 +615,7 @@ def latest_build_list(assembly_suffix):
# "assembly.howdy'.
refined = [b for b in builds if b['nvr'].endswith(assembly_suffix) or f'{assembly_suffix}.' in b['nvr']]

if refined and build_state == BuildStates.COMPLETE:
if refined:
# A final sanity check to see if the build is tagged with something we
# respect. There is a chance that a human may untag a build. There
# is no standard practice at present in which they should (they should just trigger
Expand Down Expand Up @@ -649,10 +643,6 @@ def latest_build_list(assembly_suffix):
return refined

if honor_is and self.config['is']:
if build_state != BuildStates.COMPLETE:
# If this component is defined by 'is', history failures, etc, do not matter.
return default_return()

# under 'is' for RPMs, we expect 'el7' and/or 'el8', etc. For images, just 'nvr'.
isd = self.config['is']
if self.meta_type == 'rpm':
Expand Down

0 comments on commit f19fd05

Please sign in to comment.