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)
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)