Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Add pause unpause test #11

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
language: go
sudo: required
dist: trusty
dist: xenial

go:
- "1.10.2"

go_import_path: github.com/kubernetes-sigs/cri-tools

before_install:
- sudo env PATH=$PATH GOPATH=$GOPATH hack/install-cni.sh
- sudo env PATH=$PATH GOPATH=$GOPATH hack/install-pouch.sh
chuanchang marked this conversation as resolved.
Show resolved Hide resolved

install:
- make install.tools

Expand All @@ -26,5 +22,7 @@ jobs:
- stage: Test
script:
- make
- sudo env PATH=$PATH GOPATH=$GOPATH hack/install-cni.sh
- sudo env PATH=$PATH GOPATH=$GOPATH hack/install-pouch.sh
- sudo env PATH=$PATH GOPATH=$GOPATH hack/run-pouch.sh "v1alpha2"
- sudo env PATH=$PATH GOPATH=$GOPATH hack/run-critest.sh "v1alpha2"
5 changes: 2 additions & 3 deletions hack/install-pouch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -o errexit
set -o nounset
set -o pipefail

POUCH_VERSION="5e2c01d0"
POUCH_VERSION="9df7eab"
POUCH_REPO=github.com/alibaba/pouch
WORKDIR="${GOPATH}/src/${POUCH_REPO}"

Expand Down Expand Up @@ -55,8 +55,7 @@ pouch::install() {
git fetch --all
git checkout ${POUCH_VERSION}

make build
TEST_FLAGS= BUILDTAGS="selinux seccomp apparmor" make build-daemon-integration
TEST_FLAGS= BUILDTAGS="selinux seccomp apparmor" make build
sudo env "PATH=$PATH" make install
cd -
}
Expand Down
2 changes: 1 addition & 1 deletion hack/run-critest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ critest::run_e2e() {
--focus="${CRI_FOCUS}" --ginkgo-flags="--skip=\"${CRI_SKIP}\"" validation
else
critest --runtime-endpoint=${POUCH_SOCK} \
--ginkgo.focus="${CRI_FOCUS}" --ginkgo.skip="${CRI_SKIP}"
--ginkgo.focus="${CRI_FOCUS}" --ginkgo.skip="${CRI_SKIP}" --parallel=8
fi

code=$?
Expand Down
27 changes: 15 additions & 12 deletions hack/run-pouch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,32 @@ pouch::check_cri_listening() {

# pouchd::install_dependencies downloads and installs dependent packages
pouch::install_dependencies() {
sudo apt-get update
sudo apt-get install -y socat
chuanchang marked this conversation as resolved.
Show resolved Hide resolved
cd "${WORKDIR}"
make download-dependencies
cd -
}

# pouch::stop_dockerd makes sure dockerd is not running
pouch::stop_dockerd() {
if [[ X"" != X"$(pidof docker)" ]]; then
if [[ X"" != X"$(pidof dockerd)" ]]; then
# need to avoid conflict between dockerd and pouchd
systemctl stop docker
fi
}

# pouch:run starts pouch daemon with cri enabled
pouch::run() {
local cri_runtime tmplog_dir pouchd_log sandbox_img flags
local cri_runtime pouchd_log sandbox_img flags

cri_runtime=$1
tmplog_dir="$(mktemp -d /tmp/integration-daemon-cri-testing-XXXXX)"
pouchd_log="${tmplog_dir}/pouchd.log"

# daemon cri integration coverage profile
coverage_profile="${WORKDIR}/coverage/integration_daemon_cri_${cri_runtime}_profile.out"
rm -rf "${coverage_profile}"
pouchd_log=$2

sandbox_img="gcr.io/google_containers/pause-amd64:3.0"
flags=" -test.coverprofile=${coverage_profile} DEVEL"
flags="${flags} --enable-cri --cri-version ${cri_runtime} --sandbox-image=${sandbox_img}"
flags=" --enable-cri --cri-version ${cri_runtime} --sandbox-image=${sandbox_img}"

${WORKDIR}/bin/pouchd-integration ${flags} > $pouchd_log 2>&1 &
${WORKDIR}/bin/pouchd ${flags} > "${pouchd_log}" 2>&1 &

# Wait a while for pouch daemon starting
sleep 10
Expand All @@ -101,12 +97,19 @@ main() {
fi

pouch::stop_dockerd
pouch::run "${cri_runtime}"

# tmplog_dir stores the background job log data
tmplog_dir="$(mktemp -d /tmp/integration-daemon-cri-testing-XXXXX)"
pouchd_log="${tmplog_dir}/pouchd.log"

pouch::run "${cri_runtime}" "${pouchd_log}"

pouchcri_has_listened="$(pouch::check_cri_listening)"

if [[ "${pouchcri_has_listened}" = "false" ]]; then
echo "pouchcri has not been listened: $(netstat -lx)"
echo "there is the daemon log..."
cat "${pouchd_log}"
exit 1
fi

Expand Down
4 changes: 4 additions & 0 deletions kubelet/apis/cri/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type ContainerManager interface {
// for the container. If it returns error, new container log file MUST NOT
// be created.
ReopenContainerLog(ContainerID string) error
// PauseContainer pauses the container.
PauseContainer(ContainerID string) error
// UnpauseContainer unpauses the container.
UnpauseContainer(ContainerID string) error
}

// PodSandboxManager contains methods for operating on PodSandboxes. The methods
Expand Down
24 changes: 24 additions & 0 deletions kubelet/remote/remote_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,27 @@ func (r *RemoteRuntimeService) ReopenContainerLog(containerID string) error {
}
return nil
}

func (r *RemoteRuntimeService) PauseContainer(containerID string) error {
ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel()

_, err := r.runtimeClient.PauseContainer(ctx, &runtimeapi.PauseContainerRequest{ContainerId: containerID})
if err != nil {
glog.Errorf("PauseContainer %q from runtime service failed: %v", containerID, err)
return err
}
return nil
}

func (r *RemoteRuntimeService) UnpauseContainer(containerID string) error {
ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel()

_, err := r.runtimeClient.UnpauseContainer(ctx, &runtimeapi.UnpauseContainerRequest{ContainerId: containerID})
if err != nil {
glog.Errorf("UnpauseContainer %q from runtime service failed: %v", containerID, err)
return err
}
return nil
}
32 changes: 32 additions & 0 deletions pkg/validate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,38 @@ var _ = framework.KubeDescribe("Container", func() {
testStartContainer(rc, containerID)
})

It("runtime should support pause and unpause container [Conformance]", func() {
By("create container")
containerID := framework.CreateDefaultContainer(rc, ic, podID, podConfig, "container-for-pause-unpause-test-")

By("start container")
startContainer(rc, containerID)

By("get container status")
Eventually(func() runtimeapi.ContainerState {
return getContainerStatus(rc, containerID).State
}, time.Minute, time.Second*4).Should(Equal(runtimeapi.ContainerState_CONTAINER_RUNNING))
chuanchang marked this conversation as resolved.
Show resolved Hide resolved

By("pause container")
rc.PauseContainer(containerID)

By("get container status")
Eventually(func() runtimeapi.ContainerState {
return getContainerStatus(rc, containerID).State
}, time.Minute, time.Second*4).Should(Equal(runtimeapi.ContainerState_CONTAINER_PAUSE))

By("unpause container")
rc.UnpauseContainer(containerID)

By("get container status")
Eventually(func() runtimeapi.ContainerState {
return getContainerStatus(rc, containerID).State
}, time.Minute, time.Second*4).Should(Equal(runtimeapi.ContainerState_CONTAINER_RUNNING))

By("test stop container")
testStopContainer(rc, containerID)
})

It("runtime should support stopping container [Conformance]", func() {
By("create container")
containerID := framework.CreateDefaultContainer(rc, ic, podID, podConfig, "container-for-stop-test-")
Expand Down
Loading