]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/cephfs/test_sessionmap.py
5 from tasks
.cephfs
.fuse_mount
import FuseMount
6 from teuthology
.exceptions
import CommandFailedError
7 from tasks
.cephfs
.cephfs_test_case
import CephFSTestCase
9 log
= logging
.getLogger(__name__
)
12 class TestSessionMap(CephFSTestCase
):
16 def test_tell_session_drop(self
):
18 That when a `tell` command is sent using the python CLI,
19 its MDS session is gone after it terminates
21 self
.mount_a
.umount_wait()
22 self
.mount_b
.umount_wait()
24 status
= self
.fs
.status()
25 self
.fs
.rank_tell(["session", "ls"], status
=status
)
27 ls_data
= self
.fs
.rank_asok(['session', 'ls'], status
=status
)
28 self
.assertEqual(len(ls_data
), 0)
30 def _get_connection_count(self
, status
=None):
31 perf
= self
.fs
.rank_asok(["perf", "dump"], status
=status
)
33 for module
, dump
in perf
.items():
34 if "AsyncMessenger::Worker" in module
:
35 conn
+= dump
['msgr_active_connections']
38 def test_tell_conn_close(self
):
40 That when a `tell` command is sent using the python CLI,
41 the conn count goes back to where it started (i.e. we aren't
42 leaving connections open)
44 self
.config_set('mds', 'ms_async_reap_threshold', '1')
46 self
.mount_a
.umount_wait()
47 self
.mount_b
.umount_wait()
49 status
= self
.fs
.status()
50 s
= self
._get
_connection
_count
(status
=status
)
51 self
.fs
.rank_tell(["session", "ls"], status
=status
)
53 lambda: self
._get
_connection
_count
(status
=status
) == s
,
57 def test_mount_conn_close(self
):
59 That when a client unmounts, the thread count on the MDS goes back
60 to what it was before the client mounted
62 self
.config_set('mds', 'ms_async_reap_threshold', '1')
64 self
.mount_a
.umount_wait()
65 self
.mount_b
.umount_wait()
67 status
= self
.fs
.status()
68 s
= self
._get
_connection
_count
(status
=status
)
69 self
.mount_a
.mount_wait()
70 self
.assertGreater(self
._get
_connection
_count
(status
=status
), s
)
71 self
.mount_a
.umount_wait()
73 lambda: self
._get
_connection
_count
(status
=status
) == s
,
77 def test_version_splitting(self
):
79 That when many sessions are updated, they are correctly
80 split into multiple versions to obey mds_sessionmap_keys_per_op
83 self
.mount_a
.umount_wait()
84 self
.mount_b
.umount_wait()
86 # Configure MDS to write one OMAP key at once
87 self
.set_conf('mds', 'mds_sessionmap_keys_per_op', 1)
88 self
.fs
.mds_fail_restart()
89 status
= self
.fs
.wait_for_daemons()
91 # Bring the clients back
92 self
.mount_a
.mount_wait()
93 self
.mount_b
.mount_wait()
95 # See that they've got sessions
96 self
.assert_session_count(2, mds_id
=self
.fs
.get_rank(status
=status
)['name'])
98 # See that we persist their sessions
99 self
.fs
.rank_asok(["flush", "journal"], rank
=0, status
=status
)
100 table_json
= json
.loads(self
.fs
.table_tool(["0", "show", "session"]))
101 log
.info("SessionMap: {0}".format(json
.dumps(table_json
, indent
=2)))
102 self
.assertEqual(table_json
['0']['result'], 0)
103 self
.assertEqual(len(table_json
['0']['data']['sessions']), 2)
105 # Now, induce a "force_open_sessions" event by exporting a dir
106 self
.mount_a
.run_shell(["mkdir", "bravo"])
107 self
.mount_a
.run_shell(["touch", "bravo/file_a"])
108 self
.mount_b
.run_shell(["touch", "bravo/file_b"])
110 self
.fs
.set_max_mds(2)
111 status
= self
.fs
.wait_for_daemons()
114 return self
.fs
.rank_asok(['perf', 'dump', 'objecter'], rank
=1, status
=status
)['objecter']['omap_wr']
116 # Flush so that there are no dirty sessions on rank 1
117 self
.fs
.rank_asok(["flush", "journal"], rank
=1, status
=status
)
119 # Export so that we get a force_open to rank 1 for the two sessions from rank 0
120 initial_omap_wrs
= get_omap_wrs()
121 self
.fs
.rank_asok(['export', 'dir', '/bravo', '1'], rank
=0, status
=status
)
123 # This is the critical (if rather subtle) check: that in the process of doing an export dir,
124 # we hit force_open_sessions, and as a result we end up writing out the sessionmap. There
125 # will be two sessions dirtied here, and because we have set keys_per_op to 1, we should see
126 # a single session get written out (the first of the two, triggered by the second getting marked
128 # The number of writes is two per session, because the header (sessionmap version) update and
129 # KV write both count. Also, multiply by 2 for each openfile table update.
130 self
.wait_until_true(
131 lambda: get_omap_wrs() - initial_omap_wrs
== 2*2,
132 timeout
=30 # Long enough for an export to get acked
135 # Now end our sessions and check the backing sessionmap is updated correctly
136 self
.mount_a
.umount_wait()
137 self
.mount_b
.umount_wait()
139 # In-memory sessionmap check
140 self
.assert_session_count(0, mds_id
=self
.fs
.get_rank(status
=status
)['name'])
142 # On-disk sessionmap check
143 self
.fs
.rank_asok(["flush", "journal"], rank
=0, status
=status
)
144 table_json
= json
.loads(self
.fs
.table_tool(["0", "show", "session"]))
145 log
.info("SessionMap: {0}".format(json
.dumps(table_json
, indent
=2)))
146 self
.assertEqual(table_json
['0']['result'], 0)
147 self
.assertEqual(len(table_json
['0']['data']['sessions']), 0)
149 def _configure_auth(self
, mount
, id_name
, mds_caps
, osd_caps
=None, mon_caps
=None):
151 Set up auth credentials for a client mount, and write out the keyring
152 for the client to use.
156 osd_caps
= "allow rw"
161 out
= self
.fs
.mon_manager
.raw_cluster_cmd(
162 "auth", "get-or-create", "client.{name}".format(name
=id_name
),
167 mount
.client_id
= id_name
168 mount
.client_remote
.write_file(mount
.get_keyring_path(), out
, sudo
=True)
169 self
.set_conf("client.{name}".format(name
=id_name
), "keyring", mount
.get_keyring_path())
171 def test_session_reject(self
):
172 if not isinstance(self
.mount_a
, FuseMount
):
173 self
.skipTest("Requires FUSE client to inject client metadata")
175 self
.mount_a
.run_shell(["mkdir", "foo"])
176 self
.mount_a
.run_shell(["mkdir", "foo/bar"])
177 self
.mount_a
.umount_wait()
179 # Mount B will be my rejected client
180 self
.mount_b
.umount_wait()
182 # Configure a client that is limited to /foo/bar
183 self
._configure
_auth
(self
.mount_b
, "badguy", "allow rw path=/foo/bar")
184 # Check he can mount that dir and do IO
185 self
.mount_b
.mount_wait(cephfs_mntpt
="/foo/bar")
186 self
.mount_b
.create_destroy()
187 self
.mount_b
.umount_wait()
189 # Configure the client to claim that its mount point metadata is /baz
190 self
.set_conf("client.badguy", "client_metadata", "root=/baz")
191 # Try to mount the client, see that it fails
192 with self
.assert_cluster_log("client session with non-allowable root '/baz' denied"):
193 with self
.assertRaises(CommandFailedError
):
194 self
.mount_b
.mount_wait(cephfs_mntpt
="/foo/bar")
196 def test_session_evict_blocklisted(self
):
198 Check that mds evicts blocklisted client
200 if not isinstance(self
.mount_a
, FuseMount
):
201 self
.skipTest("Requires FUSE client to use "
202 "mds_cluster.is_addr_blocklisted()")
204 self
.fs
.set_max_mds(2)
205 status
= self
.fs
.wait_for_daemons()
207 self
.mount_a
.run_shell_payload("mkdir {d0,d1} && touch {d0,d1}/file")
208 self
.mount_a
.setfattr("d0", "ceph.dir.pin", "0")
209 self
.mount_a
.setfattr("d1", "ceph.dir.pin", "1")
210 self
._wait
_subtrees
([('/d0', 0), ('/d1', 1)], status
=status
)
212 self
.mount_a
.run_shell(["touch", "d0/f0"])
213 self
.mount_a
.run_shell(["touch", "d1/f0"])
214 self
.mount_b
.run_shell(["touch", "d0/f1"])
215 self
.mount_b
.run_shell(["touch", "d1/f1"])
217 self
.assert_session_count(2, mds_id
=self
.fs
.get_rank(rank
=0, status
=status
)['name'])
218 self
.assert_session_count(2, mds_id
=self
.fs
.get_rank(rank
=1, status
=status
)['name'])
220 mount_a_client_id
= self
.mount_a
.get_global_id()
221 self
.fs
.mds_asok(['session', 'evict', "%s" % mount_a_client_id
],
222 mds_id
=self
.fs
.get_rank(rank
=0, status
=status
)['name'])
223 self
.wait_until_true(lambda: self
.mds_cluster
.is_addr_blocklisted(
224 self
.mount_a
.get_global_addr()), timeout
=30)
226 # 10 seconds should be enough for evicting client
228 self
.assert_session_count(1, mds_id
=self
.fs
.get_rank(rank
=0, status
=status
)['name'])
229 self
.assert_session_count(1, mds_id
=self
.fs
.get_rank(rank
=1, status
=status
)['name'])
231 self
.mount_a
.kill_cleanup()
232 self
.mount_a
.mount_wait()