diff --git a/internal/cloudapi/openapi.yml b/internal/cloudapi/openapi.yml index e8103cb16..8a08678ed 100644 --- a/internal/cloudapi/openapi.yml +++ b/internal/cloudapi/openapi.yml @@ -69,7 +69,7 @@ components: properties: status: type: string - enum: ['success', 'failure', 'pending'] + enum: ['success', 'failure', 'pending', 'running'] example: 'success' image_statuses: type: array diff --git a/internal/cloudapi/server.go b/internal/cloudapi/server.go index 888172b95..680931267 100644 --- a/internal/cloudapi/server.go +++ b/internal/cloudapi/server.go @@ -17,6 +17,13 @@ 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 @@ -212,10 +219,10 @@ func (server *Server) ComposeStatus(w http.ResponseWriter, r *http.Request, id s } response := ComposeStatus{ - Status: status.State.ToString(), // TODO: map the status correctly + Status: composeStatusFromJobStatus(status), ImageStatuses: &[]ImageStatus{ { - Status: status.State.ToString(), // TODO: map the status correctly + Status: composeStatusFromJobStatus(status), }, }, } @@ -225,3 +232,23 @@ func (server *Server) ComposeStatus(w http.ResponseWriter, r *http.Request, id s panic("Failed to write response") } } + +func composeStatusFromJobStatus(js *worker.JobStatus) string { + if js.Canceled { + return StatusFailure + } + + if js.Started.IsZero() { + return StatusPending + } + + if js.Finished.IsZero() { + return StatusRunning + } + + if js.Result.OSBuildOutput != nil && js.Result.OSBuildOutput.Success { + return StatusSuccess + } + + return StatusFailure +} diff --git a/test/cases/api.sh b/test/cases/api.sh index 28c8971a7..d4ac9371f 100644 --- a/test/cases/api.sh +++ b/test/cases/api.sh @@ -143,8 +143,8 @@ do COMPOSE_STATUS=$(echo "$OUTPUT" | jq -r '.status') - if [[ "$COMPOSE_STATUS" != "WAITING" && "$COMPOSE_STATUS" != "RUNNING" ]]; then - test "$COMPOSE_STATUS" = "FINISHED" + if [[ "$COMPOSE_STATUS" != "pending" && "$COMPOSE_STATUS" != "running" ]]; then + test "$COMPOSE_STATUS" = "success" break fi