ceph_objectstore_tool, test: Add list-pgs operations and unit test case

Signed-off-by: David Zafman <david.zafman@inktank.com>
This commit is contained in:
David Zafman 2014-08-05 12:26:42 -07:00 committed by David Zafman
parent 83fbc91e5c
commit f01e334c69
2 changed files with 49 additions and 11 deletions

View File

@ -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)

View File

@ -1512,7 +1512,7 @@ int main(int argc, char **argv)
("pgid", po::value<string>(&pgidstr),
"PG id, mandatory except for import, list-lost, fix-lost")
("op", po::value<string>(&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<string>(&file),
"path of file to export or import")
("debug", "Enable diagnostic output to stderr")
@ -1573,7 +1573,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);
}
@ -1916,6 +1916,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;
@ -1928,7 +1932,7 @@ int main(int argc, char **argv)
continue;
}
if (tmppgid != pgid) {
if (op != "list-pgs" && tmppgid != pgid) {
continue;
}
if (snap != CEPH_NOSNAP && debug) {
@ -1937,8 +1941,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;
@ -2166,7 +2179,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);
}