]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test, tools: Improve ceph-objectstore-tool import error handling and add tests 4932/head
authorDavid Zafman <dzafman@redhat.com>
Thu, 11 Jun 2015 19:57:10 +0000 (12:57 -0700)
committerDavid Zafman <dzafman@redhat.com>
Thu, 11 Jun 2015 19:57:10 +0000 (12:57 -0700)
Signed-off-by: David Zafman <dzafman@redhat.com>
src/test/ceph_objectstore_tool.py
src/tools/ceph_objectstore_tool.cc

index aca6d0d3e887d2d33e72a49852db9431d53f1947..3bb1d342278b712ab4167c581da601a5d1ffb53d 100755 (executable)
@@ -588,6 +588,22 @@ def main(argv):
     cmd = (CFSD_PREFIX + "--op export --pgid {pg} --file -").format(osd=ONEOSD, pg=ONEPG)
     ERRORS += test_failure_tty(cmd, "stdout is a tty and no --file filename specified")
 
+    # Prep a valid ec export file for import failure tests
+    ONEECPG = ALLECPGS[0]
+    osds = get_osds(ONEECPG, OSDDIR)
+    ONEECOSD = osds[0]
+    OTHERFILE = "/tmp/foo.{pid}".format(pid=pid)
+    cmd = (CFSD_PREFIX + "--op export --pgid {pg} --file {file}").format(osd=ONEECOSD, pg=ONEECPG, file=OTHERFILE)
+    logging.debug(cmd)
+    call(cmd, shell=True, stdout=nullfd, stderr=nullfd)
+
+    # On import can't specify a different shard
+    BADPG = ONEECPG.split('s')[0] + "s10"
+    cmd = (CFSD_PREFIX + "--op import --pgid {pg} --file {file}").format(osd=ONEECOSD, pg=BADPG, file=OTHERFILE)
+    ERRORS += test_failure(cmd, "Can't specify a different shard, must be")
+
+    os.unlink(OTHERFILE)
+
     # Prep a valid export file for import failure tests
     OTHERFILE = "/tmp/foo.{pid}".format(pid=pid)
     cmd = (CFSD_PREFIX + "--op export --pgid {pg} --file {file}").format(osd=ONEOSD, pg=ONEPG, file=OTHERFILE)
@@ -598,6 +614,10 @@ def main(argv):
     cmd = (CFSD_PREFIX + "--op import --pgid {pg} --file {file}").format(osd=ONEOSD, pg="10.0", file=OTHERFILE)
     ERRORS += test_failure(cmd, "Can't specify a different pgid pool, must be")
 
+    # On import can't specify shard for a replicated export
+    cmd = (CFSD_PREFIX + "--op import --pgid {pg}s0 --file {file}").format(osd=ONEOSD, pg=ONEPG, file=OTHERFILE)
+    ERRORS += test_failure(cmd, "Can't specify a sharded pgid with a non-sharded export")
+
     # On import can't specify a PG with a bad seed
     TMPPG="{pool}.80".format(pool=REPID)
     cmd = (CFSD_PREFIX + "--op import --pgid {pg} --file {file}").format(osd=ONEOSD, pg=TMPPG, file=OTHERFILE)
index e00df4da029085b5107da44877cd806031a76a3a..6c795375b27ed648b387a34a713eb37d9fab590c 100644 (file)
@@ -1188,6 +1188,18 @@ int ObjectStoreTool::do_import(ObjectStore *store, OSDSuperblock& sb,
         cerr << "Can't specify a different pgid pool, must be " << pgid.pool() << std::endl;
         return -EINVAL;
       }
+      if (pgid.is_no_shard() && !user_pgid.is_no_shard()) {
+        cerr << "Can't specify a sharded pgid with a non-sharded export" << std::endl;
+        return -EINVAL;
+      }
+      // Get shard from export information if not specified
+      if (!pgid.is_no_shard() && user_pgid.is_no_shard()) {
+        user_pgid.shard = pgid.shard;
+      }
+      if (pgid.shard != user_pgid.shard) {
+        cerr << "Can't specify a different shard, must be " << pgid.shard << std::endl;
+        return -EINVAL;
+      }
       pgid = user_pgid;
     }
   }