2019-10-23 15:54:33 +00:00
|
|
|
#!/bin/bash -ex
|
|
|
|
|
2019-11-15 16:05:26 +00:00
|
|
|
SCRIPT_NAME=$(basename ${BASH_SOURCE[0]})
|
2019-11-13 23:28:21 +00:00
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
2019-11-03 16:09:06 +00:00
|
|
|
FSID='00000000-0000-0000-0000-0000deadbeef'
|
2019-11-13 23:28:21 +00:00
|
|
|
FSID_LEGACY='00000000-0000-0000-0000-ffffdeadbeef'
|
|
|
|
|
2019-11-06 15:24:17 +00:00
|
|
|
# images that are used
|
|
|
|
IMAGE_MASTER=${IMAGE_MASTER:-'ceph/daemon-base:latest-master-devel'}
|
|
|
|
IMAGE_NAUTILUS=${IMAGE_NAUTILUS:-'ceph/daemon-base:latest-nautilus'}
|
|
|
|
IMAGE_MIMIC=${IMAGE_MIMIC:-'ceph/daemon-base:latest-mimic'}
|
2019-11-15 16:05:26 +00:00
|
|
|
|
2019-12-11 20:03:40 +00:00
|
|
|
CORPUS_GIT_SUBMOD="cephadm-adoption-corpus"
|
2019-12-06 22:00:36 +00:00
|
|
|
TMPDIR=$(mktemp -d)
|
|
|
|
trap "rm -rf $TMPDIR" EXIT
|
|
|
|
git clone https://github.com/ceph/$CORPUS_GIT_SUBMOD $TMPDIR
|
|
|
|
CORPUS_DIR=${TMPDIR}/archive
|
2019-12-04 22:50:46 +00:00
|
|
|
TEST_TARS=$(find ${CORPUS_DIR} -type f -iname *.tgz)
|
2019-11-03 16:09:06 +00:00
|
|
|
|
2019-11-15 16:05:26 +00:00
|
|
|
OSD_IMAGE_NAME="${SCRIPT_NAME%.*}_osd.img"
|
|
|
|
OSD_IMAGE_SIZE='6G'
|
|
|
|
OSD_TO_CREATE=6
|
|
|
|
OSD_VG_NAME=${SCRIPT_NAME%.*}
|
|
|
|
OSD_LV_NAME=${SCRIPT_NAME%.*}
|
|
|
|
|
2019-11-03 16:09:06 +00:00
|
|
|
[ -z "$SUDO" ] && SUDO=sudo
|
|
|
|
|
2019-12-11 19:57:45 +00:00
|
|
|
if [ -z "$CEPHADM" ]; then
|
|
|
|
CEPHADM=${SCRIPT_DIR}/../../../src/cephadm/cephadm
|
2019-11-03 16:09:06 +00:00
|
|
|
fi
|
|
|
|
|
2019-12-11 19:57:45 +00:00
|
|
|
# at this point, we need $CEPHADM set
|
|
|
|
if ! [ -x "$CEPHADM" ]; then
|
|
|
|
echo "cephadm not found. Please set \$CEPHADM"
|
2019-11-06 15:01:25 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-03 16:09:06 +00:00
|
|
|
# respawn ourselves with a shebang
|
2019-10-25 21:20:46 +00:00
|
|
|
PYTHONS="python3 python2" # which pythons we test
|
|
|
|
if [ -z "$PYTHON_KLUDGE" ]; then
|
2019-12-06 22:00:36 +00:00
|
|
|
TMPBINDIR=$(mktemp -d)
|
2019-12-05 14:53:29 +00:00
|
|
|
trap "rm -rf $TMPBINDIR" EXIT
|
2019-12-11 19:57:45 +00:00
|
|
|
ORIG_CEPHADM="$CEPHADM"
|
|
|
|
CEPHADM="$TMPBINDIR/cephadm"
|
2019-10-25 21:20:46 +00:00
|
|
|
for p in $PYTHONS; do
|
|
|
|
echo "=== re-running with $p ==="
|
2019-11-03 16:09:06 +00:00
|
|
|
ln -s `which $p` $TMPBINDIR/python
|
2019-12-11 19:57:45 +00:00
|
|
|
echo "#!$TMPBINDIR/python" > $CEPHADM
|
|
|
|
cat $ORIG_CEPHADM >> $CEPHADM
|
|
|
|
chmod 700 $CEPHADM
|
2019-11-03 16:09:06 +00:00
|
|
|
$TMPBINDIR/python --version
|
2019-12-11 19:57:45 +00:00
|
|
|
PYTHON_KLUDGE=1 CEPHADM=$CEPHADM $0
|
2019-10-25 21:20:46 +00:00
|
|
|
rm $TMPBINDIR/python
|
|
|
|
done
|
|
|
|
rm -rf $TMPBINDIR
|
|
|
|
echo "PASS with all of: $PYTHONS"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2019-12-09 16:53:31 +00:00
|
|
|
# add image to args
|
2019-12-11 19:57:45 +00:00
|
|
|
CEPHADM_ARGS="$CEPHADM_ARGS --image $IMAGE_MASTER"
|
2019-12-09 16:53:31 +00:00
|
|
|
|
|
|
|
# combine into a single var
|
2019-12-11 19:57:45 +00:00
|
|
|
CEPHADM_BIN="$CEPHADM"
|
|
|
|
CEPHADM="$SUDO $CEPHADM_BIN $CEPHADM_ARGS"
|
2019-12-09 16:53:31 +00:00
|
|
|
|
2019-10-23 15:54:33 +00:00
|
|
|
# clean up previous run(s)?
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM rm-cluster --fsid $FSID --force
|
|
|
|
$CEPHADM rm-cluster --fsid $FSID_LEGACY --force
|
2019-11-15 16:05:26 +00:00
|
|
|
vgchange -an $OSD_VG_NAME || true
|
2019-12-02 19:33:27 +00:00
|
|
|
loopdev=$($SUDO losetup -a | grep $(basename $OSD_IMAGE_NAME) | awk -F : '{print $1}')
|
2019-11-15 16:05:26 +00:00
|
|
|
if ! [ "$loopdev" = "" ]; then
|
2019-12-02 19:33:27 +00:00
|
|
|
$SUDO losetup -d $loopdev
|
2019-11-15 16:05:26 +00:00
|
|
|
fi
|
2019-10-23 15:54:33 +00:00
|
|
|
|
|
|
|
function expect_false()
|
|
|
|
{
|
|
|
|
set -x
|
|
|
|
if "$@"; then return 1; else return 0; fi
|
|
|
|
}
|
|
|
|
|
2019-11-21 20:41:51 +00:00
|
|
|
## prepare + check host
|
2019-12-11 19:57:45 +00:00
|
|
|
$SUDO $CEPHADM check-host
|
2019-11-21 20:41:51 +00:00
|
|
|
|
2019-10-23 15:54:33 +00:00
|
|
|
## version + --image
|
2019-12-11 19:57:45 +00:00
|
|
|
$SUDO CEPHADM_IMAGE=$IMAGE_NAUTILUS $CEPHADM_BIN version
|
|
|
|
$SUDO CEPHADM_IMAGE=$IMAGE_NAUTILUS $CEPHADM_BIN version \
|
2019-10-23 15:54:33 +00:00
|
|
|
| grep 'ceph version 14'
|
2019-12-11 19:57:45 +00:00
|
|
|
$SUDO $CEPHADM_BIN --image $IMAGE_MIMIC version
|
|
|
|
$SUDO $CEPHADM_BIN --image $IMAGE_MIMIC version \
|
2019-10-23 15:54:33 +00:00
|
|
|
| grep 'ceph version 13'
|
2019-12-11 19:57:45 +00:00
|
|
|
$SUDO $CEPHADM_BIN --image $IMAGE_MASTER version | grep 'ceph version'
|
2019-10-23 15:54:33 +00:00
|
|
|
|
|
|
|
# try force docker; this won't work if docker isn't installed
|
2019-12-11 19:57:45 +00:00
|
|
|
which docker && ( $CEPHADM --docker version | grep 'ceph version' )
|
2019-10-23 15:54:33 +00:00
|
|
|
|
2019-10-24 13:41:33 +00:00
|
|
|
## test shell before bootstrap, when crash dir isn't (yet) present on this host
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM shell -- ceph -v | grep 'ceph version'
|
|
|
|
$CEPHADM shell --fsid $FSID -- ceph -v | grep 'ceph version'
|
2019-10-24 13:41:33 +00:00
|
|
|
|
2019-10-23 15:54:33 +00:00
|
|
|
## bootstrap
|
|
|
|
ORIG_CONFIG=`mktemp -p $TMPDIR`
|
|
|
|
CONFIG=`mktemp -p $TMPDIR`
|
|
|
|
KEYRING=`mktemp -p $TMPDIR`
|
|
|
|
IP=127.0.0.1
|
|
|
|
cat <<EOF > $ORIG_CONFIG
|
|
|
|
[global]
|
2019-12-06 21:43:23 +00:00
|
|
|
log to file = true
|
2019-10-23 15:54:33 +00:00
|
|
|
EOF
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM bootstrap \
|
2019-10-23 15:54:33 +00:00
|
|
|
--mon-id a \
|
|
|
|
--mgr-id x \
|
|
|
|
--mon-ip $IP \
|
|
|
|
--fsid $FSID \
|
|
|
|
--config $ORIG_CONFIG \
|
|
|
|
--output-config $CONFIG \
|
2019-11-20 02:41:17 +00:00
|
|
|
--output-keyring $KEYRING \
|
|
|
|
--allow-overwrite
|
2019-10-23 15:54:33 +00:00
|
|
|
test -e $CONFIG
|
|
|
|
test -e $KEYRING
|
|
|
|
rm -f $ORIG_CONFIG
|
|
|
|
|
|
|
|
$SUDO test -e /var/log/ceph/$FSID/ceph-mon.a.log
|
|
|
|
$SUDO test -e /var/log/ceph/$FSID/ceph-mgr.x.log
|
|
|
|
|
|
|
|
for u in ceph.target \
|
|
|
|
ceph-$FSID.target \
|
|
|
|
ceph-$FSID@mon.a \
|
|
|
|
ceph-$FSID@mgr.x; do
|
|
|
|
systemctl is-enabled $u
|
|
|
|
systemctl is-active $u
|
|
|
|
done
|
|
|
|
systemctl | grep system-ceph | grep -q .slice # naming is escaped and annoying
|
|
|
|
|
2019-10-23 16:25:12 +00:00
|
|
|
# check ceph -s works (via shell w/ passed config/keyring)
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM shell --fsid $FSID --config $CONFIG --keyring $KEYRING -- \
|
2019-10-23 16:25:12 +00:00
|
|
|
ceph -s | grep $FSID
|
|
|
|
|
2019-10-23 15:54:33 +00:00
|
|
|
## ls
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM ls | jq '.[]' | jq 'select(.name == "mon.a").fsid' \
|
2019-10-23 15:54:33 +00:00
|
|
|
| grep $FSID
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM ls | jq '.[]' | jq 'select(.name == "mgr.x").fsid' \
|
2019-10-23 15:54:33 +00:00
|
|
|
| grep $FSID
|
|
|
|
|
|
|
|
## deploy
|
|
|
|
# add mon.b
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM deploy --name mon.b \
|
2019-10-23 15:54:33 +00:00
|
|
|
--fsid $FSID \
|
|
|
|
--mon-ip $IP:3301 \
|
|
|
|
--keyring /var/lib/ceph/$FSID/mon.a/keyring \
|
|
|
|
--config $CONFIG
|
|
|
|
for u in ceph-$FSID@mon.b; do
|
|
|
|
systemctl is-enabled $u
|
|
|
|
systemctl is-active $u
|
|
|
|
done
|
|
|
|
|
|
|
|
# add mgr.y
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM shell --fsid $FSID --config $CONFIG --keyring $KEYRING -- \
|
2019-10-23 16:25:12 +00:00
|
|
|
ceph auth get-or-create mgr.y \
|
2019-10-23 15:54:33 +00:00
|
|
|
mon 'allow profile mgr' \
|
|
|
|
osd 'allow *' \
|
|
|
|
mds 'allow *' > $TMPDIR/keyring.mgr.y
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM deploy --name mgr.y \
|
2019-10-23 15:54:33 +00:00
|
|
|
--fsid $FSID \
|
|
|
|
--keyring $TMPDIR/keyring.mgr.y \
|
|
|
|
--config $CONFIG
|
|
|
|
for u in ceph-$FSID@mgr.y; do
|
|
|
|
systemctl is-enabled $u
|
|
|
|
systemctl is-active $u
|
|
|
|
done
|
|
|
|
for f in `seq 1 30`; do
|
2019-12-11 19:57:45 +00:00
|
|
|
if $CEPHADM shell --fsid $FSID \
|
2019-10-23 16:25:12 +00:00
|
|
|
--config $CONFIG --keyring $KEYRING -- \
|
|
|
|
ceph -s -f json-pretty \
|
2019-10-23 15:54:33 +00:00
|
|
|
| jq '.mgrmap.num_standbys' | grep -q 1 ; then break; fi
|
|
|
|
sleep 1
|
|
|
|
done
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM shell --fsid $FSID --config $CONFIG --keyring $KEYRING -- \
|
2019-10-23 16:25:12 +00:00
|
|
|
ceph -s -f json-pretty \
|
2019-10-23 15:54:33 +00:00
|
|
|
| jq '.mgrmap.num_standbys' | grep -q 1
|
|
|
|
|
2019-11-15 16:05:26 +00:00
|
|
|
# add osd.{1,2,..}
|
|
|
|
dd if=/dev/zero of=$TMPDIR/$OSD_IMAGE_NAME bs=1 count=0 seek=$OSD_IMAGE_SIZE
|
2019-12-02 19:33:27 +00:00
|
|
|
loop_dev=$($SUDO losetup -f)
|
2019-11-21 00:25:09 +00:00
|
|
|
$SUDO vgremove -f $OSD_VG_NAME || true
|
2019-11-20 17:31:19 +00:00
|
|
|
$SUDO losetup $loop_dev $TMPDIR/$OSD_IMAGE_NAME
|
|
|
|
$SUDO pvcreate $loop_dev && $SUDO vgcreate $OSD_VG_NAME $loop_dev
|
2019-11-15 16:05:26 +00:00
|
|
|
for id in `seq 0 $((--OSD_TO_CREATE))`; do
|
2019-11-20 17:31:19 +00:00
|
|
|
$SUDO lvcreate -l $((100/$OSD_TO_CREATE))%VG -n $OSD_LV_NAME.$id $OSD_VG_NAME
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM shell --config $CONFIG --keyring $KEYRING -- \
|
2019-11-15 16:05:26 +00:00
|
|
|
ceph orchestrator osd create \
|
|
|
|
$(hostname):/dev/$OSD_VG_NAME/$OSD_LV_NAME.$id
|
|
|
|
done
|
|
|
|
|
2019-10-23 15:54:33 +00:00
|
|
|
## run
|
2019-10-23 16:34:46 +00:00
|
|
|
# WRITE ME
|
|
|
|
|
|
|
|
## adopt
|
2019-12-11 13:32:29 +00:00
|
|
|
if false; then
|
2019-11-13 23:28:21 +00:00
|
|
|
for tarball in $TEST_TARS; do
|
|
|
|
TMP_TAR_DIR=`mktemp -d -p $TMPDIR`
|
2019-11-20 18:40:45 +00:00
|
|
|
$SUDO tar xzvf $tarball -C $TMP_TAR_DIR
|
2019-12-11 19:57:45 +00:00
|
|
|
NAMES=$($CEPHADM ls --legacy-dir $TMP_TAR_DIR | jq -r '.[].name')
|
2019-11-13 23:28:21 +00:00
|
|
|
for name in $NAMES; do
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM adopt \
|
2019-12-09 16:53:31 +00:00
|
|
|
--style legacy \
|
|
|
|
--legacy-dir $TMP_TAR_DIR \
|
|
|
|
--name $name
|
2019-11-13 23:28:21 +00:00
|
|
|
# validate after adopt
|
2019-12-11 19:57:45 +00:00
|
|
|
out=$($CEPHADM ls | jq '.[]' \
|
2019-12-09 16:53:31 +00:00
|
|
|
| jq 'select(.name == "'$name'")')
|
2019-12-11 19:48:02 +00:00
|
|
|
echo $out | jq -r '.style' | grep 'cephadm'
|
2019-11-13 23:28:21 +00:00
|
|
|
echo $out | jq -r '.fsid' | grep $FSID_LEGACY
|
|
|
|
done
|
|
|
|
# clean-up before next iter
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM rm-cluster --fsid $FSID_LEGACY --force
|
2019-11-20 18:40:45 +00:00
|
|
|
$SUDO rm -rf $TMP_TAR_DIR
|
2019-11-13 23:28:21 +00:00
|
|
|
done
|
2019-12-11 13:32:29 +00:00
|
|
|
fi
|
2019-10-23 16:34:46 +00:00
|
|
|
|
|
|
|
## unit
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM unit --fsid $FSID --name mon.a -- is-enabled
|
|
|
|
$CEPHADM unit --fsid $FSID --name mon.a -- is-active
|
|
|
|
expect_false $CEPHADM unit --fsid $FSID --name mon.xyz -- is-active
|
|
|
|
$CEPHADM unit --fsid $FSID --name mon.a -- disable
|
|
|
|
expect_false $CEPHADM unit --fsid $FSID --name mon.a -- is-enabled
|
|
|
|
$CEPHADM unit --fsid $FSID --name mon.a -- enable
|
|
|
|
$CEPHADM unit --fsid $FSID --name mon.a -- is-enabled
|
2019-10-23 16:34:46 +00:00
|
|
|
|
2019-10-23 15:54:33 +00:00
|
|
|
## shell
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM shell -- true
|
|
|
|
$CEPHADM shell --fsid $FSID -- test -d /var/log/ceph
|
2019-10-23 16:34:46 +00:00
|
|
|
|
2019-10-23 15:54:33 +00:00
|
|
|
## enter
|
2019-12-11 19:57:45 +00:00
|
|
|
expect_false $CEPHADM enter
|
|
|
|
$CEPHADM enter --fsid $FSID --name mon.a -- test -d /var/lib/ceph/mon/ceph-a
|
|
|
|
$CEPHADM enter --fsid $FSID --name mgr.x -- test -d /var/lib/ceph/mgr/ceph-x
|
|
|
|
$CEPHADM enter --fsid $FSID --name mon.a -- pidof ceph-mon
|
|
|
|
expect_false $CEPHADM enter --fsid $FSID --name mgr.x -- pidof ceph-mon
|
|
|
|
$CEPHADM enter --fsid $FSID --name mgr.x -- pidof ceph-mgr
|
2019-10-23 15:54:33 +00:00
|
|
|
|
|
|
|
## ceph-volume
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM ceph-volume --fsid $FSID -- inventory --format=json \
|
2019-10-23 15:54:33 +00:00
|
|
|
| jq '.[]'
|
|
|
|
|
|
|
|
## rm-daemon
|
|
|
|
# mon and osd require --force
|
2019-12-11 19:57:45 +00:00
|
|
|
expect_false $CEPHADM rm-daemon --fsid $FSID --name mon.a
|
2019-10-23 15:54:33 +00:00
|
|
|
# mgr does not
|
2019-12-11 19:57:45 +00:00
|
|
|
$CEPHADM rm-daemon --fsid $FSID --name mgr.x
|
2019-10-23 15:54:33 +00:00
|
|
|
|
|
|
|
## rm-cluster
|
2019-12-11 19:57:45 +00:00
|
|
|
expect_false $CEPHADM rm-cluster --fsid $FSID
|
|
|
|
$CEPHADM rm-cluster --fsid $FSID --force
|
2019-10-23 15:54:33 +00:00
|
|
|
|
|
|
|
rm -rf $TMPDIR
|
|
|
|
echo PASS
|