From: Rishabh Dave Date: Thu, 9 Jun 2022 15:09:40 +0000 (+0530) Subject: qa/cephfs: refactor and upgrade test_single_path_rootsquash X-Git-Tag: v18.0.0~162^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=34e94e9ae53776b9cfb77558a6228edff6bfd41e;p=ceph.git qa/cephfs: refactor and upgrade test_single_path_rootsquash test_single_path_rootsquash instead of using helper methods duplicates the code from those methods. This commit fixes that and also upgrade this method since caps_helper was upgraded in previous commits. Signed-off-by: Rishabh Dave --- diff --git a/qa/tasks/cephfs/caps_helper.py b/qa/tasks/cephfs/caps_helper.py index 2eeb49a8dba9..ac9bc4401d94 100644 --- a/qa/tasks/cephfs/caps_helper.py +++ b/qa/tasks/cephfs/caps_helper.py @@ -179,9 +179,10 @@ class CapTester(CephFSTestCase): log.info(f'write perm was tested was successfully: data ' f'"{data}" was successfully written to file "{path}".') - def conduct_neg_test_for_write_caps(self): + def conduct_neg_test_for_write_caps(self, sudo_write=False): possible_errmsgs = ('permission denied', 'operation not permitted') - cmdargs = ['echo', 'some random data', Raw('|'), 'tee'] + cmdargs = ['echo', 'some random data', Raw('|')] + cmdargs += ['sudo', 'tee'] if sudo_write else ['tee'] # don't use data, cmd args to write are set already above. for mount, path, data in self.test_set: diff --git a/qa/tasks/cephfs/test_admin.py b/qa/tasks/cephfs/test_admin.py index 4f85bc84f59c..00290a214893 100644 --- a/qa/tasks/cephfs/test_admin.py +++ b/qa/tasks/cephfs/test_admin.py @@ -6,7 +6,6 @@ import uuid from io import StringIO from os.path import join as os_path_join -from teuthology.orchestra.run import Raw from teuthology.exceptions import CommandFailedError from tasks.cephfs.cephfs_test_case import CephFSTestCase @@ -1223,22 +1222,16 @@ class TestFsAuthorize(CephFSTestCase): self.captester.run_mds_cap_tests(PERM) def test_single_path_rootsquash(self): - filedata, filename = 'some data on fs 1', 'file_on_fs1' - filepath = os_path_join(self.mount_a.hostfs_mntpt, filename) - self.mount_a.write_file(filepath, filedata) + PERM = 'rw' + FS_AUTH_CAPS = (('/', PERM, 'root_squash'),) + self.captester = CapTester() + self.setup_test_env(FS_AUTH_CAPS) - keyring = self.fs.authorize(self.client_id, ('/', 'rw', 'root_squash')) - keyring_path = self.mount_a.client_remote.mktemp(data=keyring) - self.mount_a.remount(client_id=self.client_id, - client_keyring_path=keyring_path, - cephfs_mntpt='/') - - if filepath.find(self.mount_a.hostfs_mntpt) != -1: - # can read, but not write as root - contents = self.mount_a.read_file(filepath) - self.assertEqual(filedata, contents) - cmdargs = ['echo', 'some random data', Raw('|'), 'sudo', 'tee', filepath] - self.mount_a.negtestcmd(args=cmdargs, retval=1, errmsgs='permission denied') + # testing MDS caps... + # Since root_squash is set in client caps, client can read but not + # write even thought access level is set to "rw". + self.captester.conduct_pos_test_for_read_caps() + self.captester.conduct_neg_test_for_write_caps(sudo_write=True) def test_single_path_authorize_on_nonalphanumeric_fsname(self): """