]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigMonitor: make 'num' of 'config reset' command optional 27090/head
authorxie xingguo <xie.xingguo@zte.com.cn>
Thu, 21 Mar 2019 09:14:27 +0000 (17:14 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Mon, 25 Mar 2019 01:41:05 +0000 (09:41 +0800)
This way it can be used to fast cancel/undo the last command.
Also make the tip message a litter bit nicer..

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

index 29d22f9329a4f97fc8b3bd4e3a437aa8351b6f16..98d4e85aea6be736513b99b63f0d59447370cb8f 100755 (executable)
@@ -6,6 +6,19 @@ 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
@@ -51,6 +64,9 @@ 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
index d550af8fe1e48ef6859309278ce03cd39a65000e..6be226ed14c229dcb4f727578f71cca06e18361c 100644 (file)
@@ -524,24 +524,23 @@ bool ConfigMonitor::prepare_command(MonOpRequestRef op)
     }
     goto update;
   } else if (prefix == "config reset") {
-    int64_t num;
-    if (!cmd_getval(g_ceph_context, cmdmap, "num", num)) {
-      err = -EINVAL;
-      ss << "must specify what to revert to";
-      goto reply;
-    }
-    if (num < 0 ||
-       (num > 0 && num > (int64_t)version)) {
+    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) {
       err = -EINVAL;
-      ss << "must specify a valid version to revert to";
+      ss << "must specify a valid historical version to revert to; "
+         << "see 'ceph config log' for a list of avialable configuration "
+         << "historical versions";
       goto reply;
     }
-    if (num == (int64_t)version) {
+    if (revert_to == (int64_t)version) {
       err = 0;
       goto reply;
     }
-    ceph_assert((version_t)num < version);
-    for (int64_t v = version; v > num; --v) {
+    for (int64_t v = version; v > revert_to; --v) {
       ConfigChangeSet ch;
       load_changeset(v, &ch);
       for (auto& i : ch.diff) {
@@ -554,7 +553,7 @@ bool ConfigMonitor::prepare_command(MonOpRequestRef op)
        }
       }
     }
-    pending_description = string("reset to ") + stringify(num);
+    pending_description = string("reset to ") + stringify(revert_to);
     goto update;
   } else if (prefix == "config assimilate-conf") {
     ConfFile cf;
index 14962cf9cd1b693fbdbbe732d49a66b6031f53d8..7c09aeca98ee9f1400a0dc2b819029728cdd6f9e 100644 (file)
@@ -1192,9 +1192,10 @@ COMMAND("config assimilate-conf",
 COMMAND("config log name=num,type=CephInt,req=False",
        "Show recent history of config changes",
        "config", "r")
-COMMAND("config reset" \
-       " name=num,type=CephInt",
-       "Revert configuration to previous state",
+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",
        "config", "rw")
 COMMAND("config generate-minimal-conf",
        "Generate a minimal ceph.conf file",