Commit d2fd8b77 authored by Kirill Smelkov's avatar Kirill Smelkov

wcfs: Make sure to remove mountpoint directory on Server.stop

Else every time test.py/wcfs is run several empty directories are left
in /dev/shm/wcfs - each corresponding to WCFS server that was
automatically spawned and stopped at the end of the test. Over time this
can accumulate to some big number as e.g. ~20000 of such directories
were left on the testnode during last 6 months.
parent 5c13cc82
...@@ -417,6 +417,15 @@ def __stop(wcsrv, ctx, _onstuck): ...@@ -417,6 +417,15 @@ def __stop(wcsrv, ctx, _onstuck):
# unmount and wait for wcfs to exit # unmount and wait for wcfs to exit
# kill wcfs and abort FUSE connection if clean unmount fails # kill wcfs and abort FUSE connection if clean unmount fails
# at the end make sure mountpoint directory is removed
def _():
# when stop runs:
# - wcsrv could be already `fusermount -u`'ed from outside
# - the mountpoint could be also already removed from outside
_rmdir_ifexists(wcsrv.mountpoint)
defer(_)
def _(): def _():
if wcsrv._fuseabort is not None: if wcsrv._fuseabort is not None:
wcsrv._fuseabort.close() wcsrv._fuseabort.close()
...@@ -521,6 +530,14 @@ def _mkdir_p(path, mode=0o777): # -> created(bool) ...@@ -521,6 +530,14 @@ def _mkdir_p(path, mode=0o777): # -> created(bool)
return False return False
return True return True
# rmdir if path exists.
def _rmdir_ifexists(path):
try:
os.rmdir(path)
except OSError as e:
if e.errno != ENOENT:
raise
# _fuse_unmount calls `fusermount -u` + logs details if unmount failed. # _fuse_unmount calls `fusermount -u` + logs details if unmount failed.
@func @func
def _fuse_unmount(mntpt): def _fuse_unmount(mntpt):
...@@ -713,6 +730,7 @@ def main(): ...@@ -713,6 +730,7 @@ def main():
elif cmd == "stop": elif cmd == "stop":
mntpt = _mntpt_4zurl(zurl) mntpt = _mntpt_4zurl(zurl)
_fuse_unmount(mntpt) _fuse_unmount(mntpt)
_rmdir_ifexists(mntpt)
else: else:
print("wcfs: unknown command %s" % qq(cmd), file=sys.stderr) print("wcfs: unknown command %s" % qq(cmd), file=sys.stderr)
......
...@@ -53,7 +53,7 @@ from pytest import raises, fail ...@@ -53,7 +53,7 @@ from pytest import raises, fail
from wendelin.wcfs.internal import io, mm from wendelin.wcfs.internal import io, mm
from wendelin.wcfs.internal.wcfs_test import _tWCFS, read_exfault_nogil, SegmentationFault, install_sigbus_trap, fadvise_dontneed from wendelin.wcfs.internal.wcfs_test import _tWCFS, read_exfault_nogil, SegmentationFault, install_sigbus_trap, fadvise_dontneed
from wendelin.wcfs.client._wcfs import _tpywlinkwrite as _twlinkwrite from wendelin.wcfs.client._wcfs import _tpywlinkwrite as _twlinkwrite
from wendelin.wcfs import _is_mountpoint as is_mountpoint, _procwait as procwait, _ready as ready from wendelin.wcfs import _is_mountpoint as is_mountpoint, _procwait as procwait, _ready as ready, _rmdir_ifexists as rmdir_ifexists
# setup: # setup:
...@@ -106,8 +106,7 @@ def teardown_function(f): ...@@ -106,8 +106,7 @@ def teardown_function(f):
mounted = is_mountpoint(testmntpt) mounted = is_mountpoint(testmntpt)
if mounted: if mounted:
fuse_unmount(testmntpt) fuse_unmount(testmntpt)
if os.path.exists(testmntpt): rmdir_ifexists(testmntpt)
os.rmdir(testmntpt)
with raises(KeyError): with raises(KeyError):
procmounts_lookup_wcfs(testzurl) procmounts_lookup_wcfs(testzurl)
...@@ -384,7 +383,6 @@ class tWCFS(_tWCFS): ...@@ -384,7 +383,6 @@ class tWCFS(_tWCFS):
if is_mountpoint(t.wc.mountpoint): if is_mountpoint(t.wc.mountpoint):
fuse_unmount(t.wc.mountpoint) fuse_unmount(t.wc.mountpoint)
assert not is_mountpoint(t.wc.mountpoint) assert not is_mountpoint(t.wc.mountpoint)
os.rmdir(t.wc.mountpoint)
defer(_) defer(_)
def _(): def _():
def onstuck(): def onstuck():
......
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