Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Fix "task failed, build succeeded" situation in osbs2
Browse files Browse the repository at this point in the history
It can happen that a brew task fails, but brew considers the build to be
good. This commit moves the calculation of the resulting nvr forward,
and upon task failure, asks brew if the nvr has been built
successfully.
  • Loading branch information
joepvd committed Dec 5, 2022
1 parent 2f9162a commit 5fbedc3
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions doozerlib/osbs2_builder.py
Expand Up @@ -60,6 +60,7 @@ async def build(self, image: "image.ImageMetadata", profile: Dict, retries: int

error = None
message = None
nvr = f"{image.get_component_name()}-{dg.org_version}-{dg.org_release}"
for attempt in range(retries):
logger.info("Build attempt %s/%s", attempt + 1, retries)
try:
Expand All @@ -83,22 +84,12 @@ async def build(self, image: "image.ImageMetadata", profile: Dict, retries: int
logger.warning("Error downloading build logs from brew for task %s: %s", task_id, logs_err)

if error:
# Looking for error message like the following to conclude the image has already been built:
# BuildError: Build for openshift-enterprise-base-v3.7.0-0.117.0.0 already exists, id 588961
# Note it is possible that a Brew task fails
# with a build record left (https://issues.redhat.com/browse/ART-1723).
# Didn't find a variable in the context to get the Brew NVR or ID.
# Extracting the build ID from the error message.
# Hope the error message format will not change.
match = re.search(r"already exists, id (\d+)", error)
if match:
build_id = int(match[1])
builds = brew.get_build_objects([build_id], koji_api)
if builds and builds[0] and builds[0].get('state') == 1: # State 1 means complete.
build_info = builds[0]
build_url = f"{BREWWEB_URL}/buildinfo?buildID={build_info['id']}"
logger.info("Image %s already built against this dist-git commit (or version-release tag): %s", build_info["nvr"], build_url)
error = None # Treat as a success
# Error in task does not necessarily mean error in build. Look if the build is successful
build_info = koji_api.getBuild(nvr)
if build_info and build_info.get('state') == 1: # State 1 means complete.
build_url = f"{BREWWEB_URL}/buildinfo?buildID={build_info['id']}"
logger.info("Image %s already built against this dist-git commit (or version-release tag): %s", build_info["nvr"], build_url)
error = None # Treat as a success

except Exception as err:
error = f"Error building image {image.name}: {str(err)}: {traceback.format_exc()}"
Expand All @@ -112,7 +103,7 @@ async def build(self, image: "image.ImageMetadata", profile: Dict, retries: int
"name": image.get_component_name(),
"version": dg.org_version,
"release": dg.org_release,
"nvr": f"{image.get_component_name()}-{dg.org_version}-{dg.org_release}"
"nvr": nvr,
}
build_url = f"{BREWWEB_URL}/buildinfo?buildID={build_info['id']}"
elif not build_info and not self.scratch:
Expand Down

0 comments on commit 5fbedc3

Please sign in to comment.