]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/cephfs/test_dump_tree.py
6d943f9dd2ff337b13ac72cd84d8d8198833bb82
[ceph.git] / ceph / qa / tasks / cephfs / test_dump_tree.py
1 from tasks.cephfs.cephfs_test_case import CephFSTestCase
2 import random
3 import os
4
5 class TestDumpTree(CephFSTestCase):
6 def get_paths_to_ino(self):
7 inos = {}
8 p = self.mount_a.run_shell(["find", "./"])
9 paths = p.stdout.getvalue().strip().split()
10 for path in paths:
11 inos[path] = self.mount_a.path_to_ino(path, False)
12
13 return inos
14
15 def populate(self):
16 self.mount_a.run_shell(["git", "clone",
17 "https://github.com/ceph/ceph-qa-suite"])
18
19 def test_basic(self):
20 self.mount_a.run_shell(["mkdir", "parent"])
21 self.mount_a.run_shell(["mkdir", "parent/child"])
22 self.mount_a.run_shell(["touch", "parent/child/file"])
23 self.mount_a.run_shell(["mkdir", "parent/child/grandchild"])
24 self.mount_a.run_shell(["touch", "parent/child/grandchild/file"])
25
26 inos = self.get_paths_to_ino()
27 tree = self.fs.mds_asok(["dump", "tree", "/parent/child", "1"])
28
29 target_inos = [inos["./parent/child"], inos["./parent/child/file"],
30 inos["./parent/child/grandchild"]]
31
32 for ino in tree:
33 del target_inos[target_inos.index(ino['ino'])] # don't catch!
34
35 assert(len(target_inos) == 0)
36
37 def test_random(self):
38 random.seed(0)
39
40 self.populate()
41 inos = self.get_paths_to_ino()
42 target = random.choice(inos.keys())
43
44 if target != "./":
45 target = os.path.dirname(target)
46
47 subtree = [path for path in inos.keys() if path.startswith(target)]
48 target_inos = [inos[path] for path in subtree]
49 tree = self.fs.mds_asok(["dump", "tree", target[1:]])
50
51 for ino in tree:
52 del target_inos[target_inos.index(ino['ino'])] # don't catch!
53
54 assert(len(target_inos) == 0)
55
56 target_depth = target.count('/')
57 maxdepth = max([path.count('/') for path in subtree]) - target_depth
58 depth = random.randint(0, maxdepth)
59 target_inos = [inos[path] for path in subtree \
60 if path.count('/') <= depth + target_depth]
61 tree = self.fs.mds_asok(["dump", "tree", target[1:], str(depth)])
62
63 for ino in tree:
64 del target_inos[target_inos.index(ino['ino'])] # don't catch!
65
66 assert(len(target_inos) == 0)