builder: use koji_build_id from ComposeStatus

Instead of getting the `koji_build_id` from the direct reply of
the compose request call, use the one returned in the compose
status.
The reason behind this is that composer was changed so that the
CGInitBuild call to koji is now being done by a worker and not
composer itself. This means that once the compose request call
returns, the build id is not yet known. In composer release 24,
the compose request call internally waits for the worker that
does the CGInitBuild API call, but that will be changed, and
the koji_build_id will then not be returned from the compose
request API call anymore. This prepares for that. The tests are
also adapted to simulate the new behavior.

NB: this makes composer 24 a dependency, since the build id is
taken from the ComposeStatus, which was only added there.
This commit is contained in:
Christian Kellner 2020-11-17 12:16:37 +01:00 committed by Tom Gundersen
parent 3adccb716c
commit 68309e4b5a
2 changed files with 24 additions and 12 deletions

View file

@ -135,22 +135,24 @@ class ComposeStatus:
PENDING = "pending"
REGISTERING = "registering"
def __init__(self, status: str, images: List, koji_task_id: str):
def __init__(self, status: str, images: List, task_id: int, build_id):
self.status = status
self.images = images
self.koji_task_id = koji_task_id
self.koji_task_id = task_id
self.koji_build_id = build_id
@classmethod
def from_dict(cls, data: Dict):
status = data["status"].lower()
koji_task_id = data["koji_task_id"]
koji_build_id = data.get("koji_build_id")
images = [
ImageStatus(s["status"].lower()) for s in data["image_statuses"]
]
return cls(status, images, koji_task_id)
return cls(status, images, koji_task_id, koji_build_id)
def as_dict(self):
return {
data = {
"status": self.status,
"koji_task_id": self.koji_task_id,
"image_statuses": [
@ -158,6 +160,11 @@ class ComposeStatus:
]
}
if self.koji_build_id is not None:
data["koji_build_id"] = self.koji_build_id
return data
@property
def is_finished(self):
if self.is_success:
@ -209,8 +216,7 @@ class Client:
raise koji.GenericError(msg) from None
ps = res.json()
compose_id, koji_build_id = ps["id"], ps["koji_build_id"]
return compose_id, koji_build_id
return ps["id"] # the compose id
def compose_status(self, compose_id: str):
url = urllib.parse.urljoin(self.url, f"compose/{compose_id}")
@ -402,8 +408,8 @@ class OSBuildImage(BaseTaskHandler):
self.upload_json(request.as_dict(), "compose-request")
cid, bid = client.compose_create(request)
self.logger.info("Compose id: %s, Koji build id: %s", cid, bid)
cid = client.compose_create(request)
self.logger.info("Compose id: %s", cid)
self.logger.debug("Waiting for comose to finish")
status = client.wait_for_compose(cid, callback=self.on_status_update)
@ -416,6 +422,9 @@ class OSBuildImage(BaseTaskHandler):
if not status.is_success:
raise koji.BuildError(f"Compose failed (id: {cid})")
# Successful compose, must have a build id associated
bid = status.koji_build_id
# Build was successful, tag it
if not opts.get('skip_tag'):
self.tag_build(target_info["dest_tag"], bid)
@ -442,6 +451,8 @@ RED = "\033[31m"
def show_compose(cs):
print(f"status: {BOLD}{cs.status}{RESET}")
print("koji task: " + str(cs.koji_task_id))
if cs.koji_build_id is not None:
print("koji build: " + str(cs.koji_build_id))
print("images: ")
for image in cs.images:
print(" " + str(image))
@ -459,9 +470,9 @@ def compose_cmd(client: Client, args):
kojidata = ComposeRequest.Koji(args.koji, 0)
request = ComposeRequest(nvr, args.distro, images, kojidata)
cid, bid = client.compose_create(request)
cid = client.compose_create(request)
print(f"Compose: {cid} [koji build id: {bid}]")
print(f"Compose: {cid}")
while True:
status = client.compose_status(cid)
print(f"status: {status.status: <10}\r", end="")

View file

@ -61,11 +61,11 @@ class MockComposer:
compose_id = str(uuid.uuid4())
build_id = self.next_build_id()
compose = {
"id": compose_id,
"koji_build_id": build_id,
"id": compose_id
}
self.composes[compose_id] = {
"build_id": build_id,
"request": js,
"result": compose,
"status": self.status,
@ -98,6 +98,7 @@ class MockComposer:
result = {
"status": compose["status"],
"koji_task_id": compose["request"]["koji"]["task_id"],
"koji_build_id": compose["build_id"],
"image_statuses": [
{"status": compose["status"]} for _ in ireqs
]