]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/cephfs/test_subvolume.py
update ceph source to reef 18.2.0
[ceph.git] / ceph / qa / tasks / cephfs / test_subvolume.py
1 import logging
2
3 from tasks.cephfs.cephfs_test_case import CephFSTestCase
4 from teuthology.exceptions import CommandFailedError
5
6 log = logging.getLogger(__name__)
7
8
9 class TestSubvolume(CephFSTestCase):
10 CLIENTS_REQUIRED = 1
11 MDSS_REQUIRED = 1
12
13 def setUp(self):
14 super().setUp()
15 self.setup_test()
16
17 def tearDown(self):
18 # clean up
19 self.cleanup_test()
20 super().tearDown()
21
22 def setup_test(self):
23 self.mount_a.run_shell(['mkdir', 'group'])
24 self.mount_a.run_shell(['mkdir', 'group/subvol1'])
25 self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
26 '-v', '1', 'group/subvol1'])
27 self.mount_a.run_shell(['mv', 'group/subvol1', 'group/subvol2'])
28
29 def cleanup_test(self):
30 self.mount_a.run_shell(['rm', '-rf', 'group'])
31
32 def test_subvolume_move_out_file(self):
33 """
34 To verify that file can't be moved out of subvolume
35 """
36 self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
37
38 # file can't be moved out of a subvolume
39 with self.assertRaises(CommandFailedError):
40 self.mount_a.run_shell(['rename', 'group/subvol2/file1',
41 'group/file1', 'group/subvol2/file1'])
42
43
44 def test_subvolume_move_in_file(self):
45 """
46 To verify that file can't be moved into subvolume
47 """
48 # file can't be moved into a subvolume
49 self.mount_a.run_shell(['touch', 'group/file2'])
50 with self.assertRaises(CommandFailedError):
51 self.mount_a.run_shell(['rename', 'group/file2',
52 'group/subvol2/file2', 'group/file2'])
53
54 def test_subvolume_hardlink_to_outside(self):
55 """
56 To verify that file can't be hardlinked to outside subvolume
57 """
58 self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
59
60 # create hard link within subvolume
61 self.mount_a.run_shell(['ln',
62 'group/subvol2/file1', 'group/subvol2/file1_'])
63
64 # hard link can't be created out of subvolume
65 with self.assertRaises(CommandFailedError):
66 self.mount_a.run_shell(['ln',
67 'group/subvol2/file1', 'group/file1_'])
68
69 def test_subvolume_hardlink_to_inside(self):
70 """
71 To verify that file can't be hardlinked to inside subvolume
72 """
73 self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
74
75 # create hard link within subvolume
76 self.mount_a.run_shell(['ln',
77 'group/subvol2/file1', 'group/subvol2/file1_'])
78
79 # hard link can't be created inside subvolume
80 self.mount_a.run_shell(['touch', 'group/file2'])
81 with self.assertRaises(CommandFailedError):
82 self.mount_a.run_shell(['ln',
83 'group/file2', 'group/subvol2/file2_'])
84
85 def test_subvolume_snapshot_inside_subvolume_subdir(self):
86 """
87 To verify that snapshot can't be taken for a subvolume subdir
88 """
89 self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
90
91 # create snapshot at subvolume root
92 self.mount_a.run_shell(['mkdir', 'group/subvol2/.snap/s1'])
93
94 # can't create snapshot in a descendent dir of subvolume
95 self.mount_a.run_shell(['mkdir', 'group/subvol2/dir'])
96 with self.assertRaises(CommandFailedError):
97 self.mount_a.run_shell(['mkdir', 'group/subvol2/dir/.snap/s2'])
98
99 # clean up
100 self.mount_a.run_shell(['rmdir', 'group/subvol2/.snap/s1'])
101
102 def test_subvolume_file_move_across_subvolumes(self):
103 """
104 To verify that file can't be moved across subvolumes
105 """
106 self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
107
108 # create another subvol
109 self.mount_a.run_shell(['mkdir', 'group/subvol3'])
110 self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
111 '-v', '1', 'group/subvol3'])
112
113 # can't move file across subvolumes
114 with self.assertRaises(CommandFailedError):
115 self.mount_a.run_shell(['rename', 'group/subvol2/file1',
116 'group/subvol3/file1',
117 'group/subvol2/file1'])
118
119 def test_subvolume_hardlink_across_subvolumes(self):
120 """
121 To verify that hardlink can't be created across subvolumes
122 """
123 self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
124
125 # create another subvol
126 self.mount_a.run_shell(['mkdir', 'group/subvol3'])
127 self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
128 '-v', '1', 'group/subvol3'])
129
130 # can't create hard link across subvolumes
131 with self.assertRaises(CommandFailedError):
132 self.mount_a.run_shell(['ln', 'group/subvol2/file1',
133 'group/subvol3/file1'])
134
135 def test_subvolume_create_subvolume_inside_subvolume(self):
136 """
137 To verify that subvolume can't be created inside a subvolume
138 """
139 # can't create subvolume inside a subvolume
140 self.mount_a.run_shell(['mkdir', 'group/subvol2/dir'])
141 with self.assertRaises(CommandFailedError):
142 self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
143 '-v', '1', 'group/subvol2/dir'])
144
145 def test_subvolume_create_snapshot_inside_new_subvolume_parent(self):
146 """
147 To verify that subvolume can't be created inside a new subvolume parent
148 """
149 self.mount_a.run_shell(['touch', 'group/subvol2/file1'])
150
151 # clear subvolume flag
152 self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
153 '-v', '0', 'group/subvol2'])
154
155 # create a snap
156 self.mount_a.run_shell(['mkdir', 'group/subvol2/dir'])
157 self.mount_a.run_shell(['mkdir', 'group/subvol2/dir/.snap/s2'])
158
159 # override subdir subvolume with parent subvolume
160 self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
161 '-v', '1', 'group/subvol2/dir'])
162 self.mount_a.run_shell(['setfattr', '-n', 'ceph.dir.subvolume',
163 '-v', '1', 'group/subvol2'])
164
165 # can't create a snap in a subdir of a subvol parent
166 with self.assertRaises(CommandFailedError):
167 self.mount_a.run_shell(['mkdir', 'group/subvol2/dir/.snap/s3'])
168
169 # clean up
170 self.mount_a.run_shell(['rmdir', 'group/subvol2/dir/.snap/s2'])