Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount: fix remount when fstype is not set #52712

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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