Skip to content

Commit

Permalink
test: Add tests for pool recovery priority conversion
Browse files Browse the repository at this point in the history
Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit 71d82db)
  • Loading branch information
dzafman authored and Smith Farm committed Apr 30, 2019
1 parent 3243454 commit dcf60da
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
89 changes: 89 additions & 0 deletions qa/standalone/mon/osd-pool-create.sh
Expand Up @@ -233,6 +233,95 @@ function TEST_pool_create_rep_expected_num_objects() {
fi
}

function check_pool_priority() {
local dir=$1
shift
local pools=$1
shift
local spread="$1"
shift
local results="$1"

setup $dir || return 1

EXTRA_OPTS="--debug_allow_any_pool_priority=true"
export EXTRA_OPTS
run_mon $dir a || return 1
run_mgr $dir x || return 1
run_osd $dir 0 || return 1
run_osd $dir 1 || return 1
run_osd $dir 2 || return 1

# Add pool 0 too
for i in $(seq 0 $pools)
do
num=$(expr $i + 1)
ceph osd pool create test${num} 1 1
done

wait_for_clean || return 1
for i in $(seq 0 $pools)
do
num=$(expr $i + 1)
ceph osd pool set test${num} recovery_priority $(expr $i \* $spread)
done

#grep "recovery_priority.*pool set" out/mon.a.log

bin/ceph osd dump

# Restart everything so mon converts the priorities
kill_daemons
run_mon $dir a || return 1
run_mgr $dir x || return 1
activate_osd $dir 0 || return 1
activate_osd $dir 1 || return 1
activate_osd $dir 2 || return 1
sleep 5

grep convert $dir/mon.a.log
ceph osd dump

pos=1
for i in $(ceph osd dump | grep ^pool | sed 's/.*recovery_priority //' | awk '{ print $1 }')
do
result=$(echo $results | awk "{ print \$${pos} }")
# A value of 0 is an unset value so sed/awk gets "pool"
if test $result = "0"
then
result="pool"
fi
test "$result" = "$i" || return 1
pos=$(expr $pos + 1)
done
}

function TEST_pool_pos_only_prio() {
local dir=$1
check_pool_priority $dir 20 5 "0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10" || return 1
}

function TEST_pool_neg_only_prio() {
local dir=$1
check_pool_priority $dir 20 -5 "0 0 -1 -1 -2 -2 -3 -3 -4 -4 -5 -5 -6 -6 -7 -7 -8 -8 -9 -9 -10" || return 1
}

function TEST_pool_both_prio() {
local dir=$1
check_pool_priority $dir 20 "5 - 50" "-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10" || return 1
}

function TEST_pool_both_prio_no_neg() {
local dir=$1
check_pool_priority $dir 20 "2 - 4" "-4 -2 0 0 1 1 2 2 3 3 4 5 5 6 6 7 7 8 8 9 10" || return 1
}

function TEST_pool_both_prio_no_pos() {
local dir=$1
check_pool_priority $dir 20 "2 - 36" "-10 -9 -8 -8 -7 -7 -6 -6 -5 -5 -4 -3 -3 -2 -2 -1 -1 0 0 2 4" || return 1
}


main osd-pool-create "$@"

# Local Variables:
Expand Down
1 change: 1 addition & 0 deletions src/common/legacy_config_opts.h
Expand Up @@ -1548,3 +1548,4 @@ OPTION(fake_statfs_for_testing, OPT_INT) // Set a value for kb and compute kb_us
OPTION(rgw_sts_token_introspection_url, OPT_STR) // url for introspecting web tokens
OPTION(rgw_sts_client_id, OPT_STR) // Client Id
OPTION(rgw_sts_client_secret, OPT_STR) // Client Secret
OPTION(debug_allow_any_pool_priority, OPT_BOOL)
4 changes: 4 additions & 0 deletions src/common/options.cc
Expand Up @@ -8137,6 +8137,10 @@ std::vector<Option> get_mds_client_options() {
Option("fake_statfs_for_testing", Option::TYPE_INT, Option::LEVEL_DEV)
.set_default(0)
.set_description("Set a value for kb and compute kb_used from total of num_bytes"),

Option("debug_allow_any_pool_priority", Option::TYPE_BOOL, Option::LEVEL_DEV)
.set_default(false)
.set_description("Allow any pool priority to be set to test conversion to new range"),
});
}

Expand Down
10 changes: 6 additions & 4 deletions src/mon/OSDMonitor.cc
Expand Up @@ -7622,10 +7622,12 @@ int OSDMonitor::prepare_command_pool_set(const cmdmap_t& cmdmap,
ss << "error parsing int value '" << val << "': " << interr;
return -EINVAL;
}
if (n > OSD_POOL_PRIORITY_MAX || n < OSD_POOL_PRIORITY_MIN) {
ss << "pool recovery_priority must be between " << OSD_POOL_PRIORITY_MIN
<< " and " << OSD_POOL_PRIORITY_MAX;
return -EINVAL;
if (!g_conf()->debug_allow_any_pool_priority) {
if (n > OSD_POOL_PRIORITY_MAX || n < OSD_POOL_PRIORITY_MIN) {
ss << "pool recovery_priority must be between " << OSD_POOL_PRIORITY_MIN
<< " and " << OSD_POOL_PRIORITY_MAX;
return -EINVAL;
}
}
} else if (var == "pg_autoscale_bias") {
if (f < 0.0 || f > 1000.0) {
Expand Down

0 comments on commit dcf60da

Please sign in to comment.