]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigMonitor: make 'config reset' idempotent 27155/head
authorxie xingguo <xie.xingguo@zte.com.cn>
Mon, 25 Mar 2019 11:53:44 +0000 (19:53 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Mon, 25 Mar 2019 12:35:42 +0000 (20:35 +0800)
This partially revert 1bc9c86d08cfb408768c080ed5ea1ea82325ed57.
It's generally not a good idea if a command is not idempotent.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
qa/workunits/mon/config.sh
src/mon/ConfigMonitor.cc
src/mon/MonCommands.h

index 2fbc4b16355632298d98a7a2af506624c11d57e1..3221e6f612033facb84a3b65f349c73b7441a564 100755 (executable)
@@ -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
index 42a2e859e9035608c104761ca00b7b86cdfbd84b..b1395397e5d0011e38f2b065d461bf82f8dec723 100644 (file)
@@ -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 "
index 7c09aeca98ee9f1400a0dc2b819029728cdd6f9e..26f2040bf5dd3a22e82988bfd23e58f7d281e56d 100644 (file)
@@ -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 <num>, "
-        "or simply revert to last version",
+       "name=num,type=CephInt,range=0",
+       "Revert configuration to a historical version specified by <num>",
        "config", "rw")
 COMMAND("config generate-minimal-conf",
        "Generate a minimal ceph.conf file",