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 extra -t parameter #51905

Merged
merged 1 commit into from
Mar 5, 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
14 changes: 8 additions & 6 deletions salt/modules/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,13 +1208,15 @@ def mount(name, device, mkmnt=False, fstype='', opts='defaults', user=None, util
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)
else:
args += ' -t {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
36 changes: 36 additions & 0 deletions tests/unit/modules/test_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ def test_mount(self):
'stderr': True})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device'))
mock.assert_called_with('mount device name ',
python_shell=False, runas=None)

with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device', fstype='fstype'))
mock.assert_called_with('mount -t fstype device name ',
python_shell=False, runas=None)

mock = MagicMock(return_value={'retcode': False,
'stderr': False})
Expand All @@ -312,6 +319,35 @@ def test_mount(self):
'stderr': True})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device'))
mock.assert_called_with('mount device name ',
python_shell=False, runas=None)

with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device', fstype='fstype'))
mock.assert_called_with('mount -v fstype device name ',
python_shell=False, runas=None)

mock = MagicMock(return_value={'retcode': False,
'stderr': False})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device'))

with patch.dict(mount.__grains__, {'os': 'Linux'}):
mock = MagicMock(return_value=True)
with patch.object(os.path, 'exists', mock):
mock = MagicMock(return_value=None)
with patch.dict(mount.__salt__, {'file.mkdir': None}):
mock = MagicMock(return_value={'retcode': True,
'stderr': True})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device'))
mock.assert_called_with('mount -o defaults device name ',
python_shell=False, runas=None)

with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device', fstype='fstype'))
mock.assert_called_with('mount -o defaults -t fstype device name ',
python_shell=False, runas=None)

mock = MagicMock(return_value={'retcode': False,
'stderr': False})
Expand Down