]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_objectstore_tool, test: Add list-pgs operations and unit test case
authorDavid Zafman <david.zafman@inktank.com>
Tue, 5 Aug 2014 19:26:42 +0000 (12:26 -0700)
committerDavid Zafman <dzafman@redhat.com>
Tue, 3 Mar 2015 17:51:30 +0000 (09:51 -0800)
Signed-off-by: David Zafman <david.zafman@inktank.com>
(cherry picked from commit f01e334c697057158354f0ce5ecff6d6ba8e2704)

src/test/ceph_objectstore_tool.py
src/tools/ceph_objectstore_tool.cc

index 8aa55a2f1fbfdf6ac59bd816da9ac60bf1713d76..d0a0c1efc8ce607b36c8a07da38072f0c942a231 100755 (executable)
@@ -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)
index 8abbb8a82f9e4afff46a3a7bf53679d7f5cc2fcc..616103c176d06083f95b0eea38e5470a4b89417c 100644 (file)
@@ -1510,7 +1510,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")
@@ -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);
     }