]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/cephfs/test_volumes.py
7 from tasks
.cephfs
.cephfs_test_case
import CephFSTestCase
8 from teuthology
.exceptions
import CommandFailedError
10 log
= logging
.getLogger(__name__
)
12 class TestVolumes(CephFSTestCase
):
13 TEST_VOLUME_NAME
= "fs_test_vol"
14 TEST_SUBVOLUME_PREFIX
="subvolume"
15 TEST_GROUP_PREFIX
="group"
16 TEST_SNAPSHOT_PREFIX
="snapshot"
18 def _fs_cmd(self
, *args
):
19 return self
.mgr_cluster
.mon_manager
.raw_cluster_cmd("fs", *args
)
21 def _generate_random_subvolume_name(self
):
22 return "{0}_{1}".format(TestVolumes
.TEST_SUBVOLUME_PREFIX
, random
.randint(0, 10000))
24 def _generate_random_group_name(self
):
25 return "{0}_{1}".format(TestVolumes
.TEST_GROUP_PREFIX
, random
.randint(0, 100))
27 def _generate_random_snapshot_name(self
):
28 return "{0}_{1}".format(TestVolumes
.TEST_SNAPSHOT_PREFIX
, random
.randint(0, 100))
30 def _enable_multi_fs(self
):
31 self
._fs
_cmd
("flag", "set", "enable_multiple", "true", "--yes-i-really-mean-it")
33 def _create_or_reuse_test_volume(self
):
34 result
= json
.loads(self
._fs
_cmd
("volume", "ls"))
36 self
.vol_created
= True
37 self
.volname
= TestVolumes
.TEST_VOLUME_NAME
38 self
._fs
_cmd
("volume", "create", self
.volname
)
40 self
.volname
= result
[0]['name']
42 def _get_subvolume_path(self
, vol_name
, subvol_name
, group_name
=None):
43 args
= ["subvolume", "getpath", vol_name
, subvol_name
]
45 args
.append(group_name
)
47 path
= self
._fs
_cmd
(*args
)
48 # remove the leading '/', and trailing whitespaces
49 return path
[1:].rstrip()
51 def _delete_test_volume(self
):
52 self
._fs
_cmd
("volume", "rm", self
.volname
)
55 super(TestVolumes
, self
).setUp()
57 self
.vol_created
= False
58 self
._enable
_multi
_fs
()
59 self
._create
_or
_reuse
_test
_volume
()
63 self
._delete
_test
_volume
()
64 super(TestVolumes
, self
).tearDown()
66 ### basic subvolume operations
68 def test_subvolume_create_and_rm(self
):
70 subvolume
= self
._generate
_random
_subvolume
_name
()
71 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
)
74 subvolpath
= self
._fs
_cmd
("subvolume", "getpath", self
.volname
, subvolume
)
75 self
.assertNotEqual(subvolpath
, None)
78 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
)
81 self
._fs
_cmd
("subvolume", "getpath", self
.volname
, subvolume
)
82 except CommandFailedError
as ce
:
83 if ce
.exitstatus
!= errno
.ENOENT
:
86 def test_subvolume_create_idempotence(self
):
88 subvolume
= self
._generate
_random
_subvolume
_name
()
89 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
)
91 # try creating w/ same subvolume name -- should be idempotent
92 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
)
95 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
)
97 def test_nonexistent_subvolume_rm(self
):
98 # remove non-existing subvolume
99 subvolume
= "non_existent_subvolume"
101 # try, remove subvolume
103 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
)
104 except CommandFailedError
as ce
:
105 if ce
.exitstatus
!= errno
.ENOENT
:
108 # force remove subvolume
109 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
, "--force")
111 def test_nonexistent_subvolume_group_create(self
):
112 subvolume
= self
._generate
_random
_subvolume
_name
()
113 group
= "non_existent_group"
115 # try, creating subvolume in a nonexistent group
117 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
, "--group_name", group
)
118 except CommandFailedError
as ce
:
119 if ce
.exitstatus
!= errno
.ENOENT
:
122 ### subvolume group operations
124 def test_subvolume_create_and_rm_in_group(self
):
125 subvolume
= self
._generate
_random
_subvolume
_name
()
126 group
= self
._generate
_random
_group
_name
()
129 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group
)
131 # create subvolume in group
132 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
, "--group_name", group
)
135 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
, group
)
138 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
)
140 def test_subvolume_group_create_with_desired_data_pool_layout(self
):
141 group1
= self
._generate
_random
_group
_name
()
142 group2
= self
._generate
_random
_group
_name
()
145 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group1
)
146 group1_path
= os
.path
.join('volumes', group1
)
148 default_pool
= self
.mount_a
.getfattr(group1_path
, "ceph.dir.layout.pool")
149 new_pool
= "new_pool"
150 self
.assertNotEqual(default_pool
, new_pool
)
153 self
.fs
.add_data_pool(new_pool
)
155 # create group specifying the new data pool as its pool layout
156 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group2
,
157 "--pool_layout", new_pool
)
158 group2_path
= os
.path
.join('volumes', group2
)
160 desired_pool
= self
.mount_a
.getfattr(group2_path
, "ceph.dir.layout.pool")
161 self
.assertEqual(desired_pool
, new_pool
)
163 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group1
)
164 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group2
)
166 def test_subvolume_create_with_desired_data_pool_layout_in_group(self
):
167 subvol1
= self
._generate
_random
_subvolume
_name
()
168 subvol2
= self
._generate
_random
_subvolume
_name
()
169 group
= self
._generate
_random
_group
_name
()
171 # create group. this also helps set default pool layout for subvolumes
172 # created within the group.
173 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group
)
175 # create subvolume in group.
176 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvol1
, "--group_name", group
)
177 subvol1_path
= self
._get
_subvolume
_path
(self
.volname
, subvol1
, group_name
=group
)
179 default_pool
= self
.mount_a
.getfattr(subvol1_path
, "ceph.dir.layout.pool")
180 new_pool
= "new_pool"
181 self
.assertNotEqual(default_pool
, new_pool
)
184 self
.fs
.add_data_pool(new_pool
)
186 # create subvolume specifying the new data pool as its pool layout
187 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvol2
, "--group_name", group
,
188 "--pool_layout", new_pool
)
189 subvol2_path
= self
._get
_subvolume
_path
(self
.volname
, subvol2
, group_name
=group
)
191 desired_pool
= self
.mount_a
.getfattr(subvol2_path
, "ceph.dir.layout.pool")
192 self
.assertEqual(desired_pool
, new_pool
)
194 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvol2
, group
)
195 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvol1
, group
)
196 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
)
198 def test_subvolume_group_create_with_desired_mode(self
):
199 group1
= self
._generate
_random
_group
_name
()
200 group2
= self
._generate
_random
_group
_name
()
202 expected_mode1
= "755"
204 expected_mode2
= "777"
207 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group1
)
208 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group2
, "--mode", "777")
210 group1_path
= os
.path
.join('volumes', group1
)
211 group2_path
= os
.path
.join('volumes', group2
)
214 actual_mode1
= self
.mount_a
.run_shell(['stat', '-c' '%a', group1_path
]).stdout
.getvalue().strip()
215 actual_mode2
= self
.mount_a
.run_shell(['stat', '-c' '%a', group2_path
]).stdout
.getvalue().strip()
216 self
.assertEqual(actual_mode1
, expected_mode1
)
217 self
.assertEqual(actual_mode2
, expected_mode2
)
219 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group1
)
220 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group2
)
222 def test_subvolume_create_with_desired_mode_in_group(self
):
223 subvol1
= self
._generate
_random
_subvolume
_name
()
224 subvol2
= self
._generate
_random
_subvolume
_name
()
225 subvol3
= self
._generate
_random
_subvolume
_name
()
226 group
= self
._generate
_random
_group
_name
()
228 expected_mode1
= "755"
230 expected_mode2
= "777"
233 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group
)
235 # create subvolume in group
236 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvol1
, "--group_name", group
)
237 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvol2
, "--group_name", group
, "--mode", "777")
238 # check whether mode 0777 also works
239 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvol3
, "--group_name", group
, "--mode", "0777")
241 subvol1_path
= self
._get
_subvolume
_path
(self
.volname
, subvol1
, group_name
=group
)
242 subvol2_path
= self
._get
_subvolume
_path
(self
.volname
, subvol2
, group_name
=group
)
243 subvol3_path
= self
._get
_subvolume
_path
(self
.volname
, subvol3
, group_name
=group
)
245 # check subvolume's mode
246 actual_mode1
= self
.mount_a
.run_shell(['stat', '-c' '%a', subvol1_path
]).stdout
.getvalue().strip()
247 actual_mode2
= self
.mount_a
.run_shell(['stat', '-c' '%a', subvol2_path
]).stdout
.getvalue().strip()
248 actual_mode3
= self
.mount_a
.run_shell(['stat', '-c' '%a', subvol3_path
]).stdout
.getvalue().strip()
249 self
.assertEqual(actual_mode1
, expected_mode1
)
250 self
.assertEqual(actual_mode2
, expected_mode2
)
251 self
.assertEqual(actual_mode3
, expected_mode2
)
253 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvol2
, group
)
254 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvol1
, group
)
255 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
)
257 def test_nonexistent_subvolme_group_rm(self
):
258 group
= "non_existent_group"
260 # try, remove subvolume group
262 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
)
263 except CommandFailedError
as ce
:
264 if ce
.exitstatus
!= errno
.ENOENT
:
267 # force remove subvolume
268 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
, "--force")
270 ### snapshot operations
272 def test_subvolume_snapshot_create_and_rm(self
):
273 subvolume
= self
._generate
_random
_subvolume
_name
()
274 snapshot
= self
._generate
_random
_snapshot
_name
()
277 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
)
280 self
._fs
_cmd
("subvolume", "snapshot", "create", self
.volname
, subvolume
, snapshot
)
283 self
._fs
_cmd
("subvolume", "snapshot", "rm", self
.volname
, subvolume
, snapshot
)
286 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
)
288 def test_subvolume_snapshot_create_idempotence(self
):
289 subvolume
= self
._generate
_random
_subvolume
_name
()
290 snapshot
= self
._generate
_random
_snapshot
_name
()
293 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
)
296 self
._fs
_cmd
("subvolume", "snapshot", "create", self
.volname
, subvolume
, snapshot
)
298 # try creating w/ same subvolume snapshot name -- should be idempotent
299 self
._fs
_cmd
("subvolume", "snapshot", "create", self
.volname
, subvolume
, snapshot
)
302 self
._fs
_cmd
("subvolume", "snapshot", "rm", self
.volname
, subvolume
, snapshot
)
305 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
)
307 def test_nonexistent_subvolume_snapshot_rm(self
):
308 subvolume
= self
._generate
_random
_subvolume
_name
()
309 snapshot
= self
._generate
_random
_snapshot
_name
()
312 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
)
315 self
._fs
_cmd
("subvolume", "snapshot", "create", self
.volname
, subvolume
, snapshot
)
318 self
._fs
_cmd
("subvolume", "snapshot", "rm", self
.volname
, subvolume
, snapshot
)
320 # remove snapshot again
322 self
._fs
_cmd
("subvolume", "snapshot", "rm", self
.volname
, subvolume
, snapshot
)
323 except CommandFailedError
as ce
:
324 if ce
.exitstatus
!= errno
.ENOENT
:
327 # force remove snapshot
328 self
._fs
_cmd
("subvolume", "snapshot", "rm", self
.volname
, subvolume
, snapshot
, "--force")
331 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
)
333 def test_subvolume_snapshot_in_group(self
):
334 subvolume
= self
._generate
_random
_subvolume
_name
()
335 group
= self
._generate
_random
_group
_name
()
336 snapshot
= self
._generate
_random
_snapshot
_name
()
339 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group
)
341 # create subvolume in group
342 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
, "--group_name", group
)
344 # snapshot subvolume in group
345 self
._fs
_cmd
("subvolume", "snapshot", "create", self
.volname
, subvolume
, snapshot
, group
)
348 self
._fs
_cmd
("subvolume", "snapshot", "rm", self
.volname
, subvolume
, snapshot
, group
)
351 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
, group
)
354 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
)
356 def test_subvolume_group_snapshot_create_and_rm(self
):
357 subvolume
= self
._generate
_random
_subvolume
_name
()
358 group
= self
._generate
_random
_group
_name
()
359 snapshot
= self
._generate
_random
_snapshot
_name
()
362 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group
)
364 # create subvolume in group
365 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
, "--group_name", group
)
368 self
._fs
_cmd
("subvolumegroup", "snapshot", "create", self
.volname
, group
, snapshot
)
371 self
._fs
_cmd
("subvolumegroup", "snapshot", "rm", self
.volname
, group
, snapshot
)
374 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
, group
)
377 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
)
379 def test_subvolume_group_snapshot_idempotence(self
):
380 subvolume
= self
._generate
_random
_subvolume
_name
()
381 group
= self
._generate
_random
_group
_name
()
382 snapshot
= self
._generate
_random
_snapshot
_name
()
385 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group
)
387 # create subvolume in group
388 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
, "--group_name", group
)
391 self
._fs
_cmd
("subvolumegroup", "snapshot", "create", self
.volname
, group
, snapshot
)
393 # try creating snapshot w/ same snapshot name -- shoule be idempotent
394 self
._fs
_cmd
("subvolumegroup", "snapshot", "create", self
.volname
, group
, snapshot
)
397 self
._fs
_cmd
("subvolumegroup", "snapshot", "rm", self
.volname
, group
, snapshot
)
400 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
, group
)
403 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
)
405 def test_nonexistent_subvolume_group_snapshot_rm(self
):
406 subvolume
= self
._generate
_random
_subvolume
_name
()
407 group
= self
._generate
_random
_group
_name
()
408 snapshot
= self
._generate
_random
_snapshot
_name
()
411 self
._fs
_cmd
("subvolumegroup", "create", self
.volname
, group
)
413 # create subvolume in group
414 self
._fs
_cmd
("subvolume", "create", self
.volname
, subvolume
, "--group_name", group
)
417 self
._fs
_cmd
("subvolumegroup", "snapshot", "create", self
.volname
, group
, snapshot
)
420 self
._fs
_cmd
("subvolumegroup", "snapshot", "rm", self
.volname
, group
, snapshot
)
424 self
._fs
_cmd
("subvolumegroup", "snapshot", "rm", self
.volname
, group
, snapshot
)
425 except CommandFailedError
as ce
:
426 if ce
.exitstatus
!= errno
.ENOENT
:
430 self
._fs
_cmd
("subvolume", "rm", self
.volname
, subvolume
, group
)
433 self
._fs
_cmd
("subvolumegroup", "rm", self
.volname
, group
)