Don't reduce infomation uploaded in compose-status.json
Previously, the image status in the compose status uploaded to the koji build was represented as a single string describing the overall status. All information related to the image upload or error details were thrown away. Refactor `ImageStatus` to contain all the information about the image, its upload targets and potential errors, as they are returned by composer. This will improve the experience when debugging compose failures. In addition, including all the data will be important once images will be uploaded directly to the cloud, because it will contain information to locate the image in the cloud environment.
This commit is contained in:
parent
21a947d64f
commit
dd8233e8b7
1 changed files with 43 additions and 10 deletions
|
|
@ -16,7 +16,6 @@ alone client for composer's API.
|
||||||
|
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import enum
|
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -184,13 +183,47 @@ class ComposeRequest:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
class ImageStatus(enum.Enum):
|
class ComposeStatusError:
|
||||||
SUCCESS = "success"
|
def __init__(self, error_id: int, reason: str, details: Optional[Dict]):
|
||||||
FAILURE = "failure"
|
self.error_id = error_id
|
||||||
PENDING = "pending"
|
self.reason = reason
|
||||||
BUILDING = "building"
|
self.details = details
|
||||||
UPLOADING = "uploading"
|
|
||||||
REGISTERING = 'registering'
|
def as_dict(self):
|
||||||
|
data = {
|
||||||
|
"id": self.error_id,
|
||||||
|
"reason": self.reason
|
||||||
|
}
|
||||||
|
if self.details:
|
||||||
|
data["details"] = self.details
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class ImageStatus:
|
||||||
|
def __init__(self, status: str, upload_status: Optional[Dict], error: Optional[ComposeStatusError]) -> None:
|
||||||
|
self.status = status
|
||||||
|
self.upload_status = upload_status
|
||||||
|
self.error = error
|
||||||
|
|
||||||
|
def as_dict(self) -> Dict:
|
||||||
|
data = {
|
||||||
|
"status": self.status
|
||||||
|
}
|
||||||
|
if self.upload_status:
|
||||||
|
data["upload_status"] = self.upload_status
|
||||||
|
if self.error:
|
||||||
|
data["error"] = self.error.as_dict()
|
||||||
|
return data
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data: Dict) -> "ImageStatus":
|
||||||
|
status = data["status"]
|
||||||
|
upload_status = data.get("upload_status")
|
||||||
|
error = data.get("error")
|
||||||
|
if error:
|
||||||
|
error_id = error.pop("id")
|
||||||
|
error = ComposeStatusError(error_id=error_id, **error)
|
||||||
|
return cls(status, upload_status, error)
|
||||||
|
|
||||||
|
|
||||||
class ComposeStatus:
|
class ComposeStatus:
|
||||||
|
|
@ -212,7 +245,7 @@ class ComposeStatus:
|
||||||
koji_task_id = koji_status.get("task_id")
|
koji_task_id = koji_status.get("task_id")
|
||||||
koji_build_id = koji_status.get("build_id")
|
koji_build_id = koji_status.get("build_id")
|
||||||
images = [
|
images = [
|
||||||
ImageStatus(s["status"].lower()) for s in data["image_statuses"]
|
ImageStatus.from_dict(s) for s in data["image_statuses"]
|
||||||
]
|
]
|
||||||
return cls(status, images, koji_task_id, koji_build_id)
|
return cls(status, images, koji_task_id, koji_build_id)
|
||||||
|
|
||||||
|
|
@ -221,7 +254,7 @@ class ComposeStatus:
|
||||||
"status": self.status,
|
"status": self.status,
|
||||||
"koji_task_id": self.koji_task_id,
|
"koji_task_id": self.koji_task_id,
|
||||||
"image_statuses": [
|
"image_statuses": [
|
||||||
{"status": status.value} for status in self.images
|
img.as_dict() for img in self.images
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue