]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/cephfs/test_exports.py
update sources to v12.1.1
[ceph.git] / ceph / qa / tasks / cephfs / test_exports.py
CommitLineData
7c673cae
FG
1import logging
2import time
3from tasks.cephfs.fuse_mount import FuseMount
4from tasks.cephfs.cephfs_test_case import CephFSTestCase
5
6log = logging.getLogger(__name__)
7
8class TestExports(CephFSTestCase):
31f18b77
FG
9 MDSS_REQUIRED = 2
10
7c673cae
FG
11 def _wait_subtrees(self, status, rank, test):
12 timeout = 30
13 pause = 2
14 test = sorted(test)
15 for i in range(timeout/pause):
16 subtrees = self.fs.mds_asok(["get", "subtrees"], mds_id=status.get_rank(self.fs.id, rank)['name'])
17 subtrees = filter(lambda s: s['dir']['path'].startswith('/'), subtrees)
7c673cae 18 filtered = sorted([(s['dir']['path'], s['auth_first']) for s in subtrees])
31f18b77 19 log.info("%s =?= %s", filtered, test)
7c673cae
FG
20 if filtered == test:
21 return subtrees
22 time.sleep(pause)
23 raise RuntimeError("rank {0} failed to reach desired subtree state", rank)
24
25 def test_export_pin(self):
7c673cae 26 self.fs.set_max_mds(2)
224ce89b 27 self.fs.wait_for_daemons()
7c673cae
FG
28
29 status = self.fs.status()
30
31 self.mount_a.run_shell(["mkdir", "-p", "1/2/3"])
32 self._wait_subtrees(status, 0, [])
33
34 # NOP
31f18b77 35 self.mount_a.setfattr("1", "ceph.dir.pin", "-1")
7c673cae
FG
36 self._wait_subtrees(status, 0, [])
37
38 # NOP (rank < -1)
31f18b77 39 self.mount_a.setfattr("1", "ceph.dir.pin", "-2341")
7c673cae
FG
40 self._wait_subtrees(status, 0, [])
41
42 # pin /1 to rank 1
31f18b77 43 self.mount_a.setfattr("1", "ceph.dir.pin", "1")
7c673cae
FG
44 self._wait_subtrees(status, 1, [('/1', 1)])
45
46 # Check export_targets is set properly
47 status = self.fs.status()
48 log.info(status)
49 r0 = status.get_rank(self.fs.id, 0)
50 self.assertTrue(sorted(r0['export_targets']) == [1])
51
52 # redundant pin /1/2 to rank 1
31f18b77 53 self.mount_a.setfattr("1/2", "ceph.dir.pin", "1")
7c673cae
FG
54 self._wait_subtrees(status, 1, [('/1', 1), ('/1/2', 1)])
55
56 # change pin /1/2 to rank 0
31f18b77 57 self.mount_a.setfattr("1/2", "ceph.dir.pin", "0")
7c673cae
FG
58 self._wait_subtrees(status, 1, [('/1', 1), ('/1/2', 0)])
59 self._wait_subtrees(status, 0, [('/1', 1), ('/1/2', 0)])
60
61 # change pin /1/2/3 to (presently) non-existent rank 2
31f18b77 62 self.mount_a.setfattr("1/2/3", "ceph.dir.pin", "2")
7c673cae
FG
63 self._wait_subtrees(status, 0, [('/1', 1), ('/1/2', 0)])
64 self._wait_subtrees(status, 1, [('/1', 1), ('/1/2', 0)])
65
66 # change pin /1/2 back to rank 1
31f18b77 67 self.mount_a.setfattr("1/2", "ceph.dir.pin", "1")
7c673cae
FG
68 self._wait_subtrees(status, 1, [('/1', 1), ('/1/2', 1)])
69
70 # add another directory pinned to 1
71 self.mount_a.run_shell(["mkdir", "-p", "1/4/5"])
31f18b77 72 self.mount_a.setfattr("1/4/5", "ceph.dir.pin", "1")
7c673cae
FG
73 self._wait_subtrees(status, 1, [('/1', 1), ('/1/2', 1), ('/1/4/5', 1)])
74
75 # change pin /1 to 0
31f18b77 76 self.mount_a.setfattr("1", "ceph.dir.pin", "0")
7c673cae
FG
77 self._wait_subtrees(status, 0, [('/1', 0), ('/1/2', 1), ('/1/4/5', 1)])
78
79 # change pin /1/2 to default (-1); does the subtree root properly respect it's parent pin?
31f18b77 80 self.mount_a.setfattr("1/2", "ceph.dir.pin", "-1")
7c673cae
FG
81 self._wait_subtrees(status, 0, [('/1', 0), ('/1/4/5', 1)])
82
83 if len(list(status.get_standbys())):
84 self.fs.set_max_mds(3)
85 self.fs.wait_for_state('up:active', rank=2)
86 self._wait_subtrees(status, 0, [('/1', 0), ('/1/4/5', 1), ('/1/2/3', 2)])
87
88 # Check export_targets is set properly
89 status = self.fs.status()
90 log.info(status)
91 r0 = status.get_rank(self.fs.id, 0)
92 self.assertTrue(sorted(r0['export_targets']) == [1,2])
93 r1 = status.get_rank(self.fs.id, 1)
94 self.assertTrue(sorted(r1['export_targets']) == [0])
95 r2 = status.get_rank(self.fs.id, 2)
96 self.assertTrue(sorted(r2['export_targets']) == [])
97
98 # Test rename
99 self.mount_a.run_shell(["mkdir", "-p", "a/b", "aa/bb"])
31f18b77
FG
100 self.mount_a.setfattr("a", "ceph.dir.pin", "1")
101 self.mount_a.setfattr("aa/bb", "ceph.dir.pin", "0")
7c673cae
FG
102 self._wait_subtrees(status, 0, [('/1', 0), ('/1/4/5', 1), ('/1/2/3', 2), ('/a', 1), ('/aa/bb', 0)])
103 self.mount_a.run_shell(["mv", "aa", "a/b/"])
104 self._wait_subtrees(status, 0, [('/1', 0), ('/1/4/5', 1), ('/1/2/3', 2), ('/a', 1), ('/a/b/aa/bb', 0)])