From 709e39547f1d57f9f13a8b7a17e93cd65783ea2a Mon Sep 17 00:00:00 2001 From: Cedric CAFFY <cedric.caffy@cern.ch> Date: Fri, 10 May 2019 18:17:40 +0200 Subject: [PATCH] Added repack_systemtest.sh that allows to execute a repack on a specified VID with only cta-admin and eos commands Created a repack_systemtest_wrapper.sh script to allow to execute the repack_systemtest.sh in the CI Adapted the simple_repack.sh script so that it uses the repack_systemtest.sh script --- .gitlab-ci.yml | 2 +- .../orchestration/tests/repack_systemtest.sh | 110 ++++++++++++++++++ .../tests/repack_systemtest_wrapper.sh | 64 ++++++++++ .../orchestration/tests/simple_repack.sh | 28 ++++- 4 files changed, 199 insertions(+), 5 deletions(-) create mode 100755 continuousintegration/orchestration/tests/repack_systemtest.sh create mode 100755 continuousintegration/orchestration/tests/repack_systemtest_wrapper.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d09bc18fa8..489c72c913 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -176,7 +176,7 @@ repack: retry: 1 script: - export NAMESPACE="repack-${CTA_BUILD_ID}-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)" - - cd continuousintegration/orchestration/; ./run_systemtest.sh -n ${NAMESPACE} -p ${CI_PIPELINE_ID} -s tests/repack.sh -O -D -t 2400 + - cd continuousintegration/orchestration/; ./run_systemtest.sh -n ${NAMESPACE} -p ${CI_PIPELINE_ID} -s tests/repack_systemtest_wrapper.sh -O -D -t 2400 artifacts: when: always expire_in: 30 days diff --git a/continuousintegration/orchestration/tests/repack_systemtest.sh b/continuousintegration/orchestration/tests/repack_systemtest.sh new file mode 100755 index 0000000000..444be107ca --- /dev/null +++ b/continuousintegration/orchestration/tests/repack_systemtest.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +EOSINSTANCE=ctaeos + +die() { + echo "$@" 1>&2 + test -z $TAILPID || kill ${TAILPID} &> /dev/null + exit 1 +} + +usage() { cat <<EOF 1>&2 +Usage: $0 -v <vid> -b <bufferURL> +(bufferURL example : /eos/ctaeos/repack) +EOF +exit 1 +} + +testRepackBufferURL(){ + echo "Creating the repack buffer URL at root://${EOSINSTANCE}/${REPACK_BUFFER_BASEDIR}" + eos root://${EOSINSTANCE} ls -d ${REPACK_BUFFER_BASEDIR} || die "Repack bufferURL directory does not exist" + echo "Testing the insertion of a test file in the buffer URL" + for ((i=0; i<300; i++)); do + xrdcp /etc/group ${FULL_REPACK_BUFFER_URL}/testFile && break + echo -n "." + sleep 1 + done + echo OK + failed_xrdcp_test=$i + if test $failed_xrdcp_test -eq 0; then + echo "[SUCCESS]: Repack buffer URL OK" | tee -a /var/log/CI_tests + echo "Removing the test file" + eos root://${EOSINSTANCE} rm ${REPACK_BUFFER_BASEDIR}/testFile + else + echo "[ERROR]: Unable to write a file into the provided repack buffer URL." | tee -a /var/log/CI_tests + fi + echo "OK" +} + +if [ $# -lt 2 ] +then + usage +fi; + +while getopts "v:e:b:" o; do + case "${o}" in + v) + VID_TO_REPACK=${OPTARG} + ;; + e) + EOSINSTANCE=${OPTARG} + ;; + b) + REPACK_BUFFER_BASEDIR=${OPTARG} + ;; + *) + usage + ;; + esac +done +shift $((OPTIND -1)) + +if [ "x${REPACK_BUFFER_BASEDIR}" = "x" ]; then + usage + die "No repack buffer URL provided." +fi + +# get some common useful helpers for krb5 +. /root/client_helper.sh + +# Get kerberos credentials for user1 +admin_kinit +klist -s || die "Cannot get kerberos credentials for user ${USER}" + +# Get kerberos credentials for poweruser1 +eospower_kdestroy +eospower_kinit + +WAIT_FOR_REPACK_TIMEOUT=300 + +echo "Testing the repackBufferURL provided" +FULL_REPACK_BUFFER_URL=root://${EOSINSTANCE}/${REPACK_BUFFER_BASEDIR} +testRepackBufferURL + +echo "Deleting existing repack request for VID ${VID_TO_REPACK}" +admin_cta re rm --vid ${VID_TO_REPACK} + +echo "State of the tape VID ${VID_TO_REPACK} BEFORE repack" +admin_cta --json ta ls --vid ${VID_TO_REPACK} + +echo "Launching repack request for VID ${VID_TO_REPACK}, bufferURL = ${FULL_REPACK_BUFFER_URL}" +admin_cta re add --vid ${VID_TO_REPACK} --justmove --bufferurl ${FULL_REPACK_BUFFER_URL} + +SECONDS_PASSED=0 +while test 0 = `admin_cta re ls --vid ${VID_TO_REPACK} | grep -E "Complete|Failed" | wc -l`; do + echo "Waiting for repack request on tape ${VID_TO_REPACK} to be complete: Seconds passed = $SECONDS_PASSED" + sleep 1 + let SECONDS_PASSED=SECONDS_PASSED+1 + + if test ${SECONDS_PASSED} == ${WAIT_FOR_REPACK_TIMEOUT}; then + echo "Timed out after ${WAIT_FOR_REPACK_TIMEOUT} seconds waiting for tape ${VID_TO_REPACK} to be repacked" + exit 1 + fi +done +if test 1 = `admin_cta re ls -v ${VID_TO_REPACK} | grep -E "Failed" | wc -l`; then + echo "Repack failed for tape ${VID_TO_REPACK}." + exit 1 +fi + +echo "State of the tape VID ${VID_TO_REPACK} AFTER repack" +admin_cta --json ta ls --vid ${VID_TO_REPACK} \ No newline at end of file diff --git a/continuousintegration/orchestration/tests/repack_systemtest_wrapper.sh b/continuousintegration/orchestration/tests/repack_systemtest_wrapper.sh new file mode 100755 index 0000000000..cbf9adf476 --- /dev/null +++ b/continuousintegration/orchestration/tests/repack_systemtest_wrapper.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +usage() { cat <<EOF 1>&2 +Usage: $0 -n <namespace> +EOF +exit 1 +} + +while getopts "n:" o; do + case "${o}" in + n) + NAMESPACE=${OPTARG} + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + +if [ -z "${NAMESPACE}" ]; then + usage +fi + +if [ ! -z "${error}" ]; then + echo -e "ERROR:\n${error}" + exit 1 +fi + +echo "Preparing namespace for the tests" +./prepare_tests.sh -n ${NAMESPACE} + +NB_FILES=1000 +FILE_SIZE_KB=15 + +kubectl -n ${NAMESPACE} cp client_helper.sh client:/root/client_helper.sh + +echo +echo "Launching client_ar.sh on client pod" +echo " Archiving ${NB_FILES} files of ${FILE_SIZE_KB}kB each" +echo " Archiving files: xrdcp as user1" +kubectl -n ${NAMESPACE} cp client_ar.sh client:/root/client_ar.sh +kubectl -n ${NAMESPACE} exec client -- bash /root/client_ar.sh -n ${NB_FILES} -s ${FILE_SIZE_KB} -p 100 -d /eos/ctaeos/preprod -v -A || exit 1 + +REPACK_BUFFER_URL=/eos/ctaeos/repack +echo "Creating the repack buffer URL directory (${REPACK_BUFFER_URL})" +kubectl -n ${NAMESPACE} exec ctaeos -- eos mkdir ${REPACK_BUFFER_URL} +kubectl -n ${NAMESPACE} exec ctaeos -- eos chmod 1777 ${REPACK_BUFFER_URL} + +source ./repack_helper.sh +kubectl -n ${NAMESPACE} cp repack_systemtest.sh client:/root/repack_systemtest.sh + +VID_TO_REPACK=$(getFirstVidContainingFiles) +if [ "$VID_TO_REPACK" != "null" ] +then +echo + echo "Marking the tape ${VID_TO_REPACK} as full" + kubectl -n ${NAMESPACE} exec ctacli -- cta-admin ta ch -v ${VID_TO_REPACK} -f true + echo "Launching the repack test on VID ${VID_TO_REPACK}" + kubectl -n ${NAMESPACE} exec client -- bash /root/repack_systemtest.sh -v ${VID_TO_REPACK} -b ${REPACK_BUFFER_URL} +else + echo "No vid found to repack" + exit 1 +fi diff --git a/continuousintegration/orchestration/tests/simple_repack.sh b/continuousintegration/orchestration/tests/simple_repack.sh index 69ca07d17b..498170c5d1 100755 --- a/continuousintegration/orchestration/tests/simple_repack.sh +++ b/continuousintegration/orchestration/tests/simple_repack.sh @@ -31,13 +31,24 @@ source ./repack_helper.sh echo "Execution of simple_repack.sh" +REPACK_BUFFER_URL=/eos/ctaeos/repack vidToRepack1=$(getFirstVidContainingFiles) if [ "$vidToRepack1" != "null" ] then echo - writeTapeSummary $vidToRepack1 - executeRepack $vidToRepack1 + echo "Creating the repack buffer URL directory (${REPACK_BUFFER_URL})" + kubectl -n ${NAMESPACE} exec ctaeos -- eos mkdir ${REPACK_BUFFER_URL} + kubectl -n ${NAMESPACE} exec ctaeos -- eos chmod 1777 ${REPACK_BUFFER_URL} + + echo "Marking tape $vidToRepack1 as full before repacking" + kubectl -n ${NAMESPACE} exec ctacli -- cta-admin ta ch -v $vidToRepack1 -f true + + kubectl -n ${NAMESPACE} cp repack_systemtest.sh client:/root/repack_systemtest.sh + echo + echo "Launching the repack test on VID ${vidToRepack1}" + kubectl -n ${NAMESPACE} exec client -- bash /root/repack_systemtest.sh -v ${vidToRepack1} -b ${REPACK_BUFFER_URL} + echo "Reclaiming tape $vidToRepack1" executeReclaim $vidToRepack1 echo @@ -51,9 +62,18 @@ vidToRepack2=$(getFirstVidContainingFiles) if [ "$vidToRepack2" != "null" ] then echo - writeTapeSummary $vidToRepack2 - executeRepack $vidToRepack2 + echo "Creating the repack buffer URL directory (${REPACK_BUFFER_URL})" + kubectl -n ${NAMESPACE} exec ctaeos -- eos mkdir ${REPACK_BUFFER_URL} + kubectl -n ${NAMESPACE} exec ctaeos -- eos chmod 1777 ${REPACK_BUFFER_URL} + + echo "Marking tape $vidToRepack2 as full before repacking" + kubectl -n ${NAMESPACE} exec ctacli -- cta-admin ta ch -v $vidToRepack2 -f true + kubectl -n ${NAMESPACE} cp repack_systemtest.sh client:/root/repack_systemtest.sh + echo + echo "Launching the repack test on VID ${vidToRepack2}" + kubectl -n ${NAMESPACE} exec client -- bash /root/repack_systemtest.sh -v ${vidToRepack2} -b ${REPACK_BUFFER_URL} + echo "Reclaiming tape $vidToRepack2" executeReclaim $vidToRepack2 echo -- GitLab