Commit 549071a0 authored by Luca Bigliardi's avatar Luca Bigliardi

BaseDRBD: provide a way to query usermode_helper parameter

Signed-off-by: default avatarLuca Bigliardi <shammash@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 90ed09b0
......@@ -358,6 +358,7 @@ TEST_FILES = \
test/data/proc_drbd8.txt \
test/data/proc_drbd80-emptyline.txt \
test/data/proc_drbd83.txt \
test/data/sys_drbd_usermode_helper.txt \
test/import-export_unittest-helper
python_tests = \
......
......@@ -825,6 +825,7 @@ class BaseDRBD(BlockDev): # pylint: disable-msg=W0223
_ST_CONNECTED = "Connected"
_STATUS_FILE = "/proc/drbd"
_USERMODE_HELPER_FILE = "/sys/module/drbd/parameters/usermode_helper"
@staticmethod
def _GetProcData(filename=_STATUS_FILE):
......@@ -902,6 +903,23 @@ class BaseDRBD(BlockDev): # pylint: disable-msg=W0223
return retval
@staticmethod
def GetUsermodeHelper(filename=_USERMODE_HELPER_FILE):
"""Returns DRBD usermode_helper currently set.
"""
try:
helper = utils.ReadFile(filename).splitlines()[0]
except EnvironmentError, err:
if err.errno == errno.ENOENT:
_ThrowError("The file %s cannot be opened, check if the module"
" is loaded (%s)", filename, str(err))
else:
_ThrowError("Can't read DRBD helper file %s: %s", filename, str(err))
if not helper:
_ThrowError("Can't read any data from %s", filename)
return helper
@staticmethod
def _DevPath(minor):
"""Return the path to a drbd device for a given minor.
......
......@@ -143,6 +143,19 @@ class TestDRBD8Status(testutils.GanetiTestCase):
self.failUnlessRaises(errors.BlockDeviceError,
bdev.DRBD8._GetProcData, filename=temp_file)
def testHelper(self):
"""Test reading usermode_helper in /sys."""
sys_drbd_helper = self._TestDataFilename("sys_drbd_usermode_helper.txt")
drbd_helper = bdev.DRBD8.GetUsermodeHelper(filename=sys_drbd_helper)
self.failUnlessEqual(drbd_helper, "/bin/true")
def testHelperIOErrors(self):
"""Test handling of errors while reading usermode_helper in /sys."""
temp_file = self._CreateTempFile()
os.unlink(temp_file)
self.failUnlessRaises(errors.BlockDeviceError,
bdev.DRBD8.GetUsermodeHelper, filename=temp_file)
def testMinorNotFound(self):
"""Test not-found-minor in /proc"""
self.failUnless(9 not in self.mass_data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment