diff --git a/salt/modules/mount.py b/salt/modules/mount.py index 97263252c758..541a2c9cc6ac 100644 --- a/salt/modules/mount.py +++ b/salt/modules/mount.py @@ -1218,6 +1218,8 @@ def mount(name, device, mkmnt=False, fstype='', opts='defaults', user=None, util # fstype in /etc/filesystems if 'AIX' in __grains__['os']: args += ' -v {0}'.format(fstype) + elif 'solaris' in __grains__['os'].lower(): + args += ' -F {0}'.format(fstype) else: args += ' -t {0}'.format(fstype) @@ -1248,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(',') @@ -1263,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) diff --git a/tests/unit/modules/test_mount.py b/tests/unit/modules/test_mount.py index 1a0d64f2f582..808cef90df46 100644 --- a/tests/unit/modules/test_mount.py +++ b/tests/unit/modules/test_mount.py @@ -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 @@ -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