Commit 87af3b6d authored by Ian Patel's avatar Ian Patel
Browse files

Fix watchdog crashing on stunnel cleanup edge case

parent 7c1e2b3a
......@@ -78,13 +78,24 @@ def bootstrap_logging(config, log_dir=LOG_DIR):
logging.error('Malformed logging level "%s", setting logging level to %s', raw_level, level)
def parse_options(options):
opts = {}
for o in options.split(','):
if '=' in o:
k, v = o.split('=')
opts[k] = v
else:
opts[o] = None
return opts
def get_file_safe_mountpoint(mount):
mountpoint = os.path.abspath(mount.mountpoint).replace(os.sep, '.')
if mountpoint.startswith('.'):
mountpoint = mountpoint[1:]
port = mount.options[mount.options.find('port'):].split(',')[0].split('=')[1]
return mountpoint + '.' + port
opts = parse_options(mount.options)
return mountpoint + '.' + opts['port']
def get_current_local_nfs_mounts(mount_file='/proc/mounts'):
......
......@@ -9,7 +9,8 @@
import watchdog
MOUNT_FMT_LINE = '{address}:/ {mountpoint} {fs_type} rw,port=12345 0 0'
MOUNT_FMT_LINE = '{address}:/ {mountpoint} {fs_type} {options} 0 0'
DEFAULT_OPTS = 'rw,port=12345'
def _create_mount_file(tmpdir, lines):
......@@ -27,7 +28,8 @@ def test_no_mounts(tmpdir):
def test_no_local_mounts(tmpdir):
mount_file = _create_mount_file(tmpdir, [MOUNT_FMT_LINE.format(address='10.1.0.1', mountpoint='/mnt', fs_type='nfs4')])
mount_file = _create_mount_file(tmpdir, [MOUNT_FMT_LINE.format(address='10.1.0.1', mountpoint='/mnt',
fs_type='nfs4', options=DEFAULT_OPTS)])
mounts = watchdog.get_current_local_nfs_mounts(mount_file)
......@@ -35,7 +37,8 @@ def test_no_local_mounts(tmpdir):
def test_no_local_nfs_mounts(tmpdir):
mount_file = _create_mount_file(tmpdir, [MOUNT_FMT_LINE.format(address='127.0.0.1', mountpoint='/mnt', fs_type='ext4')])
mount_file = _create_mount_file(tmpdir, [MOUNT_FMT_LINE.format(address='127.0.0.1', mountpoint='/mnt',
fs_type='ext4', options=DEFAULT_OPTS)])
mounts = watchdog.get_current_local_nfs_mounts(mount_file)
......@@ -43,7 +46,18 @@ def test_no_local_nfs_mounts(tmpdir):
def test_local_nfs_mount(tmpdir):
mount_file = _create_mount_file(tmpdir, [MOUNT_FMT_LINE.format(address='127.0.0.1', mountpoint='/mnt', fs_type='nfs4')])
mount_file = _create_mount_file(tmpdir, [MOUNT_FMT_LINE.format(address='127.0.0.1', mountpoint='/mnt',
fs_type='nfs4', options=DEFAULT_OPTS)])
mounts = watchdog.get_current_local_nfs_mounts(mount_file)
assert 1 == len(mounts)
assert 'mnt.12345' in mounts
def test_local_nfs_mount_noresvport(tmpdir):
mount_file = _create_mount_file(tmpdir, [MOUNT_FMT_LINE.format(address='127.0.0.1', mountpoint='/mnt',
fs_type='nfs4', options='rw,noresvport,port=12345')])
mounts = watchdog.get_current_local_nfs_mounts(mount_file)
......
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