2015-04-28 04:52:36 +00:00
|
|
|
from textwrap import dedent
|
|
|
|
from tasks.cephfs.cephfs_test_case import CephFSTestCase
|
|
|
|
import os
|
|
|
|
|
2015-07-27 22:18:23 +00:00
|
|
|
|
2015-04-28 04:52:36 +00:00
|
|
|
class TestPoolPerm(CephFSTestCase):
|
|
|
|
def test_pool_perm(self):
|
|
|
|
self.mount_a.run_shell(["touch", "test_file"])
|
|
|
|
|
2015-07-27 22:18:23 +00:00
|
|
|
file_path = os.path.join(self.mount_a.mountpoint, "test_file")
|
2015-04-28 04:52:36 +00:00
|
|
|
|
|
|
|
remote_script = dedent("""
|
|
|
|
import os
|
|
|
|
import errno
|
|
|
|
|
|
|
|
fd = os.open("{path}", os.O_RDWR)
|
|
|
|
try:
|
|
|
|
if {check_read}:
|
|
|
|
ret = os.read(fd, 1024)
|
|
|
|
else:
|
|
|
|
os.write(fd, 'content')
|
|
|
|
except OSError, e:
|
|
|
|
if e.errno != errno.EPERM:
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
raise RuntimeError("client does not check permission of data pool")
|
|
|
|
""")
|
|
|
|
|
2015-07-27 22:20:24 +00:00
|
|
|
client_name = "client.{0}".format(self.mount_a.client_id)
|
|
|
|
|
2015-04-28 04:52:36 +00:00
|
|
|
# set data pool read only
|
2015-07-27 22:20:24 +00:00
|
|
|
self.fs.mon_manager.raw_cluster_cmd_result('auth', 'caps', client_name, 'mon', 'allow r', 'osd',
|
2015-07-27 22:18:23 +00:00
|
|
|
'allow r pool=data')
|
2015-04-28 04:52:36 +00:00
|
|
|
|
|
|
|
self.mount_a.umount_wait()
|
|
|
|
self.mount_a.mount()
|
|
|
|
self.mount_a.wait_until_mounted()
|
|
|
|
|
|
|
|
# write should fail
|
|
|
|
self.mount_a.run_python(remote_script.format(path=file_path, check_read=str(False)))
|
|
|
|
|
|
|
|
# set data pool write only
|
2015-07-27 22:20:24 +00:00
|
|
|
self.fs.mon_manager.raw_cluster_cmd_result('auth', 'caps', client_name, 'mon', 'allow r', 'osd',
|
2015-07-27 22:18:23 +00:00
|
|
|
'allow w pool=data')
|
2015-04-28 04:52:36 +00:00
|
|
|
|
|
|
|
self.mount_a.umount_wait()
|
|
|
|
self.mount_a.mount()
|
|
|
|
self.mount_a.wait_until_mounted()
|
|
|
|
|
|
|
|
# read should fail
|
|
|
|
self.mount_a.run_python(remote_script.format(path=file_path, check_read=str(True)))
|
2015-07-27 22:29:06 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.fs.mon_manager.raw_cluster_cmd_result('auth', 'caps', "client.{0}".format(self.mount_a.client_id),
|
|
|
|
'mon', 'allow r', 'osd', 'allow rw pool=data')
|
|
|
|
|
|
|
|
super(CephFSTestCase, self).tearDown()
|