]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-objectstore-tool: Improve object spec error handling
authorDavid Zafman <dzafman@redhat.com>
Wed, 14 Oct 2015 20:12:17 +0000 (13:12 -0700)
committerDavid Zafman <dzafman@redhat.com>
Fri, 30 Oct 2015 20:01:50 +0000 (13:01 -0700)
Add test cases

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

index ffa8672ff3713acea25f8e87f94757b12f57b60c..4ca9829e7f3bbd5b8e61fdbc7425997f15d5ec52 100755 (executable)
@@ -862,6 +862,27 @@ def main(argv):
     cmd = (CFSD_PREFIX + "--pgid {pg} '' notacommand").format(osd=ONEOSD, pg=ONEPG)
     ERRORS += test_failure(cmd, "Unknown object command 'notacommand'")
 
+    cmd = (CFSD_PREFIX + "foo list-omap").format(osd=ONEOSD, pg=ONEPG)
+    ERRORS += test_failure(cmd, "No object id 'foo' found or invalid JSON specified")
+
+    cmd = (CFSD_PREFIX + "'{{\"oid\":\"obj4\",\"key\":\"\",\"snapid\":-1,\"hash\":2826278768,\"max\":0,\"pool\":1,\"namespace\":\"\"}}' list-omap").format(osd=ONEOSD, pg=ONEPG)
+    ERRORS += test_failure(cmd, "Without --pgid the object '{\"oid\":\"obj4\",\"key\":\"\",\"snapid\":-1,\"hash\":2826278768,\"max\":0,\"pool\":1,\"namespace\":\"\"}' must be a JSON array")
+
+    cmd = (CFSD_PREFIX + "'[]' list-omap").format(osd=ONEOSD, pg=ONEPG)
+    ERRORS += test_failure(cmd, "Object '[]' must be a JSON array with 2 elements")
+
+    cmd = (CFSD_PREFIX + "'[\"1.0\"]' list-omap").format(osd=ONEOSD, pg=ONEPG)
+    ERRORS += test_failure(cmd, "Object '[\"1.0\"]' must be a JSON array with 2 elements")
+
+    cmd = (CFSD_PREFIX + "'[\"1.0\", 5, 8, 9]' list-omap").format(osd=ONEOSD, pg=ONEPG)
+    ERRORS += test_failure(cmd, "Object '[\"1.0\", 5, 8, 9]' must be a JSON array with 2 elements")
+
+    cmd = (CFSD_PREFIX + "'[1, 2]' list-omap").format(osd=ONEOSD, pg=ONEPG)
+    ERRORS += test_failure(cmd, "Object '[1, 2]' must be a JSON array with the first element a string")
+
+    cmd = (CFSD_PREFIX + "'[\"1.3\",{{\"snapid\":\"not an int\"}}]' list-omap").format(osd=ONEOSD, pg=ONEPG)
+    ERRORS += test_failure(cmd, "Decode object JSON error: value type is 2 not 4")
+
     TMPFILE = r"/tmp/tmp.{pid}".format(pid=pid)
     ALLPGS = OBJREPPGS + OBJECPGS
     OSDS = get_osds(ALLPGS[0], OSDDIR)
index 2977e3920b452767fe2d613b0fbedfb158b88f50..187a2578f7c90efd309a03de332bf80a0db448fc 100644 (file)
@@ -2459,7 +2459,7 @@ int main(int argc, char **argv)
          if (lookup.size() != 1) {
            stringstream ss;
            if (lookup.size() == 0)
-             ss << "No object id '" << object << "' found";
+             ss << "No object id '" << object << "' found or invalid JSON specified";
            else
              ss << "Found " << lookup.size() << " objects with id '" << object
                 << "', please use a JSON spec from --op list instead";
@@ -2473,18 +2473,22 @@ int main(int argc, char **argv)
       } else {
        stringstream ss;
        if (pgidstr.length() == 0 && v.type() != json_spirit::array_type) {
-         ss << "object '" << object
-            << "' must be a JSON array but is of type "
-            << v.type() << " instead";
+         ss << "Without --pgid the object '" << object
+            << "' must be a JSON array";
          throw std::runtime_error(ss.str());
        }
        if (v.type() == json_spirit::array_type) {
          json_spirit::Array array = v.get_array();
+         if (array.size() != 2) {
+           ss << "Object '" << object
+              << "' must be a JSON array with 2 elements";
+           throw std::runtime_error(ss.str());
+         }
          vector<json_spirit::Value>::iterator i = array.begin();
+         //if (i == array.end() || i->type() != json_spirit::str_type) {
          if (i->type() != json_spirit::str_type) {
-           ss << "object '" << object
-              << "' must be a JSON array with the first element a string but "
-              << "found type " << v.type() << " instead";
+           ss << "Object '" << object
+              << "' must be a JSON array with the first element a string";
            throw std::runtime_error(ss.str());
          }
          string object_pgidstr = i->get_str();
@@ -2511,7 +2515,7 @@ int main(int argc, char **argv)
        try {
          ghobj.decode(v);
        } catch (std::runtime_error& e) {
-         ss << "Decode object json error: " << e.what();
+         ss << "Decode object JSON error: " << e.what();
          throw std::runtime_error(ss.str());
        }
         if (pgidstr != "meta" && (uint64_t)pgid.pgid.m_pool != (uint64_t)ghobj.hobj.pool) {