Skip to content

Commit

Permalink
correctly obtain failed koji build logs
Browse files Browse the repository at this point in the history
if a koji build fails, sadly this doesn't do anything:

    koji_logs = self.client.getBuildLogs(self.build_or_task_id)

koji api docs:

> This method will only return logs for builds that are complete.
> If a build is in progress, failed, or canceled, you must look at the
> build's task logs instead (see listTaskOutput).

Instead, we need to manually traverse the task hierarchy and select the
right buildArch task, which this commit implements.

Signed-off-by: Tomas Tomecek <[email protected]>
  • Loading branch information
TomasTomecek authored and jpodivin committed Jan 24, 2024
1 parent 5e9401b commit 7b72942
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions backend/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,24 @@ def _is_build_id(self) -> bool:
return False

def _fetch_build_logs_from_build_id(self) -> list[dict[str, str]]:
koji_logs = self.client.getBuildLogs(self.build_or_task_id)
logs = []
for log in koji_logs:
if log["dir"] != self.arch:
continue

if log["name"] not in self.logs_to_look_for:
continue

url = "{}/{}".format(self.koji_url, log["path"])
response = requests.get(url)
response.raise_for_status()
logs.append(
{
"name": log["name"],
"content": response.text,
}
)
"""
Obtain build logs from a failed build by traversing
through the task hierarchy to the buildArch task's logs
return logs
Koji's method getBuildLogs sadly only works with successful builds.
"""
koji_build = self.client.getBuild(self.build_or_task_id)
root_task_id = koji_build['task_id']
# the response of getTaskDescendents:
# {'112162296': [{'arch': 'noarch', 'awaited': False...
task_descendants = self.client.getTaskDescendents(root_task_id)[str(root_task_id)]
for task_info in task_descendants:
if task_info['arch'] == self.arch and task_info['method'] == 'buildArch' \
and task_info['state'] == 5:
# this is the one and only ring!
self.build_or_task_id = task_info['id']
return self._fetch_task_logs_from_task_id()
return []

@cached_property
def task_info(self) -> dict:
Expand Down

0 comments on commit 7b72942

Please sign in to comment.