The Linux "mount" command can run via subprocess.Popen but not via sarge.run

782 views
Skip to first unread message

Shawn Skriver

unread,
Mar 14, 2014, 5:42:11 PM3/14/14
to python...@googlegroups.com
I have found an odd behavior while writing a script (Python 2.6.8) that mounts an NFS share to a directory, copies off log files, then un-mounts the directory.

def mount_dir(mnt_path, share_path, mnt_type='nfs', uid=0, gid=0):
    cmd_mkdir = shell_format('/bin/mkdir -p {0}', mnt_path)
    if mnt_type == 'nfs':
        cmd_mount = shell_format("/bin/mount -o rsize=32768,wsize=32768,intr -t {0} {1} {2}", mnt_type, share_path,
                                 mnt_path)
    else:
        cmd_mount = shell_format("/bin/mount -t {0} {1} {2}", mnt_type, share_path, mnt_path)
    run(cmd_mkdir)
    # Apparently sarge's run does not execute mount properly! TODO
    # run(cmd_mount)  # Fail
    # run(cmd_mount, shell=True)  # Fail
    p = subprocess.Popen(cmd_mount, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    p.communicate()  # Succeed
    os.chown(mnt_path, uid, gid)

Curiously, I found that I can execute the sarge.run(cmd_mount, shell=True) successfully using iPython (version 1.1.0) in a terminal.

Note that I can un-mount the directory within the script using sarge:

def umount_dir(mnt_path):
    cmd_umount = shell_format('/bin/umount {0}', mnt_path)
    cmd_rmdir = shell_format('/bin/rmdir --ignore-fail-on-non-empty {0}', mnt_path)
    run(cmd_umount)
    run(cmd_rmdir)


Is there a way to use sarge successfully for a mount operation within a script?

Thank You,

Shawn

Vinay Sajip

unread,
Mar 14, 2014, 7:39:50 PM3/14/14
to python...@googlegroups.com


On Friday, March 14, 2014 9:42:11 PM UTC, Shawn Skriver wrote:
I have found an odd behavior while writing a script (Python 2.6.8) that mounts an NFS share to a directory, copies off log files, then un-mounts the directory.
[...] 
Is there a way to use sarge successfully for a mount operation within a script?
 
I will investigate and post a response.

Regards,

Vinay Sajip
Reply all
Reply to author
Forward
0 new messages