mirror of
https://github.com/containers/podman.git
synced 2025-06-20 17:13:43 +08:00
API: fix libpod's container wait endpoint condition conversion
Signed-off-by: Nikolay Edigaryev <edigaryev@gmail.com>
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containers/podman/v2/libpod/define"
|
||||||
"github.com/containers/podman/v2/pkg/util"
|
"github.com/containers/podman/v2/pkg/util"
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -19,6 +20,7 @@ func NewAPIDecoder() *schema.Decoder {
|
|||||||
d.IgnoreUnknownKeys(true)
|
d.IgnoreUnknownKeys(true)
|
||||||
d.RegisterConverter(map[string][]string{}, convertURLValuesString)
|
d.RegisterConverter(map[string][]string{}, convertURLValuesString)
|
||||||
d.RegisterConverter(time.Time{}, convertTimeString)
|
d.RegisterConverter(time.Time{}, convertTimeString)
|
||||||
|
d.RegisterConverter(define.ContainerStatus(0), convertContainerStatusString)
|
||||||
|
|
||||||
var Signal syscall.Signal
|
var Signal syscall.Signal
|
||||||
d.RegisterConverter(Signal, convertSignal)
|
d.RegisterConverter(Signal, convertSignal)
|
||||||
@ -46,6 +48,19 @@ func convertURLValuesString(query string) reflect.Value {
|
|||||||
return reflect.ValueOf(f)
|
return reflect.ValueOf(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertContainerStatusString(query string) reflect.Value {
|
||||||
|
result, err := define.StringToContainerStatus(query)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Infof("convertContainerStatusString: Failed to parse %s: %s", query, err.Error())
|
||||||
|
|
||||||
|
// We return nil here instead of result because reflect.ValueOf().IsValid() will be true
|
||||||
|
// in github.com/gorilla/schema's decoder, which means there's no parsing error
|
||||||
|
return reflect.ValueOf(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
return reflect.ValueOf(result)
|
||||||
|
}
|
||||||
|
|
||||||
// isZero() can be used to determine if parsing failed.
|
// isZero() can be used to determine if parsing failed.
|
||||||
func convertTimeString(query string) reflect.Value {
|
func convertTimeString(query string) reflect.Value {
|
||||||
var (
|
var (
|
||||||
|
@ -63,7 +63,7 @@ cid=$(jq -r '.Id' <<<"$output")
|
|||||||
# Prior to the fix in #6835, this would fail 500 "args must not be empty"
|
# Prior to the fix in #6835, this would fail 500 "args must not be empty"
|
||||||
t POST libpod/containers/${cid}/start '' 204
|
t POST libpod/containers/${cid}/start '' 204
|
||||||
# Container should exit almost immediately. Wait for it, confirm successful run
|
# Container should exit almost immediately. Wait for it, confirm successful run
|
||||||
t POST libpod/containers/${cid}/wait '' 200 '0'
|
t POST libpod/containers/${cid}/wait?condition=stopped&condition=exited '' 200 '0'
|
||||||
t GET libpod/containers/${cid}/json 200 \
|
t GET libpod/containers/${cid}/json 200 \
|
||||||
.Id=$cid \
|
.Id=$cid \
|
||||||
.State.Status~\\\(exited\\\|stopped\\\) \
|
.State.Status~\\\(exited\\\|stopped\\\) \
|
||||||
|
Reference in New Issue
Block a user