Merge pull request #532 from runcom/e2e-fixes-0

e2e fixes - part 0
This commit is contained in:
Mrunal Patel 2017-05-22 10:59:23 -07:00 committed by GitHub
commit 774e98514f
8 changed files with 148 additions and 6 deletions

View file

@ -460,6 +460,13 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID string) error {
ftm := time.Unix(0, r.Status.FinishedAt) ftm := time.Unix(0, r.Status.FinishedAt)
fmt.Printf("Finished: %v\n", ftm) fmt.Printf("Finished: %v\n", ftm)
fmt.Printf("Exit Code: %v\n", r.Status.ExitCode) fmt.Printf("Exit Code: %v\n", r.Status.ExitCode)
if r.Status.Image != nil {
fmt.Printf("Image: %v\n", r.Status.Image.Image)
}
//
// TODO: https://github.com/kubernetes-incubator/cri-o/issues/531
//
//fmt.Printf("ImageRef: %v\n", r.Status.ImageRef)
return nil return nil
} }

View file

@ -2,8 +2,10 @@ package server
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/distribution/reference"
"github.com/kubernetes-incubator/cri-o/oci" "github.com/kubernetes-incubator/cri-o/oci"
rspec "github.com/opencontainers/runtime-spec/specs-go" rspec "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -24,14 +26,12 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
s.containerStateToDisk(c) s.containerStateToDisk(c)
containerID := c.ID() containerID := c.ID()
image := c.Image()
resp := &pb.ContainerStatusResponse{ resp := &pb.ContainerStatusResponse{
Status: &pb.ContainerStatus{ Status: &pb.ContainerStatus{
Id: containerID, Id: containerID,
Metadata: c.Metadata(), Metadata: c.Metadata(),
Labels: c.Labels(), Labels: c.Labels(),
Annotations: c.Annotations(), Annotations: c.Annotations(),
Image: image,
}, },
} }
@ -41,12 +41,39 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
} }
resp.Status.Mounts = mounts resp.Status.Mounts = mounts
status, err := s.storageImageServer.ImageStatus(s.imageContext, image.Image) imageName := c.Image().Image
status, err := s.storageImageServer.ImageStatus(s.imageContext, imageName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Status.ImageRef = status.ID imageRef := status.ID
//
// TODO: https://github.com/kubernetes-incubator/cri-o/issues/531
//
//for _, n := range status.Names {
//r, err := reference.ParseNormalizedNamed(n)
//if err != nil {
//return nil, fmt.Errorf("failed to normalize image name for ImageRef: %v", err)
//}
//if digested, isDigested := r.(reference.Canonical); isDigested {
//imageRef = reference.FamiliarString(digested)
//break
//}
//}
resp.Status.ImageRef = imageRef
for _, n := range status.Names {
r, err := reference.ParseNormalizedNamed(n)
if err != nil {
return nil, fmt.Errorf("failed to normalize image name for Image: %v", err)
}
if tagged, isTagged := r.(reference.Tagged); isTagged {
imageName = reference.FamiliarString(tagged)
break
}
}
resp.Status.Image = &pb.ImageSpec{Image: imageName}
cState := s.runtime.ContainerStatus(c) cState := s.runtime.ContainerStatus(c)
rStatus := pb.ContainerState_CONTAINER_UNKNOWN rStatus := pb.ContainerState_CONTAINER_UNKNOWN

View file

@ -32,6 +32,7 @@ func (s *Server) ImageStatus(ctx context.Context, req *pb.ImageStatusRequest) (*
Id: status.ID, Id: status.ID,
RepoTags: status.Names, RepoTags: status.Names,
Size_: *status.Size, Size_: *status.Size,
// TODO: https://github.com/kubernetes-incubator/cri-o/issues/531
}, },
} }
logrus.Debugf("ImageStatusResponse: %+v", resp) logrus.Debugf("ImageStatusResponse: %+v", resp)

View file

@ -21,6 +21,10 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
return nil, err return nil, err
} }
// If the sandbox isn't found we just return an empty response to adhere
// the the CRI interface which expects to not error out in not found
// cases.
resp := &pb.RemovePodSandboxResponse{} resp := &pb.RemovePodSandboxResponse{}
logrus.Warnf("could not get sandbox %s, it's probably been removed already: %v", req.PodSandboxId, err) logrus.Warnf("could not get sandbox %s, it's probably been removed already: %v", req.PodSandboxId, err)
return resp, nil return resp, nil

View file

@ -16,9 +16,19 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
logrus.Debugf("StopPodSandboxRequest %+v", req) logrus.Debugf("StopPodSandboxRequest %+v", req)
sb, err := s.getPodSandboxFromRequest(req.PodSandboxId) sb, err := s.getPodSandboxFromRequest(req.PodSandboxId)
if err != nil { if err != nil {
if err == errSandboxIDEmpty {
return nil, err return nil, err
} }
// If the sandbox isn't found we just return an empty response to adhere
// the the CRI interface which expects to not error out in not found
// cases.
resp := &pb.StopPodSandboxResponse{}
logrus.Warnf("could not get sandbox %s, it's probably been stopped already: %v", req.PodSandboxId, err)
return resp, nil
}
podInfraContainer := sb.infraContainer podInfraContainer := sb.infraContainer
netnsPath, err := podInfraContainer.NetNsPath() netnsPath, err := podInfraContainer.NetNsPath()
if err != nil { if err != nil {

View file

@ -147,7 +147,7 @@ function start_crio() {
if ! [ "$3" = "--no-pause-image" ] ; then if ! [ "$3" = "--no-pause-image" ] ; then
"$BIN2IMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTS --runroot "$TESTDIR/crio-run" --source-binary "$PAUSE_BINARY" "$BIN2IMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTS --runroot "$TESTDIR/crio-run" --source-binary "$PAUSE_BINARY"
fi fi
"$COPYIMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTS --runroot "$TESTDIR/crio-run" --image-name=redis:alpine --import-from=dir:"$ARTIFACTS_PATH"/redis-image --add-name=docker://docker.io/library/redis:alpine --signature-policy="$INTEGRATION_ROOT"/policy.json "$COPYIMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTS --runroot "$TESTDIR/crio-run" --image-name=redis:alpine --import-from=dir:"$ARTIFACTS_PATH"/redis-image --add-name=docker.io/library/redis:alpine --signature-policy="$INTEGRATION_ROOT"/policy.json
"$CRIO_BINARY" --conmon "$CONMON_BINARY" --listen "$CRIO_SOCKET" --cgroup-manager "$CGROUP_MANAGER" --runtime "$RUNTIME_BINARY" --root "$TESTDIR/crio" --runroot "$TESTDIR/crio-run" $STORAGE_OPTS --seccomp-profile "$seccomp" --apparmor-profile "$apparmor" --cni-config-dir "$CRIO_CNI_CONFIG" --signature-policy "$INTEGRATION_ROOT"/policy.json --config /dev/null config >$CRIO_CONFIG "$CRIO_BINARY" --conmon "$CONMON_BINARY" --listen "$CRIO_SOCKET" --cgroup-manager "$CGROUP_MANAGER" --runtime "$RUNTIME_BINARY" --root "$TESTDIR/crio" --runroot "$TESTDIR/crio-run" $STORAGE_OPTS --seccomp-profile "$seccomp" --apparmor-profile "$apparmor" --cni-config-dir "$CRIO_CNI_CONFIG" --signature-policy "$INTEGRATION_ROOT"/policy.json --config /dev/null config >$CRIO_CONFIG
# Prepare the CNI configuration files, we're running with non host networking by default # Prepare the CNI configuration files, we're running with non host networking by default
@ -170,6 +170,24 @@ function start_crio() {
if [ "$status" -ne 0 ] ; then if [ "$status" -ne 0 ] ; then
crioctl image pull busybox:latest crioctl image pull busybox:latest
fi fi
#
#
#
# TODO: remove the code below for redis digested image id when
# https://github.com/kubernetes-incubator/cri-o/issues/531 is complete
# as the digested reference will be auto-stored when pulling the tag
# above
#
#
#
REDIS_IMAGEID_DIGESTED="redis@sha256:03789f402b2ecfb98184bf128d180f398f81c63364948ff1454583b02442f73b"
run crioctl image status --id $REDIS_IMAGEID_DIGESTED
if [ "$status" -ne 0 ]; then
crioctl image pull $REDIS_IMAGEID_DIGESTED
fi
#
#
#
BUSYBOX_IMAGEID=$(crioctl image status --id=busybox | head -1 | sed -e "s/ID: //g") BUSYBOX_IMAGEID=$(crioctl image status --id=busybox | head -1 | sed -e "s/ID: //g")
} }

View file

@ -23,6 +23,58 @@ function teardown() {
stop_crio stop_crio
} }
@test "container status return image:tag if created by image ID" {
start_crio
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"
sed -e "s/%VALUE%/$REDIS_IMAGEID/g" "$TESTDATA"/container_config_by_imageid.json > "$TESTDIR"/ctr_by_imageid.json
run crioctl ctr create --config "$TESTDIR"/ctr_by_imageid.json --pod "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
run crioctl ctr status --id "$ctr_id"
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" =~ "Image: redis:alpine" ]]
cleanup_ctrs
cleanup_pods
stop_crio
}
@test "container status return image@digest if created by image ID and digest available" {
skip "depends on https://github.com/kubernetes-incubator/cri-o/issues/531"
start_crio
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"
sed -e "s/%VALUE%/$REDIS_IMAGEID_DIGESTED/g" "$TESTDATA"/container_config_by_imageid.json > "$TESTDIR"/ctr_by_imageid.json
run crioctl ctr create --config "$TESTDIR"/ctr_by_imageid.json --pod "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
run crioctl ctr status --id "$ctr_id"
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" =~ "ImageRef: redis@sha256:03789f402b2ecfb98184bf128d180f398f81c63364948ff1454583b02442f73b" ]]
cleanup_ctrs
cleanup_pods
stop_crio
}
@test "image pull" { @test "image pull" {
start_crio "" "" --no-pause-image start_crio "" "" --no-pause-image
run crioctl image pull "$IMAGE" run crioctl image pull "$IMAGE"

View file

@ -56,6 +56,29 @@ function teardown() {
stop_crio stop_crio
} }
@test "pod stop ignores not found sandboxes" {
start_crio
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"
run crioctl pod stop --id "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
run crioctl pod remove --id "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
run crioctl pod stop --id "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
cleanup_ctrs
cleanup_pods
stop_crio
}
@test "pod list filtering" { @test "pod list filtering" {
start_crio start_crio
run crioctl pod run --config "$TESTDATA"/sandbox_config.json -name pod1 --label "a=b" --label "c=d" --label "e=f" run crioctl pod run --config "$TESTDATA"/sandbox_config.json -name pod1 --label "a=b" --label "c=d" --label "e=f"