]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools, test: Some ceph-objectstore-tool error handling fixes 5197/head
authorDavid Zafman <dzafman@redhat.com>
Fri, 26 Jun 2015 00:15:39 +0000 (17:15 -0700)
committerDavid Zafman <dzafman@redhat.com>
Fri, 10 Jul 2015 17:10:43 +0000 (10:10 -0700)
Improve various error messages generated with invalid syntax
Add test cases for most of these error messages

Signed-off-by: David Zafman <dzafman@redhat.com>
src/test/ceph_objectstore_tool.py
src/tools/ceph_objectstore_tool.cc

index e75ba7fb9b791bd08b6ab8353e39cac13e340472..7d2d48a82dc06a839619b1a932f099fb70ea59d3 100755 (executable)
@@ -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)
index 80b08b35cbe5e4a010a7dfbcef5c75194c9ea14e..ea7e6759098fb861f4273cecc3138c1ff3ce331a 100644 (file)
@@ -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<coll_t, ghobject_t> found = lookup.pop();