]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools, test: Some ceph-objectstore-tool error handling fixes
authorDavid Zafman <dzafman@redhat.com>
Fri, 26 Jun 2015 00:15:39 +0000 (17:15 -0700)
committerDavid Zafman <dzafman@redhat.com>
Thu, 25 Feb 2016 20:50:24 +0000 (12:50 -0800)
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>
(cherry picked from commit 127a5f191d3d2442edd3a3fa820006bca3a08c93)

Conflicts:
src/test/ceph_objectstore_tool.py (trivial)

src/test/ceph_objectstore_tool.py
src/tools/ceph_objectstore_tool.cc

index 2a2fd55b84d0545631091d01ca2091b40bf96aff..3f51d427871f420ad542f40679ac0438716c0758 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
 
 
@@ -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)
index 0b8b054f3d499d117f94457b9360f0e30415b17c..048e176f92d27e262ebfa575f1109dbe12968fba 100644 (file)
@@ -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<coll_t, ghobject_t> found = lookup.pop();