From 3276258b1a9123caec8d635aa1a2de3ef02201e6 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Thu, 25 Jun 2015 17:15:39 -0700 Subject: [PATCH] tools, test: Some ceph-objectstore-tool error handling fixes Improve various error messages generated with invalid syntax Add test cases for most of these error messages Signed-off-by: David Zafman (cherry picked from commit 127a5f191d3d2442edd3a3fa820006bca3a08c93) Conflicts: src/test/ceph_objectstore_tool.py (trivial) --- src/test/ceph_objectstore_tool.py | 17 +++++++++++++++-- src/tools/ceph_objectstore_tool.cc | 18 +++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/test/ceph_objectstore_tool.py b/src/test/ceph_objectstore_tool.py index 2a2fd55b84d05..3f51d427871f4 100755 --- a/src/test/ceph_objectstore_tool.py +++ b/src/test/ceph_objectstore_tool.py @@ -174,7 +174,8 @@ def test_failure(cmd, errmsg): logging.info("Correctly failed with message \"" + errmsg + "\"") return 0 else: - logging.error("Bad message to stderr \"" + e.output + "\"") + errmsg = e.output.split('\n')[0] + logging.error("Bad message to stderr \"" + errmsg + "\"") return 1 @@ -650,7 +651,7 @@ def main(argv): cmd = (CFSD_PREFIX + "--op remove").format(osd=ONEOSD) ERRORS += test_failure(cmd, "Must provide pgid") - # Don't secify a --op + # Don't secify a --op nor object command cmd = CFSD_PREFIX.format(osd=ONEOSD) ERRORS += test_failure(cmd, "Must provide --op or object command...") @@ -658,6 +659,18 @@ def main(argv): cmd = (CFSD_PREFIX + "--op oops").format(osd=ONEOSD) ERRORS += test_failure(cmd, "Must provide --op (info, log, remove, export, import, list, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal, dump-super)") + # Provide just the object param not a command + cmd = (CFSD_PREFIX + "object").format(osd=ONEOSD) + ERRORS += test_failure(cmd, "Invalid syntax, missing command") + + # Provide an object name that doesn't exist + cmd = (CFSD_PREFIX + "NON_OBJECT get-bytes").format(osd=ONEOSD) + ERRORS += test_failure(cmd, "No object id 'NON_OBJECT' found") + + # Provide an invalid object command + cmd = (CFSD_PREFIX + "--pgid {pg} '' notacommand").format(osd=ONEOSD, pg=ONEPG) + ERRORS += test_failure(cmd, "Unknown object command 'notacommand'") + TMPFILE = r"/tmp/tmp.{pid}".format(pid=pid) ALLPGS = OBJREPPGS + OBJECPGS OSDS = get_osds(ALLPGS[0], OSDDIR) diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 0b8b054f3d499..048e176f92d27 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -2791,12 +2791,7 @@ int main(int argc, char **argv) usage(desc); myexit(1); } - if (op != "list" && vm.count("object") && !vm.count("objcmd")) { - cerr << "Invalid syntax, missing command" << std::endl; - usage(desc); - myexit(1); - } - if (!vm.count("op") && !(vm.count("object") && vm.count("objcmd"))) { + if (!vm.count("op") && !vm.count("object")) { cerr << "Must provide --op or object command..." << std::endl; usage(desc); myexit(1); @@ -2806,6 +2801,11 @@ int main(int argc, char **argv) usage(desc); myexit(1); } + if (op != "list" && vm.count("object") && !vm.count("objcmd")) { + cerr << "Invalid syntax, missing command" << std::endl; + usage(desc); + myexit(1); + } outistty = isatty(STDOUT_FILENO); file_fd = fd_none; @@ -2992,10 +2992,10 @@ int main(int argc, char **argv) if (lookup.size() != 1) { stringstream ss; if (lookup.size() == 0) - ss << objcmd << ": " << cpp_strerror(ENOENT); + ss << "No object id '" << object << "' found"; else - ss << "expected a single object named '" << object - << "' but got " << lookup.size() << " instead"; + ss << "Found " << lookup.size() << " objects with id '" << object + << "', please use a JSON spec from --op list instead"; throw std::runtime_error(ss.str()); } pair found = lookup.pop(); -- 2.39.5