From: David Zafman Date: Thu, 11 Jun 2015 19:57:10 +0000 (-0700) Subject: test, tools: Improve ceph-objectstore-tool import error handling and add tests X-Git-Tag: v0.94.7~28^2~7^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6c8884b11b8211642662bfd7d612872621ffd8ff;p=ceph.git test, tools: Improve ceph-objectstore-tool import error handling and add tests Signed-off-by: David Zafman (cherry picked from commit ddc4d52782a04d99a4293c9fc278894dfe328515) --- diff --git a/src/test/ceph_objectstore_tool.py b/src/test/ceph_objectstore_tool.py index c8493c4ccb18a..dfaa7d41832aa 100755 --- a/src/test/ceph_objectstore_tool.py +++ b/src/test/ceph_objectstore_tool.py @@ -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) diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 70209496a60ae..5a57ecb841d01 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -1992,6 +1992,18 @@ int do_import(ObjectStore *store, OSDSuperblock& sb, bool force, string pgidstr) 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; } }