Cloud API: fix image_status.status value for running compose

Previously, the Cloud API endpoint `/v1/compose/{id}` return value's
`image_status.status` for a running worker job was "running", which didn't
comply with the Cloud API specification. Equivalents allowed by the API
specification are "building", "uploading" or "registering".

As a result, the Image Builder API also does not comply in this regard
to its specification, because it currently just copies the status value
string returned by osbuild-composer.

Define the `image_status.status` as a reusable type in the Cloud API
specification. This forces openapi to generate an explicit type for it,
which can be then explicitly used in the code, instead of plain strings.

Return "building", instead of "running"  for running compose.

Modify api integration test to check for all valid `image_status.status`
values for a compose.

Add News entry explaining this change.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2021-03-19 18:05:22 +01:00 committed by Tomas Hozza
parent 6804fe456b
commit 4a47ad36af
5 changed files with 101 additions and 70 deletions

View file

@ -21,13 +21,6 @@ import (
"github.com/osbuild/osbuild-composer/internal/worker"
)
const (
StatusPending = "pending"
StatusRunning = "running"
StatusSuccess = "success"
StatusFailure = "failure"
)
// Server represents the state of the cloud Server
type Server struct {
workers *worker.Server
@ -373,24 +366,26 @@ func (server *Server) ComposeStatus(w http.ResponseWriter, r *http.Request, id s
}
}
func composeStatusFromJobStatus(js *worker.JobStatus, result *worker.OSBuildJobResult) string {
func composeStatusFromJobStatus(js *worker.JobStatus, result *worker.OSBuildJobResult) ImageStatusValue {
if js.Canceled {
return StatusFailure
return ImageStatusValue_failure
}
if js.Started.IsZero() {
return StatusPending
return ImageStatusValue_pending
}
if js.Finished.IsZero() {
return StatusRunning
// TODO: handle also ImageStatusValue_uploading
// TODO: handle also ImageStatusValue_registering
return ImageStatusValue_building
}
if result.Success {
return StatusSuccess
return ImageStatusValue_success
}
return StatusFailure
return ImageStatusValue_failure
}
// GetOpenapiJson handles a /openapi.json GET request