From 5e3f89ece7bdd09ed06ca4208cfa0a0b3104f109 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Tue, 5 Aug 2014 12:26:42 -0700 Subject: [PATCH] ceph_objectstore_tool, test: Add list-pgs operations and unit test case Signed-off-by: David Zafman (cherry picked from commit f01e334c697057158354f0ce5ecff6d6ba8e2704) --- src/test/ceph_objectstore_tool.py | 35 +++++++++++++++++++++++++----- src/tools/ceph_objectstore_tool.cc | 25 ++++++++++++++++----- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/test/ceph_objectstore_tool.py b/src/test/ceph_objectstore_tool.py index 8aa55a2f1fb..d0a0c1efc8c 100755 --- a/src/test/ceph_objectstore_tool.py +++ b/src/test/ceph_objectstore_tool.py @@ -25,16 +25,24 @@ def get_pool_id(name, nullfd): return check_output(cmd, stderr=nullfd).split()[3] +# return a list of unique PGS given an osd subdirectory +def get_osd_pgs(SUBDIR, ID): + PGS = [] + if ID: + endhead = re.compile("{id}.*_head$".format(id=ID)) + DIR = os.path.join(SUBDIR, "current") + PGS += [f for f in os.listdir(DIR) if os.path.isdir(os.path.join(DIR, f)) and (ID == None or endhead.match(f))] + PGS = [re.sub("_head", "", p) for p in PGS if "_head" in p] + return PGS + + # return a sorted list of unique PGs given a directory def get_pgs(DIR, ID): OSDS = [f for f in os.listdir(DIR) if os.path.isdir(os.path.join(DIR, f)) and string.find(f, "osd") == 0] PGS = [] - endhead = re.compile("{id}.*_head$".format(id=ID)) for d in OSDS: - DIRL2 = os.path.join(DIR, d) - SUBDIR = os.path.join(DIRL2, "current") - PGS += [f for f in os.listdir(SUBDIR) if os.path.isdir(os.path.join(SUBDIR, f)) and endhead.match(f)] - PGS = [re.sub("_head", "", p) for p in PGS] + SUBDIR = os.path.join(DIR, d) + PGS += get_osd_pgs(SUBDIR, ID) return sorted(set(PGS)) @@ -533,6 +541,23 @@ def main(): except: pass + print "Test list-pgs" + for osd in [f for f in os.listdir(OSDDIR) if os.path.isdir(os.path.join(OSDDIR, f)) and string.find(f, "osd") == 0]: + + CHECK_PGS = get_osd_pgs(os.path.join(OSDDIR, osd), None) + CHECK_PGS = sorted(CHECK_PGS) + + cmd = (CFSD_PREFIX + "--op list-pgs").format(osd=osd) + logging.debug(cmd) + TEST_PGS = check_output(cmd, shell=True).split("\n") + TEST_PGS = sorted(TEST_PGS)[1:] # Skip extra blank line + + if TEST_PGS != CHECK_PGS: + logging.error("list-pgs got wrong result for osd.{osd}".format(osd=osd)) + logging.error("Expected {pgs}".format(pgs=CHECK_PGS)) + logging.error("Got {pgs}".format(pgs=TEST_PGS)) + ERRORS += 1 + print "Test pg export" EXP_ERRORS = 0 os.mkdir(TESTDIR) diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 8abbb8a82f9..616103c176d 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -1510,7 +1510,7 @@ int main(int argc, char **argv) ("pgid", po::value(&pgidstr), "PG id, mandatory except for import, list-lost, fix-lost") ("op", po::value(&op), - "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost]") + "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs]") ("file", po::value(&file), "path of file to export or import") ("debug", "Enable diagnostic output to stderr") @@ -1571,7 +1571,7 @@ int main(int argc, char **argv) usage(desc); } if (op != "import" && op != "list-lost" && op != "fix-lost" - && !vm.count("pgid")) { + && op != "list-pgs" && !vm.count("pgid")) { cerr << "Must provide pgid" << std::endl; usage(desc); } @@ -1914,6 +1914,10 @@ int main(int argc, char **argv) goto out; } + if (debug && op == "list-pgs") + cout << "Performing list-pgs operation" << std::endl; + + // Find pg for (it = ls.begin(); it != ls.end(); ++it) { snapid_t snap; spg_t tmppgid; @@ -1926,7 +1930,7 @@ int main(int argc, char **argv) continue; } - if (tmppgid != pgid) { + if (op != "list-pgs" && tmppgid != pgid) { continue; } if (snap != CEPH_NOSNAP && debug) { @@ -1935,8 +1939,17 @@ int main(int argc, char **argv) continue; } - //Found! - break; + if (op != "list-pgs") { + //Found! + break; + } + + cout << tmppgid << std::endl; + } + + if (op == "list-pgs") { + ret = 0; + goto out; } epoch_t map_epoch; @@ -2164,7 +2177,7 @@ int main(int argc, char **argv) formatter->flush(cout); cout << std::endl; } else { - cerr << "Must provide --op (info, log, remove, export, import, list, list-lost, fix-lost)" + cerr << "Must provide --op (info, log, remove, export, import, list, list-lost, fix-lost, list-pgs)" << std::endl; usage(desc); } -- 2.47.3