From 7e96aaab090c98bef6fb18ec3e0f13b8c2925b7f Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Mon, 9 Sep 2019 16:17:04 -0700 Subject: [PATCH] Add CRI Validation test. Signed-off-by: Lantao Liu --- .travis.yml | 1 - Makefile | 18 +++- hack/install/install-cni.sh | 5 +- hack/install/install-containerd.sh | 11 +-- hack/install/install-critools.sh | 16 ++-- hack/install/install-runc.sh | 5 +- hack/install/windows/install-cni-config.sh | 86 +++++++++++++++++++ hack/install/windows/install-cni.sh | 37 ++++++++ hack/install/windows/install-deps.sh | 47 +++++++++++ hack/install/windows/install-hcsshim.sh | 37 ++++++++ hack/test-cri.sh | 3 +- hack/utils.sh | 2 +- test/windows/runner.sh | 98 ++++++++++++++++++++++ test/windows/setup-ssh.ps1 | 32 +++++++ test/windows/setup-vm.ps1 | 23 +++++ test/windows/test.sh | 45 ++++++++++ 16 files changed, 440 insertions(+), 26 deletions(-) create mode 100755 hack/install/windows/install-cni-config.sh create mode 100755 hack/install/windows/install-cni.sh create mode 100755 hack/install/windows/install-deps.sh create mode 100755 hack/install/windows/install-hcsshim.sh create mode 100755 test/windows/runner.sh create mode 100644 test/windows/setup-ssh.ps1 create mode 100644 test/windows/setup-vm.ps1 create mode 100755 test/windows/test.sh diff --git a/.travis.yml b/.travis.yml index c3edb9e7d..c1f9539bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,6 @@ before_script: script: - make .install.gitvalidation - make .gitvalidation - - make binaries - make install.deps - make containerd - sudo PATH=$PATH GOPATH=$GOPATH make install-containerd diff --git a/Makefile b/Makefile index 9140a14b4..b3cbed693 100644 --- a/Makefile +++ b/Makefile @@ -129,14 +129,14 @@ containerd: $(BUILD_DIR)/containerd ## build a customized containerd with CRI pl install-containerd: containerd ## installs customized containerd to system location @echo "$(WHALE) $@" - @install -D -m 755 $(BUILD_DIR)/containerd $(BINDIR)/containerd + @install -D -m 755 $(BUILD_DIR)/containerd "$(BINDIR)/containerd" install: install-containerd ## installs customized containerd to system location @echo "$(WHALE) $@" uninstall: ## remove containerd from system location @echo "$(WHALE) $@" - @rm -f $(BINDIR)/containerd + @rm -f "$(BINDIR)/containerd" $(BUILD_DIR)/$(TARBALL): static-binaries vendor.conf @BUILD_DIR=$(BUILD_DIR) TARBALL=$(TARBALL) VERSION=$(VERSION) ./hack/release.sh @@ -152,12 +152,22 @@ proto: ## update protobuf of the cri plugin api @API_PATH=pkg/api/v1 hack/update-proto.sh @API_PATH=pkg/api/runtimeoptions/v1 hack/update-proto.sh -.PHONY: install.deps +.PHONY: install.deps .install.deps.linux .install.deps.windows -install.deps: ## install dependencies of cri (default 'seccomp apparmor' BUILDTAGS for runc build) +ifeq ($(GOOS),windows) +install.deps: .install.deps.windows ## install windows deps on windows +else +install.deps: .install.deps.linux ## install windows deps on linux +endif + +.install.deps.linux: ## install dependencies of cri (default 'seccomp apparmor' BUILDTAGS for runc build) @echo "$(WHALE) $@" @./hack/install/install-deps.sh +.install.deps.windows: ## install dependencies of cri on windows + @echo "$(WHALE) $@" + @./hack/install/windows/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. diff --git a/hack/install/install-cni.sh b/hack/install/install-cni.sh index 0e3dd649e..e7d120146 100755 --- a/hack/install/install-cni.sh +++ b/hack/install/install-cni.sh @@ -23,8 +23,7 @@ CNI_DIR=${DESTDIR}/opt/cni CNI_PKG=github.com/containernetworking/plugins # Create a temporary GOPATH for cni installation. -TMPGOPATH=$(mktemp -d /tmp/cri-install-cni.XXXX) -GOPATH=${TMPGOPATH} +GOPATH=$(mktemp -d /tmp/cri-install-cni.XXXX) # Install cni from-vendor CNI github.com/containernetworking/plugins @@ -35,4 +34,4 @@ ${SUDO} mkdir -p ${CNI_DIR} ${SUDO} cp -r ./bin ${CNI_DIR} # Clean the tmp GOPATH dir. -rm -rf ${TMPGOPATH} +rm -rf ${GOPATH} diff --git a/hack/install/install-containerd.sh b/hack/install/install-containerd.sh index 84c8c6e4c..e36a8bd8f 100755 --- a/hack/install/install-containerd.sh +++ b/hack/install/install-containerd.sh @@ -19,7 +19,7 @@ set -o nounset set -o pipefail source $(dirname "${BASH_SOURCE[0]}")/utils.sh -CONTAINERD_DIR=${DESTDIR}/usr/local +CONTAINERD_DIR=${CONTAINERD_DIR:-"${DESTDIR}/usr/local"} CONTAINERD_PKG=github.com/containerd/containerd # CHECKOUT_CONTAINERD indicates whether to checkout containerd repo. @@ -29,8 +29,7 @@ CHECKOUT_CONTAINERD=${CHECKOUT_CONTAINERD:-true} if ${CHECKOUT_CONTAINERD}; then # Create a temporary GOPATH for containerd installation. - TMPGOPATH=$(mktemp -d /tmp/cri-install-containerd.XXXX) - GOPATH=${TMPGOPATH} + GOPATH=$(mktemp -d /tmp/cri-install-containerd.XXXX) from-vendor CONTAINERD github.com/containerd/containerd checkout_repo ${CONTAINERD_PKG} ${CONTAINERD_VERSION} ${CONTAINERD_REPO} fi @@ -40,9 +39,11 @@ cd ${GOPATH}/src/${CONTAINERD_PKG} make BUILDTAGS="${BUILDTAGS}" # containerd make install requires `go` to work. Explicitly # set PATH to make sure it can find `go` even with `sudo`. -${SUDO} sh -c "PATH=${PATH} make install -e DESTDIR=${CONTAINERD_DIR}" +# The single quote is required because containerd Makefile +# can't handle spaces in the path. +${SUDO} make install -e DESTDIR="'${CONTAINERD_DIR}'" # Clean the tmp GOPATH dir. if ${CHECKOUT_CONTAINERD}; then - rm -rf ${TMPGOPATH} + rm -rf ${GOPATH} fi diff --git a/hack/install/install-critools.sh b/hack/install/install-critools.sh index 0194ca23a..35bb6d5f1 100755 --- a/hack/install/install-critools.sh +++ b/hack/install/install-critools.sh @@ -19,22 +19,22 @@ set -o nounset set -o pipefail source $(dirname "${BASH_SOURCE[0]}")/utils.sh -CRITOOL_DIR=${DESTDIR}/usr/local/bin -CRICTL_CONFIG_DIR=${DESTDIR}/etc +CRITOOL_DIR="${CRITOOL_DIR:-${DESTDIR}/usr/local/bin}" +CRICTL_CONFIG_DIR="${CRICTL_CONFIG_DIR:-"${DESTDIR}/etc"}" +CRICTL_RUNTIME_ENDPOINT=${CRICTL_RUNTIME_ENDPOINT:-unix:///run/containerd/containerd.sock} # Create a temporary GOPATH for crictl installation. -TMPGOPATH=$(mktemp -d /tmp/cri-install-crictl.XXXX) -GOPATH=${TMPGOPATH} +GOPATH=$(mktemp -d /tmp/cri-install-crictl.XXXX) #Install crictl checkout_repo ${CRITOOL_PKG} ${CRITOOL_VERSION} ${CRITOOL_REPO} cd ${GOPATH}/src/${CRITOOL_PKG} make VERSION=${CRITOOL_VERSION} -${SUDO} make install -e BINDIR=${CRITOOL_DIR} GOPATH=${GOPATH} +${SUDO} make install -e BINDIR="\"${CRITOOL_DIR}\"" GOPATH=${GOPATH} ${SUDO} mkdir -p ${CRICTL_CONFIG_DIR} -${SUDO} bash -c 'cat >'${CRICTL_CONFIG_DIR}'/crictl.yaml <"'"${CRICTL_CONFIG_DIR}"'"/crictl.yaml <= 8 )); then + mask=255 + elif (( len > 0 )); then + mask=$(( 256 - 2 ** ( 8 - len ) )) + else + mask=0 + fi + (( len -= 8 )) + result_array[i]=$(( gateway_array[i] & mask )) + done + result="$(printf ".%s" "${result_array[@]}")" + result="${result:1}" + echo "$result/$((32 - prefix_len))" +} + +# nat already exists on the Windows VM, the subnet and gateway +# we specify should match that. +gateway="$(powershell -c "(Get-NetIPAddress -InterfaceAlias 'vEthernet (nat)' -AddressFamily IPv4).IPAddress")" +prefix_len="$(powershell -c "(Get-NetIPAddress -InterfaceAlias 'vEthernet (nat)' -AddressFamily IPv4).PrefixLength")" + +subnet="$(calculate_subnet "$gateway" "$prefix_len")" + +# The "name" field in the config is used as the underlying +# network type right now (see +# https://github.com/microsoft/windows-container-networking/pull/45), +# so it must match a network type in: +# https://docs.microsoft.com/en-us/windows-server/networking/technologies/hcn/hcn-json-document-schemas +bash -c 'cat >"'"${CNI_CONFIG_DIR}"'"/0-containerd-nat.conf < "${REPORT_DIR}/containerd.log" & +pid=$! +ctr version + +set +o errexit +critest --runtime-endpoint=npipe:////./pipe/containerd-containerd --ginkgo.focus="${FOCUS}" --ginkgo.skip="${SKIP}" --report-dir="${REPORT_DIR}" --report-prefix="windows" +TEST_RC=$? +set -o errexit +kill -9 $pid +echo -n "${TEST_RC}" > "${REPORT_DIR}/exitcode"