]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/cephfs/test_misc.py
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / qa / tasks / cephfs / test_misc.py
1
2 from unittest import SkipTest
3 from tasks.cephfs.fuse_mount import FuseMount
4 from tasks.cephfs.cephfs_test_case import CephFSTestCase
5 from teuthology.orchestra.run import CommandFailedError, ConnectionLostError
6 import errno
7 import time
8 import json
9 import logging
10 import time
11
12 log = logging.getLogger(__name__)
13
14 class TestMisc(CephFSTestCase):
15 CLIENTS_REQUIRED = 2
16
17 def test_getattr_caps(self):
18 """
19 Check if MDS recognizes the 'mask' parameter of open request.
20 The parameter allows client to request caps when opening file
21 """
22
23 if not isinstance(self.mount_a, FuseMount):
24 raise SkipTest("Require FUSE client")
25
26 # Enable debug. Client will requests CEPH_CAP_XATTR_SHARED
27 # on lookup/open
28 self.mount_b.umount_wait()
29 self.set_conf('client', 'client debug getattr caps', 'true')
30 self.mount_b.mount()
31 self.mount_b.wait_until_mounted()
32
33 # create a file and hold it open. MDS will issue CEPH_CAP_EXCL_*
34 # to mount_a
35 p = self.mount_a.open_background("testfile")
36 self.mount_b.wait_for_visible("testfile")
37
38 # this triggers a lookup request and an open request. The debug
39 # code will check if lookup/open reply contains xattrs
40 self.mount_b.run_shell(["cat", "testfile"])
41
42 self.mount_a.kill_background(p)
43
44 def test_root_rctime(self):
45 """
46 Check that the root inode has a non-default rctime on startup.
47 """
48
49 t = time.time()
50 rctime = self.mount_a.getfattr(".", "ceph.dir.rctime")
51 log.info("rctime = {}".format(rctime))
52 self.assertGreaterEqual(rctime, t-10)
53
54 def test_fs_new(self):
55 self.mount_a.umount_wait()
56 self.mount_b.umount_wait()
57
58 data_pool_name = self.fs.get_data_pool_name()
59
60 self.fs.mds_stop()
61 self.fs.mds_fail()
62
63 self.fs.mon_manager.raw_cluster_cmd('fs', 'rm', self.fs.name,
64 '--yes-i-really-mean-it')
65
66 self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'delete',
67 self.fs.metadata_pool_name,
68 self.fs.metadata_pool_name,
69 '--yes-i-really-really-mean-it')
70 self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'create',
71 self.fs.metadata_pool_name,
72 self.fs.get_pgs_per_fs_pool().__str__())
73
74 dummyfile = '/etc/fstab'
75
76 self.fs.put_metadata_object_raw("key", dummyfile)
77
78 def get_pool_df(fs, name):
79 try:
80 return fs.get_pool_df(name)['objects'] > 0
81 except RuntimeError as e:
82 return False
83
84 self.wait_until_true(lambda: get_pool_df(self.fs, self.fs.metadata_pool_name), timeout=30)
85
86 try:
87 self.fs.mon_manager.raw_cluster_cmd('fs', 'new', self.fs.name,
88 self.fs.metadata_pool_name,
89 data_pool_name)
90 except CommandFailedError as e:
91 self.assertEqual(e.exitstatus, errno.EINVAL)
92 else:
93 raise AssertionError("Expected EINVAL")
94
95 self.fs.mon_manager.raw_cluster_cmd('fs', 'new', self.fs.name,
96 self.fs.metadata_pool_name,
97 data_pool_name, "--force")
98
99 self.fs.mon_manager.raw_cluster_cmd('fs', 'rm', self.fs.name,
100 '--yes-i-really-mean-it')
101
102
103 self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'delete',
104 self.fs.metadata_pool_name,
105 self.fs.metadata_pool_name,
106 '--yes-i-really-really-mean-it')
107 self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'create',
108 self.fs.metadata_pool_name,
109 self.fs.get_pgs_per_fs_pool().__str__())
110 self.fs.mon_manager.raw_cluster_cmd('fs', 'new', self.fs.name,
111 self.fs.metadata_pool_name,
112 data_pool_name)
113
114 def test_evict_client(self):
115 """
116 Check that a slow client session won't get evicted if it's the
117 only session
118 """
119
120 session_autoclose = self.fs.get_var("session_autoclose")
121
122 self.mount_b.umount_wait()
123 ls_data = self.fs.mds_asok(['session', 'ls'])
124 self.assert_session_count(1, ls_data)
125
126 self.mount_a.kill()
127 self.mount_a.kill_cleanup()
128
129 time.sleep(session_autoclose * 1.5)
130 ls_data = self.fs.mds_asok(['session', 'ls'])
131 self.assert_session_count(1, ls_data)
132
133 self.mount_a.mount()
134 self.mount_a.wait_until_mounted()
135 self.mount_b.mount()
136 self.mount_b.wait_until_mounted()
137
138 ls_data = self._session_list()
139 self.assert_session_count(2, ls_data)
140
141 self.mount_a.kill()
142 self.mount_a.kill_cleanup()
143
144 time.sleep(session_autoclose * 1.5)
145 ls_data = self.fs.mds_asok(['session', 'ls'])
146 self.assert_session_count(1, ls_data)
147
148 def test_cap_revoke_nonresponder(self):
149 """
150 Check that a client is evicted if it has not responded to cap revoke
151 request for configured number of seconds.
152 """
153 session_timeout = self.fs.get_var("session_timeout")
154 eviction_timeout = session_timeout / 2.0
155
156 self.fs.mds_asok(['config', 'set', 'mds_cap_revoke_eviction_timeout',
157 str(eviction_timeout)])
158
159 cap_holder = self.mount_a.open_background()
160
161 # Wait for the file to be visible from another client, indicating
162 # that mount_a has completed its network ops
163 self.mount_b.wait_for_visible()
164
165 # Simulate client death
166 self.mount_a.kill()
167
168 try:
169 # The waiter should get stuck waiting for the capability
170 # held on the MDS by the now-dead client A
171 cap_waiter = self.mount_b.write_background()
172
173 a = time.time()
174 time.sleep(eviction_timeout)
175 cap_waiter.wait()
176 b = time.time()
177 cap_waited = b - a
178 log.info("cap_waiter waited {0}s".format(cap_waited))
179
180 # check if the cap is transferred before session timeout kicked in.
181 # this is a good enough check to ensure that the client got evicted
182 # by the cap auto evicter rather than transitioning to stale state
183 # and then getting evicted.
184 self.assertLess(cap_waited, session_timeout,
185 "Capability handover took {0}, expected less than {1}".format(
186 cap_waited, session_timeout
187 ))
188
189 self.assertTrue(self.mount_a.is_blacklisted())
190 cap_holder.stdin.close()
191 try:
192 cap_holder.wait()
193 except (CommandFailedError, ConnectionLostError):
194 # We killed it (and possibly its node), so it raises an error
195 pass
196 finally:
197 self.mount_a.kill_cleanup()
198
199 self.mount_a.mount()
200 self.mount_a.wait_until_mounted()
201
202 def test_filtered_df(self):
203 pool_name = self.fs.get_data_pool_name()
204 raw_df = self.fs.get_pool_df(pool_name)
205 raw_avail = float(raw_df["max_avail"])
206 out = self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'get',
207 pool_name, 'size',
208 '-f', 'json-pretty')
209 j = json.loads(out)
210 pool_size = int(j['size'])
211
212 proc = self.mount_a.run_shell(['df', '.'])
213 output = proc.stdout.getvalue()
214 fs_avail = output.split('\n')[1].split()[3]
215 fs_avail = float(fs_avail) * 1024
216
217 ratio = raw_avail / fs_avail
218 assert 0.9 < ratio < 1.1
219
220 def test_dump_inode(self):
221 info = self.fs.mds_asok(['dump', 'inode', '1'])
222 assert(info['path'] == "/")
223
224 def test_dump_inode_hexademical(self):
225 self.mount_a.run_shell(["mkdir", "-p", "foo"])
226 ino = self.mount_a.path_to_ino("foo")
227 assert type(ino) is int
228 info = self.fs.mds_asok(['dump', 'inode', hex(ino)])
229 assert info['path'] == "/foo"
230
231
232 class TestCacheDrop(CephFSTestCase):
233 CLIENTS_REQUIRED = 1
234
235 def _run_drop_cache_cmd(self, timeout=None):
236 result = None
237 mds_id = self.fs.get_lone_mds_id()
238 if timeout is not None:
239 result = self.fs.mon_manager.raw_cluster_cmd("tell", "mds.{0}".format(mds_id),
240 "cache", "drop", str(timeout))
241 else:
242 result = self.fs.mon_manager.raw_cluster_cmd("tell", "mds.{0}".format(mds_id),
243 "cache", "drop")
244 return json.loads(result)
245
246 def _setup(self, max_caps=20, threshold=400):
247 # create some files
248 self.mount_a.create_n_files("dc-dir/dc-file", 1000, sync=True)
249
250 # Reduce this so the MDS doesn't rkcall the maximum for simple tests
251 self.fs.rank_asok(['config', 'set', 'mds_recall_max_caps', str(max_caps)])
252 self.fs.rank_asok(['config', 'set', 'mds_recall_max_decay_threshold', str(threshold)])
253
254 def test_drop_cache_command(self):
255 """
256 Basic test for checking drop cache command.
257 Confirm it halts without a timeout.
258 Note that the cache size post trimming is not checked here.
259 """
260 mds_min_caps_per_client = int(self.fs.get_config("mds_min_caps_per_client"))
261 self._setup()
262 result = self._run_drop_cache_cmd()
263 self.assertTrue(result['client_recall']['return_code'] == 0)
264 self.assertTrue(result['flush_journal']['return_code'] == 0)
265 # It should take at least 1 second
266 self.assertTrue(result['duration'] > 1)
267 self.assertGreaterEqual(result['trim_cache']['trimmed'], 1000-2*mds_min_caps_per_client)
268
269 def test_drop_cache_command_timeout(self):
270 """
271 Basic test for checking drop cache command.
272 Confirm recall halts early via a timeout.
273 Note that the cache size post trimming is not checked here.
274 """
275 self._setup()
276 result = self._run_drop_cache_cmd(timeout=10)
277 self.assertTrue(result['client_recall']['return_code'] == -errno.ETIMEDOUT)
278 self.assertTrue(result['flush_journal']['return_code'] == 0)
279 self.assertTrue(result['duration'] > 10)
280 self.assertGreaterEqual(result['trim_cache']['trimmed'], 100) # we did something, right?
281
282 def test_drop_cache_command_dead_timeout(self):
283 """
284 Check drop cache command with non-responding client using tell
285 interface. Note that the cache size post trimming is not checked
286 here.
287 """
288 self._setup()
289 self.mount_a.kill()
290 # Note: recall is subject to the timeout. The journal flush will
291 # be delayed due to the client being dead.
292 result = self._run_drop_cache_cmd(timeout=5)
293 self.assertTrue(result['client_recall']['return_code'] == -errno.ETIMEDOUT)
294 self.assertTrue(result['flush_journal']['return_code'] == 0)
295 self.assertTrue(result['duration'] > 5)
296 self.assertTrue(result['duration'] < 120)
297 self.assertEqual(0, result['trim_cache']['trimmed'])
298 self.mount_a.kill_cleanup()
299 self.mount_a.mount()
300 self.mount_a.wait_until_mounted()
301
302 def test_drop_cache_command_dead(self):
303 """
304 Check drop cache command with non-responding client using tell
305 interface. Note that the cache size post trimming is not checked
306 here.
307 """
308 self._setup()
309 self.mount_a.kill()
310 result = self._run_drop_cache_cmd()
311 self.assertTrue(result['client_recall']['return_code'] == 0)
312 self.assertTrue(result['flush_journal']['return_code'] == 0)
313 self.assertTrue(result['duration'] > 5)
314 self.assertTrue(result['duration'] < 120)
315 self.assertEqual(0, result['trim_cache']['trimmed'])
316 self.mount_a.kill_cleanup()
317 self.mount_a.mount()
318 self.mount_a.wait_until_mounted()