From: David Zafman Date: Fri, 26 Jun 2015 00:15:39 +0000 (-0700) Subject: tools, test: Some ceph-objectstore-tool error handling fixes X-Git-Tag: v9.0.3~48^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F5197%2Fhead;p=ceph.git 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 --- diff --git a/src/test/ceph_objectstore_tool.py b/src/test/ceph_objectstore_tool.py index e75ba7fb9b79..7d2d48a82dc0 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 @@ -653,7 +654,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...") @@ -661,6 +662,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, meta-list)") + # 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 80b08b35cbe5..ea7e6759098f 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -1941,12 +1941,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); @@ -1956,6 +1951,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; @@ -2144,10 +2144,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();