Skip to content

Commit

Permalink
mon: test 'mon feature' cli
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Eduardo Luis <joao@suse.de>
  • Loading branch information
jecluis committed Feb 22, 2017
1 parent 6e9c2be commit a3e9ca8
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qa/workunits/cephtool/test.sh
Expand Up @@ -1045,6 +1045,12 @@ function test_mon_mon()
[ -s $TEMP_DIR/monmap.$$ ]
# ceph mon tell
ceph mon_status

# test mon features
ceph mon feature list
ceph mon feature set kraken --yes-i-really-mean-it
expect_false ceph mon feature set abcd
expect_false ceph mon feature set abcd --yes-i-really-mean-it
}

function test_mon_osd()
Expand Down
118 changes: 118 additions & 0 deletions src/test/mon/misc.sh
Expand Up @@ -150,6 +150,124 @@ function TEST_no_segfault_for_bad_keyring() {
teardown $dir || return 1
}

function jq_success() {
input="$1"
filter="$2"
expects="\"$3\""

in_escaped=$(printf %s "$input" | sed "s/'/'\\\\''/g")
filter_escaped=$(printf %s "$filter" | sed "s/'/'\\\\''/g")

ret=$(echo "$in_escaped" | jq "$filter_escaped")
if [[ "$ret" == "true" ]]; then
return 0
elif [[ -n "$expects" ]]; then
if [[ "$ret" == "$expects" ]]; then
return 0
fi
fi
return 1
input=$1
filter=$2
expects="$3"

ret="$(echo $input | jq \"$filter\")"
if [[ "$ret" == "true" ]]; then
return 0
elif [[ -n "$expects" && "$ret" == "$expects" ]]; then
return 0
fi
return 1
}

function TEST_mon_features() {
local dir=$1
setup $dir || return 1

fsid=$(uuidgen)
MONA=127.0.0.1:7127 # git grep '\<7127\>' ; there must be only one
MONB=127.0.0.1:7128 # git grep '\<7128\>' ; there must be only one
MONC=127.0.0.1:7129 # git grep '\<7129\>' ; there must be only one
CEPH_ARGS_orig=$CEPH_ARGS
CEPH_ARGS="--fsid=$fsid --auth-supported=none "
CEPH_ARGS+="--mon-initial-members=a,b,c "
CEPH_ARGS+="--mon-host=$MONA,$MONB,$MONC "

run_mon $dir a --public-addr $MONA || return 1
run_mon $dir b --public-addr $MONB || return 1
timeout 120 ceph -s > /dev/null || return 1

# NOTE:
# jq only support --exit-status|-e from version 1.4 forwards, which makes
# returning on error waaaay prettier and straightforward.
# However, the current automated upstream build is running with v1.3,
# which has no idea what -e is. Hence the convoluted error checking we
# need. Sad.
# The next time someone changes this code, please check if v1.4 is now
# a thing, and, if so, please change these to use -e. Thanks.

# jq '.all.supported | select([.[] == "foo"] | any)'

# expect monmap to contain 3 monitors (a, b, and c)
jqinput="$(ceph mon_status --format=json 2>/dev/null)"
jq_success "$jqinput" '.monmap.mons | length == 3' || return 1
# quorum contains two monitors
jq_success "$jqinput" '.quorum | length == 2' || return 1
# quorum's monitor features contain kraken and luminous
jqfilter='.features.quorum_mon[]|select(. == "kraken")'
jq_success "$jqinput" "$jqfilter" "kraken" || return 1
jqfilter='.features.quorum_mon[]|select(. == "luminous")'
jq_success "$jqinput" "$jqfilter" "luminous" || return 1

# monmap must have no persistent features set, because we
# don't currently have a quorum made out of all the monitors
# in the monmap.
jqfilter='.monmap.features.persistent | length == 0'
jq_success "$jqinput" "$jqfilter" || return 1

# nor do we have any optional features, for that matter.
jqfilter='.monmap.features.optional | length == 0'
jq_success "$jqinput" "$jqfilter" || return 1

# validate 'mon feature list'

jqinput="$(ceph mon feature list --format=json 2>/dev/null)"
# 'kraken' and 'luminous' are supported
jqfilter='.all.supported[] | select(. == "kraken")'
jq_success "$jqinput" "$jqfilter" "kraken" || return 1
jqfilter='.all.supported[] | select(. == "luminous")'
jq_success "$jqinput" "$jqfilter" "luminous" || return 1

# start third monitor
run_mon $dir c --public-addr $MONC || return 1

wait_for_quorum 300 3 || return 1

timeout 300 ceph -s > /dev/null || return 1

jqinput="$(ceph mon_status --format=json 2>/dev/null)"
# expect quorum to have all three monitors
echo "$jqinput" | jq -e '.quorum | length == 3' || return 1
# quorum's monitor features contain kraken and luminous
jqfilter='.features.quorum_mon[]|select(. == "kraken")'
echo "$jqinput" | jq -e "$jqfilter" || return 1
jqfilter='.features.quorum_mon[]|select(. == "luminous")'
echo "$jqinput" | jq -e "$jqfilter" || return 1

# monmap must have no both 'kraken' and 'luminous' persistent
# features set.
jqfilter='.monmap.features.persistent | length == 2'
jq_success "$jqinput" "$jqfilter" || return 1
jqfilter='.monmap.features.persistent[]|select(. == "kraken")'
jq_success "$jqinput" "$jqfilter" "kraken" || return 1
jqfilter='.monmap.features.persistent[]|select(. == "luminous")'
jq_success "$jqinput" "$jqfilter" "luminous" || return 1

CEPH_ARGS=$CEPH_ARGS_orig
# that's all folks. thank you for tuning in.
teardown $dir || return 1
}

main misc "$@"

# Local Variables:
Expand Down

0 comments on commit a3e9ca8

Please sign in to comment.