Skip to content

Commit

Permalink
mount: fix remount when fstype is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
aplanas committed Apr 29, 2019
1 parent f3df53f commit e0596ab
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 11 deletions.
22 changes: 12 additions & 10 deletions salt/modules/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,10 +1219,10 @@ def mount(name, device, mkmnt=False, fstype='', opts='defaults', user=None, util
if 'AIX' in __grains__['os']:
args += ' -v {0}'.format(fstype)
elif 'solaris' in __grains__['os'].lower():
if fstype:
args += ' -F {0}'.format(fstype)
args += ' -F {0}'.format(fstype)
else:
args += ' -t {0}'.format(fstype)

cmd = 'mount {0} {1} {2} '.format(args, device, name)
out = __salt__['cmd.run_all'](cmd, runas=user, python_shell=False)
if out['retcode']:
Expand Down Expand Up @@ -1250,7 +1250,7 @@ def remount(name, device, mkmnt=False, fstype='', opts='defaults', user=None):

if 'AIX' in __grains__['os']:
if opts == 'defaults':
opts = ''
opts = []

if isinstance(opts, six.string_types):
opts = opts.split(',')
Expand All @@ -1265,14 +1265,16 @@ def remount(name, device, mkmnt=False, fstype='', opts='defaults', user=None):
lopts = ','.join(opts)
args = '-o {0}'.format(lopts)

# use of fstype on AIX differs from typical Linux use of -t functionality
# AIX uses -v vfsname, -t fstype mounts all with fstype in /etc/filesystems
if 'AIX' in __grains__['os']:
if fstype:
if fstype:
# use of fstype on AIX differs from typical Linux use of
# -t functionality AIX uses -v vfsname, -t fstype mounts
# all with fstype in /etc/filesystems
if 'AIX' in __grains__['os']:
args += ' -v {0}'.format(fstype)
args += ' -o remount'
else:
args += ' -t {0}'.format(fstype)
elif 'solaris' in __grains__['os'].lower():
args += ' -F {0}'.format(fstype)
else:
args += ' -t {0}'.format(fstype)

if __grains__['os'] not in ['OpenBSD', 'MacOS', 'Darwin'] or force_mount:
cmd = 'mount {0} {1} {2} '.format(args, device, name)
Expand Down
73 changes: 72 additions & 1 deletion tests/unit/modules/test_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_mount(self):
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device'))

def test_remount(self):
def test_remount_non_mounted(self):
'''
Attempt to remount a device, if the device is not already mounted, mount
is called
Expand All @@ -381,6 +381,77 @@ def test_remount(self):
with patch.object(mount, 'mount', mock):
self.assertTrue(mount.remount('name', 'device'))

with patch.dict(mount.__grains__, {'os': 'Linux'}):
mock = MagicMock(return_value=[])
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value=True)
with patch.object(mount, 'mount', mock):
self.assertTrue(mount.remount('name', 'device'))

def test_remount_already_mounted_no_fstype(self):
'''
Attempt to remount a device already mounted that do not provides
fstype
'''
with patch.dict(mount.__grains__, {'os': 'MacOS'}):
mock = MagicMock(return_value=['name'])
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.remount('name', 'device'))
mock.assert_called_with('mount -u -o noowners device name ',
python_shell=False, runas=None)

with patch.dict(mount.__grains__, {'os': 'AIX'}):
mock = MagicMock(return_value=['name'])
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.remount('name', 'device'))
mock.assert_called_with('mount -o remount device name ',
python_shell=False, runas=None)

with patch.dict(mount.__grains__, {'os': 'Linux'}):
mock = MagicMock(return_value=['name'])
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.remount('name', 'device'))
mock.assert_called_with('mount -o defaults,remount device name ',
python_shell=False, runas=None)

def test_remount_already_mounted_with_fstype(self):
'''
Attempt to remount a device already mounted that do not provides
fstype
'''
with patch.dict(mount.__grains__, {'os': 'MacOS'}):
mock = MagicMock(return_value=['name'])
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.remount('name', 'device', fstype='type'))
mock.assert_called_with('mount -u -o noowners -t type device name ',
python_shell=False, runas=None)

with patch.dict(mount.__grains__, {'os': 'AIX'}):
mock = MagicMock(return_value=['name'])
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.remount('name', 'device', fstype='type'))
mock.assert_called_with('mount -o remount -v type device name ',
python_shell=False, runas=None)

with patch.dict(mount.__grains__, {'os': 'Linux'}):
mock = MagicMock(return_value=['name'])
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.remount('name', 'device', fstype='type'))
mock.assert_called_with('mount -o defaults,remount -t type device name ',
python_shell=False, runas=None)

def test_umount(self):
'''
Attempt to unmount a device by specifying the directory it is
Expand Down

0 comments on commit e0596ab

Please sign in to comment.