diff options
author | Thiago da Silva <thiago@redhat.com> | 2015-02-19 14:59:48 -0500 |
---|---|---|
committer | Thiago da Silva <thiago@redhat.com> | 2015-02-20 13:49:06 -0500 |
commit | b5a327eb9c0c1ec3f77a36676d6cc9878353ec1b (patch) | |
tree | 37714687e54129a0352acfd10ce30e903f82314b | |
parent | ec407b4d61b15506e6ae5b3f28d3983af4f28457 (diff) |
adding functions setfsuid and setfsgid
Did not add functional tests at the moment. This function requires
superuser privilege to execute
Change-Id: I35c0a6b3eba60586da64ccfb4dc818d403542f41
Signed-off-by: Thiago da Silva <thiago@redhat.com>
-rwxr-xr-x | glusterfs/api.py | 6 | ||||
-rwxr-xr-x | glusterfs/gfapi.py | 16 | ||||
-rw-r--r-- | test/unit/gluster/test_gfapi.py | 30 |
3 files changed, 50 insertions, 2 deletions
diff --git a/glusterfs/api.py b/glusterfs/api.py index 6bc19ea..037c893 100755 --- a/glusterfs/api.py +++ b/glusterfs/api.py @@ -223,6 +223,12 @@ glfs_rmdir = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_char_p)(('glfs_rmdir', client)) +glfs_setfsuid = ctypes.CFUNCTYPE(ctypes.c_int, + ctypes.c_uint)(('glfs_setfsuid', client)) + +glfs_setfsgid = ctypes.CFUNCTYPE(ctypes.c_int, + ctypes.c_uint)(('glfs_setfsgid', client)) + # TODO: creat and open fails on test_create_file_already_exists & test_open_file_not_exist functional testing, # noqa # when defined via function prototype.. Need to find RCA. For time being, using it from 'api.glfs_' # noqa diff --git a/glusterfs/gfapi.py b/glusterfs/gfapi.py index fc6bb27..16929df 100755 --- a/glusterfs/gfapi.py +++ b/glusterfs/gfapi.py @@ -177,8 +177,6 @@ class Dir(object): class Volume(object): - # Housekeeping functions. - def __init__(self, host, volid, proto="tcp", port=24007): # Add a reference so the module-level variable "api" doesn't # get yanked out from under us (see comment above File def'n). @@ -441,6 +439,20 @@ class Volume(object): except OSError as e: onerror(self.rmdir, path, e) + def setfsuid(self, uid): + ret = api.glfs_setfsuid(uid) + if ret < 0: + err = ctypes.get_errno() + raise OSError(err, os.strerror(err)) + return ret + + def setfsgid(self, gid): + ret = api.glfs_setfsgid(gid) + if ret < 0: + err = ctypes.get_errno() + raise OSError(err, os.strerror(err)) + return ret + def setxattr(self, path, key, value, vlen): ret = api.glfs_setxattr(self.fs, path, key, value, vlen, 0) if ret < 0: diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py index 550ba79..f772b0d 100644 --- a/test/unit/gluster/test_gfapi.py +++ b/test/unit/gluster/test_gfapi.py @@ -761,6 +761,36 @@ class TestVolume(unittest.TestCase): mock_unlink.assert_called_once_with("dir1/file") mock_rmdir.assert_called_with("dir1") + def test_setfsuid_success(self): + mock_glfs_setfsuid = Mock() + mock_glfs_setfsuid.return_value = 0 + + with patch("glusterfs.gfapi.api.glfs_setfsuid", mock_glfs_setfsuid): + ret = self.vol.setfsuid(1000) + self.assertEquals(ret, 0) + + def test_setfsuid_fail(self): + mock_glfs_setfsuid = Mock() + mock_glfs_setfsuid.return_value = -1 + + with patch("glusterfs.gfapi.api.glfs_setfsuid", mock_glfs_setfsuid): + self.assertRaises(OSError, self.vol.setfsuid, 1001) + + def test_setfsgid_success(self): + mock_glfs_setfsgid = Mock() + mock_glfs_setfsgid.return_value = 0 + + with patch("glusterfs.gfapi.api.glfs_setfsgid", mock_glfs_setfsgid): + ret = self.vol.setfsgid(1000) + self.assertEquals(ret, 0) + + def test_setfsgid_fail(self): + mock_glfs_setfsgid = Mock() + mock_glfs_setfsgid.return_value = -1 + + with patch("glusterfs.gfapi.api.glfs_setfsgid", mock_glfs_setfsgid): + self.assertRaises(OSError, self.vol.setfsgid, 1001) + def test_setxattr_success(self): mock_glfs_setxattr = Mock() mock_glfs_setxattr.return_value = 0 |