Skip to content

Commit

Permalink
ci: Add a job to run e2e tests on a single node cluster
Browse files Browse the repository at this point in the history
E2E tests will run on a single node minikube cluster
on centos ci instances.

Signed-off-by: Yug Gupta <[email protected]>
  • Loading branch information
Yuggupta27 authored and nixpanic committed Jul 9, 2020
1 parent 477a122 commit 1feb9d9
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 0 deletions.
55 changes: 55 additions & 0 deletions mini-e2e.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
def cico_retries = 16
def cico_retry_interval = 60
// temporary git repository for testing purpose
def ci_git_repo = 'https://github.com/Yuggupta27/ceph-csi'
def ci_git_branch = 'mini-e2e'
def git_repo = 'https://github.com/ceph/ceph-csi'
def ref = "master"

node('cico-workspace') {
stage('checkout ci repository') {
git url: "${ci_git_repo}",
branch: "${ci_git_branch}",
changelog: false
}

stage('reserve bare-metal machine') {
def firstAttempt = true
retry(30) {
if (!firstAttempt) {
sleep(time: 5, unit: "MINUTES")
}
firstAttempt = false
cico = sh(
script: "cico node get -f value -c hostname -c comment --retry-count ${cico_retries} --retry-interval ${cico_retry_interval}",
returnStdout: true
).trim().tokenize(' ')
env.CICO_NODE = "${cico[0]}.ci.centos.org"
env.CICO_SSID = "${cico[1]}"
}
}

try {
stage('prepare bare-metal machine') {
if (params.ghprbPullId != null) {
ref = "pull/${ghprbPullId}/head"
}
sh 'scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ./prepare.sh ./single-node-k8s.sh root@${CICO_NODE}:'
sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} ./prepare.sh --workdir=/opt/build/go/src/github.com/ceph/ceph-csi --gitrepo=${git_repo} --ref=${ref}"
}
stage('e2e kube v1.17.5') {
// timeout is kept minimal as of now to catch errors quickly. It will be extended when pipeline has expected execution
timeout(time: 25, unit: 'MINUTES') {
node ('cico-workspace') {
sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} ./single-node-k8s.sh --ref=${ref} --k8s_version=v1.17.5 --test_type=functest"
}
}
}
}

finally {
stage('return bare-metal machine') {
sh 'cico node done ${CICO_SSID}'
}
}
}
31 changes: 31 additions & 0 deletions scripts/skip-doc-change.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash -e
CHANGED_FILES=$(git --no-pager diff --name-only "tip/${ref}" $(git merge-base "tip/${ref}" master))

[[ -z $CHANGED_FILES ]] && exit 1

skip=0
#files to be skipped
declare -a FILES=(^docs/ .md$ ^scripts/ LICENSE .mergify.yml .github .gitignore)

function check_file_present() {
local file=$1
for FILE in "${FILES[@]}"; do
if [[ $file =~ $FILE ]]; then
if [[ $file =~ (minikube.sh|travis-functest.sh) ]]; then
continue
fi
return 0
fi
done
return 1
}

for CHANGED_FILE in $CHANGED_FILES; do
if ! check_file_present "$CHANGED_FILE"; then
skip=1
fi
done
if [ $skip -eq 0 ]; then
echo "Skipping functional tests"
exit 1
fi
144 changes: 144 additions & 0 deletions single-node-k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/bin/bash

set -x
# set -e -o pipefail

ARGUMENT_LIST=(
"k8s_version"
"ref"
"test_type"
)

opts=$(getopt \
--longoptions "$(printf "%s:," "${ARGUMENT_LIST[@]}")help" \
--name "$(basename "${0}")" \
--options "" \
-- "$@"
)
ret=$?

if [ ${ret} -ne 0 ]
then
echo "Try '--help' for more information."
exit 1
fi

eval set -- "${opts}"

while true; do
case "${1}" in
--help)
shift
echo "Options:"
echo "--help|-h specify the flags"
echo "--ref specify the reference of pr"
echo "--k8s_version specify the kubernetes version"
echo "--test_type specify the test type functest|helmtest"

echo " "
echo "Sample Usage:"
echo "./single-node-k8s.sh --ref=pull/123/head"
exit 0
;;
--k8s_version)
shift
k8s_version=${1}
echo "${k8s_version}"
;;
--test_type)
shift
test_type=${1}
echo "${test_type}"
;;
--ref)
shift
ref=${1}
echo "${ref}"
;;
--)
shift
break
;;
esac
shift
done

function set_env() {
export GOPATH="/opt/build/go"
export GOLANGCI_VERSION="v1.21.0"
export GO111MODULE="on"
export GOSEC_VERSION="2.0.0"
export TEST_COVERAGE="stdout"
export GO_METALINTER_THREADS=1
export HELM_VERSION="v3.1.2"
export VM_DRIVER="none"
export MINIKUBE_VERSION="v1.6.0"
export CHANGE_MINIKUBE_NONE_USER=true
export KUBECONFIG="$HOME/.kube/config"
export CEPH_CSI_RUN_ALL_TESTS=true
# the CentOS CI has some network conflicts with the default pod network
export POD_NW_CIDR='192.168.123.0/24'

# script/minikube.sh installs under /usr/local/bin
export PATH=$PATH:/usr/local/bin
}

check_errs()
{
if [ "${1}" -ne "0" ]; then
echo "ERROR # ${1} : ${2}"
exit "${1}"
fi
}

install_docker()
{
# TODO: use podman, but minikube currently depends on Docker
yum -y install docker-latest
# minikube/kubelet is configured with cgroupfs
sed 's/native.cgroupdriver=systemd/native.cgroupdriver=cgroupfs/' < /usr/lib/systemd/system/docker-latest.service > /etc/systemd/system/docker.service
# start the docker service (actually docker-latest, but minikube checks for 'docker.service')
systemctl daemon-reload
systemctl enable --now docker
}

# Set environment variables
set_env

if [ "$test_type" = "functest" ]; then
cd ${GOPATH}/src/github.com/ceph/ceph-csi || exit
# sh scripts/skip-doc-change.sh "${ref}"
# check_errs $? "Error occured while checking document changes"

make image-cephcsi
check_errs $? "Error occured during image creation"

install_docker

# TODO: maybe need to import the image from podman into docker?

make containerized-build TARGET=e2e.test
check_errs $? "Error occured during build of e2e executable"

# running e2e.test requires librados and librbd
yum -y install librados2 librbd1

sh scripts/travis-functest.sh "${k8s_version}"
check_errs $? "Error occured while running functional tests"

elif [ "$test_type" = "helmtest" ]; then
cd ${GOPATH}/src/github.com/ceph/ceph-csi || exit
# sh scripts/skip-doc-change.sh "${ref}"
# check_errs $? "Error occured while checking document changes"

make image-cephcsi
check_errs $? "Error occured during image creation"

install_docker

sh scripts/travis-helmtest.sh "${k8s_version}"
check_errs $? "Error occured while running helm tests"

else
echo "test_type can be functest|helmtest"
fi

0 comments on commit 1feb9d9

Please sign in to comment.