'Test the parser for linux mounts.'

def testLinGetRawDevice(self):

    proc_mounts = 'rootfs    /    rootfs    rw    0    0\nnone    /sys    sysfs    rw,nosuid,nodev,noexec,relatime    0    0\nnone    /proc    proc    rw,nosuid,nodev,noexec,relatime    0    0\nnone    /dev    devtmpfs    rw,relatime,size=4056920k,nr_inodes=1014230,mode=755    0    0\nnone    /dev/pts    devpts    rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000    0    0\n/dev/mapper/root    /    ext4    rw,relatime,errors=remount-ro,barrier=1,data=ordered    0    0\nnone    /sys/fs/fuse/connections    fusectl    rw,relatime    0    0\nnone    /sys/kernel/debug    debugfs    rw,relatime    0    0\nnone    /sys/kernel/security    securityfs    rw,relatime    0    0\nnone    /dev/shm    tmpfs    rw,nosuid,nodev,relatime    0    0\nnone    /var/run    tmpfs    rw,nosuid,relatime    0    0\nnone    /var/lock    tmpfs    rw,nosuid,nodev,noexec,relatime    0    0\nnone    /lib/init/rw    tmpfs    rw,nosuid,relatime,mode=755    0    0\n/dev/sda1    /boot    ext2    rw,relatime,errors=continue    0    0\n/dev/mapper/usr    /usr/local/    ext4    rw,relatime,barrier=1,data=writeback    0    0\nbinfmt_misc    /proc/sys/fs/binfmt_misc    binfmt_misc    rw,nosuid,relatime    0    0\nserver.nfs:/vol/home    /home/user    nfs    rw,nosuid,relatime    0    0\n'
    mountpoints = client_utils_linux.GetMountpoints(proc_mounts)
    def GetMountpointsMock():
        return mountpoints
    old_getmountpoints = client_utils_linux.GetMountpoints
    client_utils_linux.GetMountpoints = GetMountpointsMock
    for (filename, expected_device, expected_path, device_type) in [('/etc/passwd', '/dev/mapper/root', '/etc/passwd', rdf_paths.PathSpec.PathType.OS), ('/usr/local/bin/ls', '/dev/mapper/usr', '/bin/ls', rdf_paths.PathSpec.PathType.OS), ('/proc/net/sys', 'none', '/net/sys', rdf_paths.PathSpec.PathType.UNSET), ('/home/user/test.txt', 'server.nfs:/vol/home', '/test.txt', rdf_paths.PathSpec.PathType.UNSET)]:
        (raw_pathspec, path) = client_utils_linux.LinGetRawDevice(filename)
        self.assertEqual(expected_device, raw_pathspec.path)
        self.assertEqual(device_type, raw_pathspec.pathtype)
        self.assertEqual(expected_path, path)
        client_utils_linux.GetMountpoints = old_getmountpoints
