]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
Merge PR #41509 into master
authorSage Weil <sage@newdream.net>
Mon, 7 Jun 2021 14:02:52 +0000 (10:02 -0400)
committerSage Weil <sage@newdream.net>
Mon, 7 Jun 2021 14:02:52 +0000 (10:02 -0400)
* refs/pull/41509/head:
common/cmdparse: fix CephBool validation for tell commands
mgr/nfs: fix 'nfs export create' argument order
common/cmdparse: emit proper json
mon/MonCommands: add -- seperator to example
qa/tasks/cephfs/test_nfs: fix export create test
mgr: make mgr commands compat with pre-quincy mon
doc/_ext/ceph_commands: handle non-positional args in docs
mgr: fix reweight-by-utilization cephbool flag
mon/MonCommands: convert some CephChoices to CephBool
mgr/k8sevents: fix help strings
pybind/mgr/mgr_module: fix help desc formatting
mgr/orchestrator: clean up 'orch {daemon add,apply} rgw' args
mgr/orchestrator: add end_positional to a few methods
mgr/orchestrator: reformat a few methods
pybind/ceph_argparse: stop parsing when we run out of positional args
pybind/ceph_argparse: remove dead code
pybind/mgr/mgr_module: infer non-positional args
pybind/mgr/mgr_module: add separator for non-positional args
command/cmdparse: use -- to separate positional from non-positional args
pybind/ceph_argparse: adjust help text for non-positional args
pybind/ceph_argparse: track a 'positional' property on cli args

Reviewed-by: Kefu Chai <kchai@redhat.com>
1  2 
qa/tasks/cephfs/test_nfs.py
src/common/cmdparse.cc
src/common/cmdparse.h
src/mgr/DaemonServer.cc
src/mon/MgrMonitor.cc
src/mon/Monitor.cc
src/mon/MonmapMonitor.cc
src/mon/OSDMonitor.cc
src/pybind/mgr/mgr_module.py
src/pybind/mgr/nfs/module.py
src/pybind/mgr/orchestrator/module.py

Simple merge
index 6817f6454115f1ba910731e6846af9dc63f8f865,9d28a5c57dbf6b11a31633d99714dd59ffc8daf5..d02a2b99bbd11913f485cb04e9d513ebe2977d76
@@@ -645,30 -691,47 +691,49 @@@ bool cmd_getval(const cmdmap_t& cmdmap
     * so earlier clients are sent a CephChoices argdesc instead, and will
     * send us a "--foo-bar" value string for boolean arguments.
     */
 -  if (cmdmap.count(k)) {
 +  auto found = cmdmap.find(k);
 +  if (found == cmdmap.end()) {
 +    return false;
 +  }
 +  try {
 +    val = boost::get<bool>(found->second);
 +    return true;
 +  } catch (boost::bad_get&) {
      try {
 -      val = boost::get<bool>(cmdmap.find(k)->second);
 -      return true;
 -    } catch (boost::bad_get&) {
 -      try {
 -        std::string expected = "--" + k;
 -        std::replace(expected.begin(), expected.end(), '_', '-');
 -
 -        std::string v_str = boost::get<std::string>(cmdmap.find(k)->second);
 -        if (v_str == expected) {
 -          val = true;
 -          return true;
 -        } else {
 -          throw bad_cmd_get(k, cmdmap);
 -        }
 -      } catch (boost::bad_get&) {
 -        throw bad_cmd_get(k, cmdmap);
 +      std::string expected{"--"};
 +      expected += k;
 +      std::replace(expected.begin(), expected.end(), '_', '-');
 +
 +      std::string v_str = boost::get<std::string>(found->second);
 +      if (v_str == expected) {
 +      val = true;
 +      return true;
 +      } else {
 +      throw bad_cmd_get(k, cmdmap);
        }
 +    } catch (boost::bad_get&) {
 +      throw bad_cmd_get(k, cmdmap);
      }
    }
 -  return false;
  }
  
+ bool cmd_getval_compat_cephbool(
+   const cmdmap_t& cmdmap,
+   const std::string& k, bool& val)
+ {
+   try {
+     return cmd_getval(cmdmap, k, val);
+   } catch (bad_cmd_get& e) {
+     // try as legacy/compat CephChoices
+     std::string t;
+     if (!cmd_getval(cmdmap, k, t)) {
+       return false;
+     }
+     std::string expected = "--"s + k;
+     std::replace(expected.begin(), expected.end(), '_', '-');
+     val = (t == expected);
+     return true;
+   }
+ }
  }
index 0dec47773a3988b845a8e520830b3d421b5697a6,4d5160d3333b24bbb656421cfdcef80157017e5b..f6edf0cb88dfa45bfb9bde22517c663db0f326ec
@@@ -60,50 -57,44 +60,54 @@@ struct bad_cmd_get : public std::except
  };
  
  bool cmd_getval(const cmdmap_t& cmdmap,
 -              const std::string& k, bool& val);
 +              std::string_view k, bool& val);
  
+ bool cmd_getval_compat_cephbool(
+   const cmdmap_t& cmdmap,
+   const std::string& k, bool& val);
  template <typename T>
  bool cmd_getval(const cmdmap_t& cmdmap,
 -              const std::string& k, T& val)
 +              std::string_view k, T& val)
  {
 -  if (cmdmap.count(k)) {
 -    try {
 -      val = boost::get<T>(cmdmap.find(k)->second);
 -      return true;
 -    } catch (boost::bad_get&) {
 -      throw bad_cmd_get(k, cmdmap);
 -    }
 +  auto found = cmdmap.find(k);
 +  if (found == cmdmap.end()) {
 +    return false;
 +  }
 +  try {
 +    val = boost::get<T>(found->second);
 +    return true;
 +  } catch (boost::bad_get&) {
 +    throw bad_cmd_get(k, cmdmap);
    }
 -  return false;
  }
  
 -// with default
 -
  template <typename T>
 -bool cmd_getval(
 -  const cmdmap_t& cmdmap, const std::string& k,
 -  T& val, const T& defval)
 +std::optional<T> cmd_getval(const cmdmap_t& cmdmap,
 +                          std::string_view k)
  {
 -  if (cmdmap.count(k)) {
 -    try {
 -      val = boost::get<T>(cmdmap.find(k)->second);
 -      return true;
 -    } catch (boost::bad_get&) {
 -      throw bad_cmd_get(k, cmdmap);
 -    }
 +  T ret;
 +  if (const bool found = cmd_getval(cmdmap, k, ret); found) {
 +    return std::make_optional(std::move(ret));
    } else {
 -    val = defval;
 -    return true;
 +    return std::nullopt;
 +  }
 +}
 +
 +// with default
 +
 +template <typename T, typename V>
 +T cmd_getval_or(const cmdmap_t& cmdmap, std::string_view k,
 +              const V& defval)
 +{
 +  auto found = cmdmap.find(k);
 +  if (found == cmdmap.end()) {
 +    return T(defval);
 +  }
 +  try {
 +    return boost::get<T>(cmdmap.find(k)->second);
 +  } catch (boost::bad_get&) {
 +    throw bad_cmd_get(k, cmdmap);
    }
  }
  
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge