Commit 1b045f5d authored by Balazs Lecz's avatar Balazs Lecz
Browse files

Add utils.GetMounts()


Signed-off-by: default avatarBalazs Lecz <leczb@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 425f0f54
......@@ -176,6 +176,8 @@ LOG_BURNIN = LOG_DIR + "burnin.log"
DEV_CONSOLE = "/dev/console"
PROC_MOUNTS = "/proc/mounts"
# luxi related constants
LUXI_EOM = "\3"
......
......@@ -3156,6 +3156,26 @@ def CalculateDirectorySize(path):
return BytesToMebibyte(size)
def GetMounts(filename=constants.PROC_MOUNTS):
"""Returns the list of mounted filesystems.
This function is Linux-specific.
@param filename: path of mounts file (/proc/mounts by default)
@rtype: list of tuples
@return: list of mount entries (device, mountpoint, fstype, options)
"""
# TODO(iustin): investigate non-Linux options (e.g. via mount output)
data = []
mountlines = ReadFile(filename).splitlines()
for line in mountlines:
device, mountpoint, fstype, options, _ = line.split(None, 4)
data.append((device, mountpoint, fstype, options))
return data
def GetFilesystemStats(path):
"""Returns the total and free space on a filesystem.
......
......@@ -1148,6 +1148,27 @@ class TestEtcHosts(testutils.GanetiTestCase):
self.assertFileMode(self.tmpname, 0644)
class TestGetMounts(unittest.TestCase):
"""Test case for GetMounts()."""
TESTDATA = (
"rootfs / rootfs rw 0 0\n"
"none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
"none /proc proc rw,nosuid,nodev,noexec,relatime 0 0\n")
def setUp(self):
self.tmpfile = tempfile.NamedTemporaryFile()
utils.WriteFile(self.tmpfile.name, data=self.TESTDATA)
def testGetMounts(self):
self.assertEqual(utils.GetMounts(filename=self.tmpfile.name),
[
("rootfs", "/", "rootfs", "rw"),
("none", "/sys", "sysfs", "rw,nosuid,nodev,noexec,relatime"),
("none", "/proc", "proc", "rw,nosuid,nodev,noexec,relatime"),
])
class TestShellQuoting(unittest.TestCase):
"""Test case for shell quoting functions"""
......
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