From 32ec1f1e21dca493d9d438df266ee846a3bdd655 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Sat, 24 Jun 2017 01:13:12 +0000 Subject: [PATCH] Add CRI validation test into presubmit test. Signed-off-by: Lantao Liu --- .travis.yml | 21 ++++++++- Makefile | 15 ++++++- hack/install-deps.sh | 90 ++++++++++++++++++++++++++++++++++++++ hack/test-cri.sh | 75 +++++++++++++++++++++++++++++++ hack/verify-boilerplate.sh | 2 +- hack/versions | 4 ++ 6 files changed, 203 insertions(+), 4 deletions(-) create mode 100755 hack/install-deps.sh create mode 100755 hack/test-cri.sh create mode 100644 hack/versions diff --git a/.travis.yml b/.travis.yml index 3b1caf8ca..7694295b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,21 @@ go: sudo: required -install: +services: + - docker + +before_install: + # libseccomp in trusty is not new enough, need backports version. + - sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' > /etc/apt/sources.list.d/backports.list" + - sudo apt-get update + +install: + - sudo apt-get install btrfs-tools + - sudo apt-get install libseccomp2/trusty-backports + - sudo apt-get install libseccomp-dev/trusty-backports + - docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter - make install.tools + - make install.deps before_script: - export PATH=$HOME/gopath/bin:$PATH @@ -16,3 +29,9 @@ script: - make verify - make binaries - make test + - make test-cri +after_script: + # Abuse travis to preserve the log. + # TODO(random-liu): Use prow for integration test. + - cat /tmp/cri-containerd.log + - cat /tmp/containerd.log diff --git a/Makefile b/Makefile index cdd388d44..630e4851b 100644 --- a/Makefile +++ b/Makefile @@ -35,9 +35,11 @@ help: @echo " * 'install' - Install binaries to system locations" @echo " * 'binaries' - Build cri-containerd" @echo " * 'test' - Test cri-containerd" + @echo " * 'test-cri' - Test cri-containerd with cri validation test" @echo " * 'clean' - Clean artifacts" @echo " * 'verify' - Execute the source code verification tools" - @echo " * 'install.tools' - Installs tools used by verify" + @echo " * 'install.tools' - Install tools used by verify" + @echo " * 'install.deps' - Install dependencies of cri-containerd (containerd, runc, cni)" @echo " * 'uninstall' - Remove installed binaries from system locations" @echo " * 'version' - Print current cri-containerd release version" @@ -71,7 +73,10 @@ cri-containerd: check-gopath $(PROJECT)/cmd/cri-containerd test: - go test -timeout=10m -v -race ./pkg/... $(BUILD_TAGS) + go test -timeout=10m -race ./pkg/... $(BUILD_TAGS) + +test-cri: + @./hack/test-cri.sh clean: rm -f $(BUILD_DIR)/cri-containerd @@ -84,6 +89,11 @@ install: check-gopath uninstall: rm -f $(BINDIR)/cri-containerd +.PHONY: install.deps + +install.deps: + @./hack/install-deps.sh + .PHONY: .gitvalidation # When this is running in travis, it will only check the travis commit range. # When running outside travis, it will check from $(EPOCH_TEST_COMMIT)..HEAD. @@ -115,5 +125,6 @@ install.tools: .install.gitvalidation .install.gometalinter install \ lint \ test \ + test-cri \ uninstall \ version diff --git a/hack/install-deps.sh b/hack/install-deps.sh new file mode 100755 index 000000000..d046acf54 --- /dev/null +++ b/hack/install-deps.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Dependencies: +# runc: +# - libseccomp-dev(Ubuntu,Debian)/libseccomp-devel(Fedora, CentOS, RHEL). Note that +# libseccomp in ubuntu <=trusty and debian <=jessie is not new enough, backport +# is required. +# - libapparmor-dev(Ubuntu,Debian)/libapparmor-devel(Fedora, CentOS, RHEL) +# containerd: +# - btrfs-tools(Ubuntu,Debian)/btrfs-progs-devel(Fedora, CentOS, RHEL) + +set -o errexit +set -o nounset +set -o pipefail + +ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/.. +. ${ROOT}/hack/versions + +BUILD_IMAGE=golang:1.8 +RUNC_PKG=github.com/opencontainers/runc +CNI_PKG=github.com/containernetworking/cni +CNI_DIR=/opt/cni +CNI_CONFIG_DIR=/etc/cni/net.d +CONTAINERD_PKG=github.com/containerd/containerd + +# Install runc +go get -d ${RUNC_PKG}/... +cd ${GOPATH}/src/${RUNC_PKG} +git fetch --all +git checkout ${RUNC_VERSION} +make +sudo make install +which runc + +# Install cni +go get -d ${CNI_PKG}/... +cd ${GOPATH}/src/${CNI_PKG} +git fetch --all +git checkout ${CNI_VERSION} +./build +sudo mkdir -p ${CNI_DIR} +sudo cp -r ./bin ${CNI_DIR} +sudo mkdir -p ${CNI_CONFIG_DIR} +sudo bash -c 'cat >'${CNI_CONFIG_DIR}'/10-containerd-bridge.conf <'${CNI_CONFIG_DIR}'/99-loopback.conf < ${REPORT_DIR}/containerd.log & + +# Start cri-containerd +cd ${ROOT} +sudo _output/cri-containerd --alsologtostderr --v 4 &> ${REPORT_DIR}/cri-containerd.log & + +# Run cri validation test +sudo env PATH=${PATH} GOPATH=${GOPATH} ${CRITEST} --runtime-endpoint=${CRICONTAINERD_SOCK} --focus="${FOCUS}" --ginkgo-flags="--skip=\"${SKIP}\"" validation +test_exit_code=$? + +sudo pkill containerd + +exit ${test_exit_code} diff --git a/hack/verify-boilerplate.sh b/hack/verify-boilerplate.sh index 09bb1921a..851fe713b 100755 --- a/hack/verify-boilerplate.sh +++ b/hack/verify-boilerplate.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2014 The Kubernetes Authors. +# Copyright 2017 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/hack/versions b/hack/versions new file mode 100644 index 000000000..93782b59e --- /dev/null +++ b/hack/versions @@ -0,0 +1,4 @@ +RUNC_VERSION=639454475cb9c8b861cc599f8bcd5c8c790ae402 +CNI_VERSION=v0.4.0 +CONTAINERD_VERSION=8ed1e24ae925b5c6d8195858ee89dddb0507d65f +CRITEST_VERSION=2d59bc793e71ee324895ca422e87a863435aa8cd