]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/cephadm/test_adoption.sh
83e11a40ace6409e683bd1bb8a97be8ba27438d3
[ceph.git] / ceph / qa / workunits / cephadm / test_adoption.sh
1 #!/bin/bash -ex
2
3 SCRIPT_NAME=$(basename ${BASH_SOURCE[0]})
4 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5 CEPHADM_SRC_DIR=${SCRIPT_DIR}/../../../src/cephadm
6 CORPUS_COMMIT=50c5dd734638939facd1ed32295ce59c9a5986b4
7
8 [ -z "$SUDO" ] && SUDO=sudo
9 if [ -z "$CEPHADM" ]; then
10 CEPHADM=${CEPHADM_SRC_DIR}/cephadm
11 fi
12
13 # at this point, we need $CEPHADM set
14 if ! [ -x "$CEPHADM" ]; then
15 echo "cephadm not found. Please set \$CEPHADM"
16 exit 1
17 fi
18
19 # respawn ourselves with a shebang
20 if [ -z "$PYTHON_KLUDGE" ]; then
21 # see which pythons we should test with
22 PYTHONS=""
23 which python3 && PYTHONS="$PYTHONS python3"
24 which python2 && PYTHONS="$PYTHONS python2"
25 echo "PYTHONS $PYTHONS"
26 if [ -z "$PYTHONS" ]; then
27 echo "No PYTHONS found!"
28 exit 1
29 fi
30
31 TMPBINDIR=$(mktemp -d)
32 trap "rm -rf $TMPBINDIR" EXIT
33 ORIG_CEPHADM="$CEPHADM"
34 CEPHADM="$TMPBINDIR/cephadm"
35 for p in $PYTHONS; do
36 echo "=== re-running with $p ==="
37 ln -s `which $p` $TMPBINDIR/python
38 echo "#!$TMPBINDIR/python" > $CEPHADM
39 cat $ORIG_CEPHADM >> $CEPHADM
40 chmod 700 $CEPHADM
41 $TMPBINDIR/python --version
42 PYTHON_KLUDGE=1 CEPHADM=$CEPHADM $0
43 rm $TMPBINDIR/python
44 done
45 rm -rf $TMPBINDIR
46 echo "PASS with all of: $PYTHONS"
47 exit 0
48 fi
49
50 # combine into a single var
51 CEPHADM_BIN="$CEPHADM"
52 CEPHADM="$SUDO $CEPHADM_BIN"
53
54 ## adopt
55 CORPUS_GIT_SUBMOD="cephadm-adoption-corpus"
56 TMPDIR=$(mktemp -d)
57 git clone https://github.com/ceph/$CORPUS_GIT_SUBMOD $TMPDIR
58 trap "$SUDO rm -rf $TMPDIR" EXIT
59
60 git -C $TMPDIR checkout $CORPUS_COMMIT
61 CORPUS_DIR=${TMPDIR}/archive
62
63 for subdir in `ls ${CORPUS_DIR}`; do
64 for tarfile in `ls ${CORPUS_DIR}/${subdir} | grep .tgz`; do
65 tarball=${CORPUS_DIR}/${subdir}/${tarfile}
66 FSID_LEGACY=`echo "$tarfile" | cut -c 1-36`
67 TMP_TAR_DIR=`mktemp -d -p $TMPDIR`
68 $SUDO tar xzvf $tarball -C $TMP_TAR_DIR
69 NAMES=$($CEPHADM ls --legacy-dir $TMP_TAR_DIR | jq -r '.[].name')
70 for name in $NAMES; do
71 $CEPHADM adopt \
72 --style legacy \
73 --legacy-dir $TMP_TAR_DIR \
74 --name $name
75 # validate after adopt
76 out=$($CEPHADM ls | jq '.[]' \
77 | jq 'select(.name == "'$name'")')
78 echo $out | jq -r '.style' | grep 'cephadm'
79 echo $out | jq -r '.fsid' | grep $FSID_LEGACY
80 done
81 # clean-up before next iter
82 $CEPHADM rm-cluster --fsid $FSID_LEGACY --force
83 $SUDO rm -rf $TMP_TAR_DIR
84 done
85 done
86
87 echo "OK"