Merge pull request #543 from runcom/fix-ctr-status-reasons
[e2e fix] server: correctly fill ctr termination reason
This commit is contained in:
commit
5ed79fb5cd
3 changed files with 68 additions and 5 deletions
|
@ -13,14 +13,14 @@ const (
|
|||
containerTypeContainer = "container"
|
||||
)
|
||||
|
||||
func (s *Server) getContainerFromRequest(containerID string) (*oci.Container, error) {
|
||||
if containerID == "" {
|
||||
func (s *Server) getContainerFromRequest(cid string) (*oci.Container, error) {
|
||||
if cid == "" {
|
||||
return nil, fmt.Errorf("container ID should not be empty")
|
||||
}
|
||||
|
||||
containerID, err := s.ctrIDIndex.Get(containerID)
|
||||
containerID, err := s.ctrIDIndex.Get(cid)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("container with ID starting with %s not found: %v", containerID, err)
|
||||
return nil, fmt.Errorf("container with ID starting with %s not found: %v", cid, err)
|
||||
}
|
||||
|
||||
c := s.state.containers.Get(containerID)
|
||||
|
|
|
@ -98,8 +98,13 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
|
|||
finished := cState.Finished.UnixNano()
|
||||
resp.Status.FinishedAt = finished
|
||||
resp.Status.ExitCode = cState.ExitCode
|
||||
if cState.OOMKilled {
|
||||
switch {
|
||||
case cState.OOMKilled:
|
||||
resp.Status.Reason = "OOMKilled"
|
||||
case cState.ExitCode == 0:
|
||||
resp.Status.Reason = "Completed"
|
||||
default:
|
||||
resp.Status.Reason = "Error"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,64 @@ function teardown() {
|
|||
cleanup_test
|
||||
}
|
||||
|
||||
@test "ctr not found correct error message" {
|
||||
start_crio
|
||||
run crioctl ctr status --id randomid
|
||||
echo "$output"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "container with ID starting with randomid not found" ]]
|
||||
|
||||
stop_crio
|
||||
}
|
||||
|
||||
@test "ctr termination reason Completed" {
|
||||
start_crio
|
||||
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
pod_id="$output"
|
||||
run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
ctr_id="$output"
|
||||
run crioctl ctr start --id "$ctr_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
run crioctl ctr status --id "$ctr_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Reason: Completed" ]]
|
||||
|
||||
cleanup_ctrs
|
||||
cleanup_pods
|
||||
stop_crio
|
||||
}
|
||||
|
||||
@test "ctr termination reason Error" {
|
||||
start_crio
|
||||
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
pod_id="$output"
|
||||
errorconfig=$(cat "$TESTDATA"/container_config.json | python -c 'import json,sys;obj=json.load(sys.stdin);obj["command"] = ["false"]; json.dump(obj, sys.stdout)')
|
||||
echo "$errorconfig" > "$TESTDIR"/container_config_error.json
|
||||
run crioctl ctr create --config "$TESTDIR"/container_config_error.json --pod "$pod_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
ctr_id="$output"
|
||||
run crioctl ctr start --id "$ctr_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
run crioctl ctr status --id "$ctr_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Reason: Error" ]]
|
||||
|
||||
cleanup_ctrs
|
||||
cleanup_pods
|
||||
stop_crio
|
||||
}
|
||||
|
||||
@test "ctr remove" {
|
||||
start_crio
|
||||
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
|
||||
|
|
Loading…
Add table
Reference in a new issue