fix a bunch of small bugs in mount module - test with bind and local mounts
This commit is contained in:
parent
fcfd73de71
commit
634c11748e
1 changed files with 17 additions and 15 deletions
|
@ -56,7 +56,7 @@ def write_fstab(lines, dest):
|
||||||
fs_w.flush()
|
fs_w.flush()
|
||||||
fs_w.close()
|
fs_w.close()
|
||||||
|
|
||||||
def set_mount(kwargs):
|
def set_mount(**kwargs):
|
||||||
"set/change a mount point location in fstab"
|
"set/change a mount point location in fstab"
|
||||||
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
|
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
|
||||||
args = { 'opts':'defaults',
|
args = { 'opts':'defaults',
|
||||||
|
@ -65,7 +65,7 @@ def set_mount(kwargs):
|
||||||
'fstab':'/etc/fstab' }
|
'fstab':'/etc/fstab' }
|
||||||
args.update(kwargs)
|
args.update(kwargs)
|
||||||
|
|
||||||
new_line = '%{src}s %{name}s %{fstype}s %{opts}s %{dump}s %{passno}s\n'
|
new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n'
|
||||||
|
|
||||||
to_write = []
|
to_write = []
|
||||||
exists = False
|
exists = False
|
||||||
|
@ -95,7 +95,7 @@ def set_mount(kwargs):
|
||||||
for t in ('src', 'fstype','opts', 'dump', 'passno'):
|
for t in ('src', 'fstype','opts', 'dump', 'passno'):
|
||||||
if ld[t] != args[t]:
|
if ld[t] != args[t]:
|
||||||
changed = True
|
changed = True
|
||||||
ld[t] == args[t]
|
ld[t] = args[t]
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
to_write.append(new_line % ld)
|
to_write.append(new_line % ld)
|
||||||
|
@ -113,8 +113,8 @@ def set_mount(kwargs):
|
||||||
return (args['name'], changed)
|
return (args['name'], changed)
|
||||||
|
|
||||||
|
|
||||||
def unset_mount(kwargs):
|
def unset_mount(**kwargs):
|
||||||
"remount a mount point in fstab"
|
"remove a mount point from fstab"
|
||||||
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
|
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
|
||||||
args = { 'opts':'default',
|
args = { 'opts':'default',
|
||||||
'dump':'0',
|
'dump':'0',
|
||||||
|
@ -153,7 +153,7 @@ def unset_mount(kwargs):
|
||||||
return (args['name'], changed)
|
return (args['name'], changed)
|
||||||
|
|
||||||
|
|
||||||
def mount(kwargs):
|
def mount(**kwargs):
|
||||||
"mount up a path or remount if needed"
|
"mount up a path or remount if needed"
|
||||||
name = kwargs['name']
|
name = kwargs['name']
|
||||||
if os.path.ismount(name):
|
if os.path.ismount(name):
|
||||||
|
@ -163,18 +163,18 @@ def mount(kwargs):
|
||||||
|
|
||||||
call = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
call = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
out, err = call.communicate()
|
out, err = call.communicate()
|
||||||
if call.rc == 0:
|
if call.returncode == 0:
|
||||||
return 0, ''
|
return 0, ''
|
||||||
else:
|
else:
|
||||||
return call.rc, out+err
|
return call.rc, out+err
|
||||||
|
|
||||||
def umount(kwargs):
|
def umount(**kwargs):
|
||||||
"unmount a path"
|
"unmount a path"
|
||||||
cmd = ['/bin/umount', name]
|
cmd = ['/bin/umount', name]
|
||||||
|
|
||||||
call = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
call = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
out, err = call.communicate()
|
out, err = call.communicate()
|
||||||
if call.rc == 0:
|
if call.returncode == 0:
|
||||||
return 0, ''
|
return 0, ''
|
||||||
else:
|
else:
|
||||||
return call.rc, out+err
|
return call.rc, out+err
|
||||||
|
@ -191,7 +191,7 @@ if not len(items):
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
for x in items:
|
for x in items:
|
||||||
(k, v) = x.split("=")
|
(k, v) = x.split("=",1)
|
||||||
params[k] = v
|
params[k] = v
|
||||||
|
|
||||||
state = params.get('state',None)
|
state = params.get('state',None)
|
||||||
|
@ -201,7 +201,7 @@ passno = params.get('passno', None)
|
||||||
dump = params.get('dump', None)
|
dump = params.get('dump', None)
|
||||||
src = params.get('src', None)
|
src = params.get('src', None)
|
||||||
fstype = params.get('fstype', None)
|
fstype = params.get('fstype', None)
|
||||||
|
fstab = params.get('fstab', None)
|
||||||
|
|
||||||
|
|
||||||
if state not in [ 'present', 'absent', 'mounted', 'unmounted' ]:
|
if state not in [ 'present', 'absent', 'mounted', 'unmounted' ]:
|
||||||
|
@ -228,6 +228,8 @@ if opts is not None:
|
||||||
args['opts'] = opts
|
args['opts'] = opts
|
||||||
if dump is not None:
|
if dump is not None:
|
||||||
args['dump'] = dump
|
args['dump'] = dump
|
||||||
|
if fstab is not None:
|
||||||
|
args['fstab'] = fstab
|
||||||
|
|
||||||
|
|
||||||
# absent == remove from fstab and unmounted
|
# absent == remove from fstab and unmounted
|
||||||
|
@ -240,7 +242,7 @@ if state == 'absent':
|
||||||
name, changed = unset_mount(**args)
|
name, changed = unset_mount(**args)
|
||||||
if changed:
|
if changed:
|
||||||
if os.path.ismount(name):
|
if os.path.ismount(name):
|
||||||
res,msg = umount(name)
|
res,msg = umount(**args)
|
||||||
if res:
|
if res:
|
||||||
fail_json(msg="Error unmounting %s: %s" % (name, msg))
|
fail_json(msg="Error unmounting %s: %s" % (name, msg))
|
||||||
|
|
||||||
|
@ -255,7 +257,7 @@ if state == 'absent':
|
||||||
|
|
||||||
if state == 'unmounted':
|
if state == 'unmounted':
|
||||||
if os.path.ismount(name):
|
if os.path.ismount(name):
|
||||||
res,msg = umount(name)
|
res,msg = umount(**args)
|
||||||
if res:
|
if res:
|
||||||
fail_json(msg="Error unmounting %s: %s" % (name, msg))
|
fail_json(msg="Error unmounting %s: %s" % (name, msg))
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -276,10 +278,10 @@ if state in ['mounted', 'present']:
|
||||||
res = 0
|
res = 0
|
||||||
if os.path.ismount(name):
|
if os.path.ismount(name):
|
||||||
if changed:
|
if changed:
|
||||||
res,msg = mount(name)
|
res,msg = mount(**args)
|
||||||
else:
|
else:
|
||||||
changed = True
|
changed = True
|
||||||
res,msg = mount(name)
|
res,msg = mount(**args)
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
fail_json(msg="Error mounting %s: %s" % (name, msg))
|
fail_json(msg="Error mounting %s: %s" % (name, msg))
|
||||||
|
|
Loading…
Reference in a new issue