simple_repack.sh 2.61 KB
Newer Older
1
#!/bin/bash
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

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

executeReclaim() {
    kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin ta reclaim -v $1
    echo "Tape $1 reclaimed"
}

executeRepack() {
36
    WAIT_FOR_REPACK_FILE_TIMEOUT=300
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    echo
    echo "Changing the tape $1 to FULL status"
    kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin ta ch -v $1 -f true
    echo "Creating the eos directory to put the retrieve files from the repack request"
    kubectl -n ${NAMESPACE} exec ctacli -ti -- rm -rf root://ctaeos.cta.svc.cluster.local:1094//eos/ctaeos/repack
    kubectl -n ${NAMESPACE} exec ctaeos -ti -- eos mkdir /eos/ctaeos/repack
    kubectl -n ${NAMESPACE} exec ctaeos -ti -- eos chmod 1777 /eos/ctaeos/repack
    echo "Removing an eventual previous repack request for tape $1"
    kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin re rm -v $1
    echo "Launching the repack request on tape $1"
    kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin re add -v $1 -m -b root://ctaeos.cta.svc.cluster.local:1094//eos/ctaeos/repack
    SECONDS_PASSED=0
    while test 0 = `kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin re ls -v $1 | grep -E "Complete|Failed" | wc -l`; do
      echo "Waiting for repack request on tape $1 to be complete: Seconds passed = $SECONDS_PASSED"
      sleep 1
      let SECONDS_PASSED=SECONDS_PASSED+1

      if test ${SECONDS_PASSED} == ${WAIT_FOR_REPACK_FILE_TIMEOUT}; then
        echo "Timed out after ${WAIT_FOR_REPACK_FILE_TIMEOUT} seconds waiting for tape $1 to be repacked"
        exit 1
      fi
    done
    if test 1 = `kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin re ls -v $1 | grep -E "Failed" | wc -l`; then
        echo "Repack failed for tape $1"
        exit 1
    fi
}

echo "Execution of simple_repack.sh"

kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin ta ls --all -h

executeRepack V01001

sleep 1

echo "Reclaiming tape V01001"
executeReclaim V01001

executeRepack V01003

echo
echo "Summary of the content of the tapes"
kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin ta ls -v V01001 -h
kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin ta ls -v V01003 -h

echo
echo "Summary of the repack requests"
85
86
87
88
89
90
kubectl -n ${NAMESPACE} exec ctacli -ti -- cta-admin re ls -h

echo "Reclaiming tape V01003"
executeReclaim V01003

echo "End of test simple_repack"