]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tasks/cephfs: add TestDataScan.test_pg_files
authorJohn Spray <john.spray@redhat.com>
Wed, 19 Oct 2016 22:19:21 +0000 (23:19 +0100)
committerJohn Spray <john.spray@redhat.com>
Wed, 19 Oct 2016 22:19:21 +0000 (23:19 +0100)
Fixes: http://tracker.ceph.com/issues/17249
Signed-off-by: John Spray <john.spray@redhat.com>
tasks/cephfs/filesystem.py
tasks/cephfs/test_data_scan.py

index 4f7868c9eee9980eb1043834b479227231e86fff..3f0687512a4f64cfacf85b8b92adbda19ab54cff 100644 (file)
@@ -334,6 +334,15 @@ class Filesystem(MDSCluster):
     def get_data_pool_name(self):
         return self.data_pool_name
 
+    def get_data_pool_id(self):
+        """
+        Don't call this if you have multiple data pools
+        :return: integer
+        """
+        pools = self.get_mds_map()['data_pools']
+        assert(len(pools) == 1)
+        return pools[0]
+
     def get_data_pool_names(self):
         osd_map = self.mon_manager.get_osd_dump_json()
         id_to_name = {}
index 134b567b916542d7a506cb469feecf61ad978dd8..2a0d05abc7b593f433303268bfdc50b5d5778f65 100644 (file)
@@ -2,12 +2,13 @@
 """
 Test our tools for recovering metadata from the data pool
 """
+import json
 
 import logging
 import os
 from textwrap import dedent
 import traceback
-from collections import namedtuple
+from collections import namedtuple, defaultdict
 
 from teuthology.orchestra.run import CommandFailedError
 from tasks.cephfs.cephfs_test_case import CephFSTestCase, for_teuthology
@@ -509,3 +510,38 @@ class TestDataScan(CephFSTestCase):
     @for_teuthology
     def test_parallel_execution(self):
         self._rebuild_metadata(ManyFilesWorkload(self.fs, self.mount_a, 25), workers=7)
+
+    def test_pg_files(self):
+        """
+        That the pg files command tells us which files are associated with
+        a particular PG
+        """
+        file_count = 20
+        self.mount_a.run_shell(["mkdir", "mydir"])
+        self.mount_a.create_n_files("mydir/myfile", file_count)
+
+        # Some files elsewhere in the system that we will ignore
+        # to check that the tool is filtering properly
+        self.mount_a.run_shell(["mkdir", "otherdir"])
+        self.mount_a.create_n_files("otherdir/otherfile", file_count)
+
+        pgs_to_files = defaultdict(list)
+        # Rough (slow) reimplementation of the logic
+        for i in range(0, file_count):
+            file_path = "mydir/myfile_{0}".format(i)
+            ino = self.mount_a.path_to_ino(file_path)
+            obj = "{0:x}.{1:08x}".format(ino, 0)
+            pgid = json.loads(self.fs.mon_manager.raw_cluster_cmd(
+                "osd", "map", self.fs.get_data_pool_name(), obj,
+                "--format=json-pretty"
+            ))['pgid']
+            pgs_to_files[pgid].append(file_path)
+            log.info("{0}: {1}".format(file_path, pgid))
+
+        pg_count = self.fs.get_pgs_per_fs_pool()
+        for pg_n in range(0, pg_count):
+            pg_str = "{0}.{1}".format(self.fs.get_data_pool_id(), pg_n)
+            out = self.fs.data_scan(["pg_files", "mydir", pg_str])
+            lines = [l for l in out.split("\n") if l]
+            log.info("{0}: {1}".format(pg_str, lines))
+            self.assertSetEqual(set(lines), set(pgs_to_files[pg_str]))
\ No newline at end of file