class CapsHelper(CephFSTestCase):
- def write_test_files(self, mounts):
+ def write_test_files(self, mounts, testpath=''):
"""
Exercising 'r' and 'w' access levels on a file on CephFS mount is
pretty routine across all tests for caps. Adding to method to write
"""
filepaths, filedata = [], 'testdata'
dirname, filename = 'testdir', 'testfile'
+ # XXX: The reason behind testpath[1:] below is that the testpath is
+ # supposed to contain a path inside CephFS (which might be passed as
+ # an absolute path). os.path.join() deletes all previous path
+ # components when it encounters a path component starting with '/'.
+ # Deleting the first '/' from the string in testpath ensures that
+ # previous path components are not deleted by os.path.join().
+ if testpath:
+ testpath = testpath[1:] if testpath[0] == '/' else testpath
+ # XXX: passing just '/' screw up os.path.join() ahead.
+ if testpath == '/':
+ testpath = ''
for mount_x in mounts:
- dirpath = os_path_join(mount_x.hostfs_mntpt, dirname)
+ dirpath = os_path_join(mount_x.hostfs_mntpt, testpath, dirname)
mount_x.run_shell(f'mkdir {dirpath}')
filepath = os_path_join(dirpath, filename)
mount_x.write_file(filepath, filedata)
return filepaths, (filedata,), mounts
- def run_cap_tests(self, filepaths, filedata, mounts, perm):
+ def run_cap_tests(self, filepaths, filedata, mounts, perm, mntpt=None):
# TODO
#self.run_mon_cap_tests()
- self.run_mds_cap_tests(filepaths, filedata, mounts, perm)
+ self.run_mds_cap_tests(filepaths, filedata, mounts, perm, mntpt=mntpt)
def run_mon_cap_tests(self, moncap, keyring):
keyring_path = self.fs.admin_remote.mktemp(data=keyring)
else:
self.assertNotIn('name: ' + fsname, fsls)
- def run_mds_cap_tests(self, filepaths, filedata, mounts, perm):
+ def run_mds_cap_tests(self, filepaths, filedata, mounts, perm, mntpt=None):
+ # XXX: mntpt is path inside cephfs that serves as root for current
+ # mount. Therefore, this path must me deleted from filepaths.
+ # Example -
+ # orignal path: /mnt/cephfs_x/dir1/dir2/testdir
+ # cephfs dir serving as root for current mnt: /dir1/dir2
+ # therefore, final path: /mnt/cephfs_x//testdir
+ if mntpt:
+ filepaths = [x.replace(mntpt, '') for x in filepaths]
+
self.conduct_pos_test_for_read_caps(filepaths, filedata, mounts)
if perm == 'rw':