diff options
author | Alpha <alpha@pokesplash.net> | 2015-08-31 01:28:53 -0400 |
---|---|---|
committer | Prashanth Pai <ppai@redhat.com> | 2018-03-28 17:39:15 +0530 |
commit | 4fe135300dbb7b7c9f3f0d0676ea76149414fb6b (patch) | |
tree | b77570e5152e195c2c9395d32882c4f65312613e | |
parent | b5073b090535744608164e266badba919298f894 (diff) |
Disable logging by default
Superusers should not be required to use this API with default settings.
Provide a disable_logging method of Volume. Ensure that set_logging
gets called with new values.
Change-Id: Ia27a682c96d6ca28f85d43f9d8483f08d1dc6367
Signed-off-by: Alpha <alpha@pokesplash.net>
Signed-off-by: Prashanth Pai <ppai@redhat.com>
-rw-r--r-- | gluster/gfapi/gfapi.py | 16 | ||||
-rw-r--r-- | test/functional/libgfapi-python-tests.py | 2 | ||||
-rw-r--r-- | test/unit/gluster/test_gfapi.py | 2 |
3 files changed, 13 insertions, 7 deletions
diff --git a/gluster/gfapi/gfapi.py b/gluster/gfapi/gfapi.py index c01d534..eedc03b 100644 --- a/gluster/gfapi/gfapi.py +++ b/gluster/gfapi/gfapi.py @@ -626,7 +626,7 @@ class DirEntry(object): class Volume(object): def __init__(self, host, volname, - proto="tcp", port=24007, log_file=None, log_level=7): + proto="tcp", port=24007, log_file="/dev/null", log_level=7): """ Create a Volume object instance. @@ -638,7 +638,7 @@ class Volume(object): :param port: Port number where gluster management daemon is listening. :param log_file: Path to log file. When this is set to None, a new logfile will be created in default log directory - i.e /var/log/glusterfs + i.e /var/log/glusterfs. The default is "/dev/null" :param log_level: Integer specifying the degree of verbosity. Higher the value, more verbose the logging. @@ -762,22 +762,28 @@ class Volume(object): Higher the value, more verbose the logging. """ if self.fs: - ret = api.glfs_set_logging(self.fs, self.log_file, self.log_level) + ret = api.glfs_set_logging(self.fs, log_file, log_level) if ret < 0: err = ctypes.get_errno() raise LibgfapiException("glfs_set_logging(%s, %s) failed: %s" % - (self.log_file, self.log_level, + (log_file, log_level, os.strerror(err))) self.log_file = log_file self.log_level = log_level + def disable_logging(self): + """ + Sends logs to /dev/null effectively disabling them + """ + self.set_logging("/dev/null", self.log_level) + @validate_mount def get_volume_id(self): """ Returns the volume ID (of type uuid.UUID) for the currently mounted volume. """ - if self.volid != None: + if self.volid is not None: return self.volid size = 16 buf = ctypes.create_string_buffer(size) diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py index 58bda89..8f631d4 100644 --- a/test/functional/libgfapi-python-tests.py +++ b/test/functional/libgfapi-python-tests.py @@ -1095,7 +1095,7 @@ class TestVolumeInit(unittest.TestCase): # Create volume object instance vol = Volume(HOST, VOLNAME) # Check attribute init - self.assertEqual(vol.log_file, None) + self.assertEqual(vol.log_file, "/dev/null") self.assertEqual(vol.log_level, 7) self.assertEqual(vol.host, HOST) self.assertEqual(vol.volname, VOLNAME) diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py index 4b58597..4216f96 100644 --- a/test/unit/gluster/test_gfapi.py +++ b/test/unit/gluster/test_gfapi.py @@ -449,7 +449,7 @@ class TestVolume(unittest.TestCase): _m_set_logging = Mock(return_value=-1) with patch("gluster.gfapi.api.glfs_set_logging", _m_set_logging): self.assertRaises(LibgfapiException, v.set_logging, "/dev/null", 7) - _m_set_logging.assert_called_once_with(v.fs, None, 7) + _m_set_logging.assert_called_once_with(v.fs, "/dev/null", 7) def test_chmod_success(self): mock_glfs_chmod = Mock() |