From 794e3dfc808479bcdd8ed5db191166361a22ee14 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Mon, 25 Mar 2019 19:53:44 +0800 Subject: [PATCH] mon/ConfigMonitor: make 'config reset' idempotent This partially revert 1bc9c86d08cfb408768c080ed5ea1ea82325ed57. It's generally not a good idea if a command is not idempotent. Signed-off-by: xie xingguo --- qa/workunits/mon/config.sh | 21 +++++---------------- src/mon/ConfigMonitor.cc | 10 ++++------ src/mon/MonCommands.h | 5 ++--- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/qa/workunits/mon/config.sh b/qa/workunits/mon/config.sh index 2fbc4b1635563..3221e6f612033 100755 --- a/qa/workunits/mon/config.sh +++ b/qa/workunits/mon/config.sh @@ -6,19 +6,6 @@ function expect_false() if "$@"; then return 1; else return 0; fi } -# some of the commands are just not idempotent. -function without_test_dup_command() -{ - if [ -z ${CEPH_CLI_TEST_DUP_COMMAND+x} ]; then - $@ - else - local saved=${CEPH_CLI_TEST_DUP_COMMAND} - unset CEPH_CLI_TEST_DUP_COMMAND - $@ - CEPH_CLI_TEST_DUP_COMMAND=saved - fi -} - ceph config dump # value validation @@ -64,9 +51,6 @@ ceph config get mon.a debug_asok | grep 11 ceph config rm mon debug_asok ceph config get mon.a debug_asok | grep 33 ceph config rm global debug_asok -without_test_dup_command ceph config reset -ceph config get mon.a debug_asok | grep 33 -without_test_dup_command ceph config reset # help ceph config help debug_asok | grep debug_asok @@ -123,4 +107,9 @@ grep keyring $t2 expect_false grep debug_asok $t2 rm -f $t1 $t2 +expect_false ceph config reset +expect_false ceph config reset -1 +# we are at end of testing, so it's okay to revert everything +ceph config reset 0 + echo OK diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index 42a2e859e9035..b1395397e5d00 100644 --- a/src/mon/ConfigMonitor.cc +++ b/src/mon/ConfigMonitor.cc @@ -521,12 +521,10 @@ bool ConfigMonitor::prepare_command(MonOpRequestRef op) } goto update; } else if (prefix == "config reset") { - int64_t num = -1; - cmd_getval(g_ceph_context, cmdmap, "num", num); - int64_t revert_to = num; - if (revert_to < 0) // revert to last version - revert_to = version - 1; - if (revert_to > (int64_t)version) { + int64_t revert_to = -1; + cmd_getval(g_ceph_context, cmdmap, "num", revert_to); + if (revert_to < 0 || + revert_to > (int64_t)version) { err = -EINVAL; ss << "must specify a valid historical version to revert to; " << "see 'ceph config log' for a list of avialable configuration " diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 7c09aeca98ee9..26f2040bf5dd3 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -1193,9 +1193,8 @@ COMMAND("config log name=num,type=CephInt,req=False", "Show recent history of config changes", "config", "r") COMMAND("config reset " \ - "name=num,type=CephInt,range=0,req=False", - "Revert configuration to a historical version specified by , " - "or simply revert to last version", + "name=num,type=CephInt,range=0", + "Revert configuration to a historical version specified by ", "config", "rw") COMMAND("config generate-minimal-conf", "Generate a minimal ceph.conf file", -- 2.39.5