Fix remote integration for healthchecks

the one remaining test that is still skipped do to missing exec function

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude
2020-05-20 14:43:01 -05:00
parent 09f8f14b4f
commit 141b34f6be
7 changed files with 71 additions and 74 deletions

View File

@ -4,6 +4,7 @@ import (
"net/http"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/api/handlers/utils"
)
@ -12,32 +13,27 @@ func RunHealthCheck(w http.ResponseWriter, r *http.Request) {
name := utils.GetName(r)
status, err := runtime.HealthCheck(name)
if err != nil {
if status == libpod.HealthCheckContainerNotFound {
if status == define.HealthCheckContainerNotFound {
utils.ContainerNotFound(w, name, err)
return
}
if status == libpod.HealthCheckNotDefined {
if status == define.HealthCheckNotDefined {
utils.Error(w, "no healthcheck defined", http.StatusConflict, err)
return
}
if status == libpod.HealthCheckContainerStopped {
if status == define.HealthCheckContainerStopped {
utils.Error(w, "container not running", http.StatusConflict, err)
return
}
utils.InternalServerError(w, err)
return
}
ctr, err := runtime.LookupContainer(name)
if err != nil {
utils.InternalServerError(w, err)
return
hcStatus := define.HealthCheckUnhealthy
if status == define.HealthCheckSuccess {
hcStatus = define.HealthCheckHealthy
}
hcLog, err := ctr.GetHealthCheckLog()
if err != nil {
utils.InternalServerError(w, err)
return
report := define.HealthCheckResults{
Status: hcStatus,
}
utils.WriteResponse(w, http.StatusOK, hcLog)
utils.WriteResponse(w, http.StatusOK, report)
}