2015-05-22 10:38:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
2015-05-22 10:38:15 +00:00
|
|
|
'''
|
|
|
|
# Import Python libs
|
2018-01-26 13:09:58 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2017-03-22 16:42:17 +00:00
|
|
|
import os
|
2015-05-22 10:38:15 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-03-22 16:42:17 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import (
|
2015-05-22 10:38:15 +00:00
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON,
|
|
|
|
MagicMock,
|
|
|
|
patch)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.states.mount as mount
|
2015-05-22 10:38:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-03-22 16:42:17 +00:00
|
|
|
class MountTestCase(TestCase, LoaderModuleMockMixin):
|
2015-05-22 10:38:15 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.states.mount
|
|
|
|
'''
|
2017-03-22 16:42:17 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {mount: {}}
|
|
|
|
|
2015-05-22 10:38:15 +00:00
|
|
|
# 'mounted' function tests: 1
|
|
|
|
|
|
|
|
def test_mounted(self):
|
|
|
|
'''
|
|
|
|
Test to verify that a device is mounted.
|
|
|
|
'''
|
2017-09-29 20:03:42 +00:00
|
|
|
name = os.path.realpath('/mnt/sdb')
|
|
|
|
device = os.path.realpath('/dev/sdb5')
|
2015-05-22 10:38:15 +00:00
|
|
|
fstype = 'xfs'
|
|
|
|
|
2017-09-29 20:03:42 +00:00
|
|
|
name2 = os.path.realpath('/mnt/cifs')
|
2015-12-08 09:08:12 +00:00
|
|
|
device2 = '//SERVER/SHARE/'
|
|
|
|
fstype2 = 'cifs'
|
|
|
|
opts2 = ['noowners']
|
|
|
|
superopts2 = ['uid=510', 'gid=100', 'username=cifsuser',
|
|
|
|
'domain=cifsdomain']
|
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
name3 = os.path.realpath('/mnt/jfs2')
|
|
|
|
device3 = '/dev/hd1'
|
|
|
|
fstype3 = 'jfs2'
|
|
|
|
opts3 = ['']
|
|
|
|
superopts3 = ['uid=510', 'gid=100', 'username=jfs2user',
|
|
|
|
'domain=jfs2sdomain']
|
|
|
|
|
2015-05-22 10:38:15 +00:00
|
|
|
ret = {'name': name,
|
|
|
|
'result': False,
|
|
|
|
'comment': '',
|
|
|
|
'changes': {}}
|
|
|
|
|
|
|
|
mock = MagicMock(side_effect=['new', 'present', 'new', 'change',
|
2015-12-08 09:08:12 +00:00
|
|
|
'bad config', 'salt', 'present'])
|
2015-05-22 10:38:15 +00:00
|
|
|
mock_t = MagicMock(return_value=True)
|
|
|
|
mock_f = MagicMock(return_value=False)
|
|
|
|
mock_ret = MagicMock(return_value={'retcode': 1})
|
|
|
|
mock_mnt = MagicMock(return_value={name: {'device': device, 'opts': [],
|
2015-12-08 09:08:12 +00:00
|
|
|
'superopts': []},
|
|
|
|
name2: {'device': device2, 'opts': opts2,
|
2018-07-27 16:40:17 +00:00
|
|
|
'superopts': superopts2},
|
|
|
|
name3: {'device': device3, 'opts': opts3,
|
|
|
|
'superopts': superopts3}})
|
|
|
|
mock_aixfs_retn = MagicMock(return_value='present')
|
|
|
|
|
2015-05-22 10:38:15 +00:00
|
|
|
mock_emt = MagicMock(return_value={})
|
|
|
|
mock_str = MagicMock(return_value='salt')
|
2015-12-08 09:08:12 +00:00
|
|
|
mock_user = MagicMock(return_value={'uid': 510})
|
|
|
|
mock_group = MagicMock(return_value={'gid': 100})
|
2017-08-28 03:50:48 +00:00
|
|
|
mock_read_cache = MagicMock(return_value={})
|
|
|
|
mock_write_cache = MagicMock(return_value=True)
|
2015-05-22 10:38:15 +00:00
|
|
|
with patch.dict(mount.__grains__, {'os': 'Darwin'}):
|
|
|
|
with patch.dict(mount.__salt__, {'mount.active': mock_mnt,
|
|
|
|
'cmd.run_all': mock_ret,
|
2017-09-29 20:03:42 +00:00
|
|
|
'mount.umount': mock_f}), \
|
|
|
|
patch('os.path.exists', MagicMock(return_value=True)):
|
2015-05-22 10:38:15 +00:00
|
|
|
comt = ('Unable to find device with label /dev/sdb5.')
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(mount.mounted(name, 'LABEL=/dev/sdb5',
|
|
|
|
fstype), ret)
|
|
|
|
|
|
|
|
with patch.dict(mount.__opts__, {'test': True}):
|
|
|
|
comt = ('Remount would be forced because'
|
|
|
|
' options (noowners) changed')
|
|
|
|
ret.update({'comment': comt, 'result': None})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device, fstype),
|
|
|
|
ret)
|
|
|
|
|
|
|
|
with patch.dict(mount.__opts__, {'test': False}):
|
2017-09-29 20:03:42 +00:00
|
|
|
comt = ('Unable to unmount {0}: False.'.format(name))
|
2015-05-22 10:38:15 +00:00
|
|
|
umount = ('Forced unmount and mount because'
|
|
|
|
' options (noowners) changed')
|
|
|
|
ret.update({'comment': comt, 'result': False,
|
|
|
|
'changes': {'umount': umount}})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device, 'nfs'),
|
|
|
|
ret)
|
|
|
|
|
2017-09-29 20:03:42 +00:00
|
|
|
umount1 = ("Forced unmount because devices don't match. "
|
2018-07-27 17:35:40 +00:00
|
|
|
"Wanted: {0}, current: {1}, {1}"
|
|
|
|
.format(os.path.realpath('/dev/sdb6'), device))
|
2015-05-22 10:38:15 +00:00
|
|
|
comt = ('Unable to unmount')
|
|
|
|
ret.update({'comment': comt, 'result': None,
|
|
|
|
'changes': {'umount': umount1}})
|
2017-09-29 20:03:42 +00:00
|
|
|
self.assertDictEqual(mount.mounted(name, os.path.realpath('/dev/sdb6'),
|
2015-05-22 10:38:15 +00:00
|
|
|
fstype, opts=[]), ret)
|
|
|
|
|
|
|
|
with patch.dict(mount.__salt__, {'mount.active': mock_emt,
|
|
|
|
'mount.mount': mock_str,
|
|
|
|
'mount.set_automaster': mock}):
|
2017-09-29 20:03:42 +00:00
|
|
|
with patch.dict(mount.__opts__, {'test': True}), \
|
|
|
|
patch('os.path.exists', MagicMock(return_value=False)):
|
2016-02-19 12:11:59 +00:00
|
|
|
comt = ('{0} does not exist and would not be created'.format(name))
|
2015-05-22 10:38:15 +00:00
|
|
|
ret.update({'comment': comt, 'changes': {}})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device,
|
|
|
|
fstype), ret)
|
|
|
|
|
|
|
|
with patch.dict(mount.__opts__, {'test': False}):
|
|
|
|
with patch.object(os.path, 'exists', mock_f):
|
|
|
|
comt = ('Mount directory is not present')
|
|
|
|
ret.update({'comment': comt, 'result': False})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device,
|
|
|
|
fstype), ret)
|
|
|
|
|
|
|
|
with patch.object(os.path, 'exists', mock_t):
|
|
|
|
comt = ('Mount directory is not present')
|
|
|
|
ret.update({'comment': 'salt', 'result': False})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device,
|
|
|
|
fstype), ret)
|
|
|
|
|
2017-09-29 20:03:42 +00:00
|
|
|
with patch.dict(mount.__opts__, {'test': True}), \
|
|
|
|
patch('os.path.exists', MagicMock(return_value=False)):
|
2016-02-19 12:11:59 +00:00
|
|
|
comt = ('{0} does not exist and would neither be created nor mounted. '
|
2018-07-27 17:35:40 +00:00
|
|
|
'{0} needs to be written to the fstab in order to be made persistent.'
|
|
|
|
.format(name))
|
2015-05-22 10:38:15 +00:00
|
|
|
ret.update({'comment': comt, 'result': None})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device, fstype,
|
|
|
|
mount=False), ret)
|
|
|
|
|
2017-09-29 20:03:42 +00:00
|
|
|
with patch.dict(mount.__opts__, {'test': False}), \
|
|
|
|
patch('os.path.exists', MagicMock(return_value=False)):
|
2016-02-19 12:11:59 +00:00
|
|
|
comt = ('{0} not present and not mounted. '
|
|
|
|
'Entry already exists in the fstab.'.format(name))
|
2015-05-22 10:38:15 +00:00
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device, fstype,
|
|
|
|
mount=False), ret)
|
|
|
|
|
2016-02-19 12:11:59 +00:00
|
|
|
comt = ('{0} not present and not mounted. '
|
|
|
|
'Added new entry to the fstab.'.format(name))
|
2015-05-22 10:38:15 +00:00
|
|
|
ret.update({'comment': comt, 'result': True,
|
|
|
|
'changes': {'persist': 'new'}})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device, fstype,
|
|
|
|
mount=False), ret)
|
|
|
|
|
2016-02-19 12:11:59 +00:00
|
|
|
comt = ('{0} not present and not mounted. '
|
|
|
|
'Updated the entry in the fstab.'.format(name))
|
2015-05-22 10:38:15 +00:00
|
|
|
ret.update({'comment': comt, 'result': True,
|
|
|
|
'changes': {'persist': 'update'}})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device, fstype,
|
|
|
|
mount=False), ret)
|
|
|
|
|
2016-02-19 12:11:59 +00:00
|
|
|
comt = ('{0} not present and not mounted. '
|
|
|
|
'However, the fstab was not found.'.format(name))
|
2015-05-22 10:38:15 +00:00
|
|
|
ret.update({'comment': comt, 'result': False,
|
|
|
|
'changes': {}})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device, fstype,
|
|
|
|
mount=False), ret)
|
|
|
|
|
2016-02-19 12:11:59 +00:00
|
|
|
comt = ('{0} not present and not mounted'.format(name))
|
2015-05-22 10:38:15 +00:00
|
|
|
ret.update({'comment': comt, 'result': True,
|
|
|
|
'changes': {}})
|
|
|
|
self.assertDictEqual(mount.mounted(name, device, fstype,
|
|
|
|
mount=False), ret)
|
|
|
|
|
2015-12-08 09:08:12 +00:00
|
|
|
# Test no change for uid provided as a name #25293
|
|
|
|
with patch.dict(mount.__grains__, {'os': 'CentOS'}):
|
|
|
|
with patch.dict(mount.__salt__, {'mount.active': mock_mnt,
|
|
|
|
'mount.mount': mock_str,
|
|
|
|
'mount.umount': mock_f,
|
2017-08-28 03:50:48 +00:00
|
|
|
'mount.read_mount_cache': mock_read_cache,
|
|
|
|
'mount.write_mount_cache': mock_write_cache,
|
2015-12-08 09:08:12 +00:00
|
|
|
'mount.set_fstab': mock,
|
|
|
|
'user.info': mock_user,
|
|
|
|
'group.info': mock_group}):
|
|
|
|
with patch.dict(mount.__opts__, {'test': True}):
|
|
|
|
with patch.object(os.path, 'exists', mock_t):
|
2018-01-26 13:12:11 +00:00
|
|
|
comt = 'Target was already mounted. Entry already exists in the fstab.'
|
2015-12-08 09:08:12 +00:00
|
|
|
ret.update({'name': name2, 'result': True})
|
|
|
|
ret.update({'comment': comt, 'changes': {}})
|
|
|
|
self.assertDictEqual(mount.mounted(name2, device2,
|
|
|
|
fstype2,
|
|
|
|
opts=['uid=user1',
|
|
|
|
'gid=group1']),
|
|
|
|
ret)
|
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
with patch.dict(mount.__grains__, {'os': 'AIX'}):
|
|
|
|
with patch.dict(mount.__salt__, {'mount.active': mock_mnt,
|
|
|
|
'mount.mount': mock_str,
|
|
|
|
'mount.umount': mock_f,
|
|
|
|
'mount.read_mount_cache': mock_read_cache,
|
|
|
|
'mount.write_mount_cache': mock_write_cache,
|
|
|
|
'mount.set_filesystems': mock_aixfs_retn,
|
|
|
|
'user.info': mock_user,
|
|
|
|
'group.info': mock_group}):
|
|
|
|
with patch.dict(mount.__opts__, {'test': True}):
|
|
|
|
with patch.object(os.path, 'exists', mock_t):
|
|
|
|
comt = 'Target was already mounted. Entry already exists in the fstab.'
|
|
|
|
ret.update({'name': name3, 'result': True})
|
|
|
|
ret.update({'comment': comt, 'changes': {}})
|
|
|
|
self.assertDictEqual(mount.mounted(name3, device3,
|
|
|
|
fstype3,
|
|
|
|
opts=['uid=user1',
|
|
|
|
'gid=group1']),
|
|
|
|
ret)
|
|
|
|
|
2015-05-22 10:38:15 +00:00
|
|
|
# 'swap' function tests: 1
|
|
|
|
|
|
|
|
def test_swap(self):
|
|
|
|
'''
|
|
|
|
Test to activates a swap device.
|
|
|
|
'''
|
|
|
|
name = '/mnt/sdb'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': None,
|
|
|
|
'comment': '',
|
|
|
|
'changes': {}}
|
|
|
|
|
|
|
|
mock = MagicMock(side_effect=['present', 'new', 'change', 'bad config'])
|
|
|
|
mock_f = MagicMock(return_value=False)
|
|
|
|
mock_swp = MagicMock(return_value=[name])
|
|
|
|
mock_fs = MagicMock(return_value={'none': {'device': name,
|
|
|
|
'fstype': 'xfs'}})
|
2018-07-27 16:40:17 +00:00
|
|
|
mock_aixfs = MagicMock(return_value={name: {'dev': name,
|
|
|
|
'fstype': 'jfs2'}})
|
2015-05-22 10:38:15 +00:00
|
|
|
mock_emt = MagicMock(return_value={})
|
2018-07-27 16:40:17 +00:00
|
|
|
with patch.dict(mount.__grains__, {'os': 'test'}):
|
|
|
|
with patch.dict(mount.__salt__, {'mount.swaps': mock_swp,
|
|
|
|
'mount.fstab': mock_fs,
|
|
|
|
'file.is_link': mock_f}):
|
|
|
|
with patch.dict(mount.__opts__, {'test': True}):
|
|
|
|
comt = ('Swap {0} is set to be added to the '
|
|
|
|
'fstab and to be activated'.format(name))
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
2015-05-22 10:38:15 +00:00
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
with patch.dict(mount.__opts__, {'test': False}):
|
2015-05-22 10:38:15 +00:00
|
|
|
comt = ('Swap {0} already active'.format(name))
|
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
with patch.dict(mount.__salt__, {'mount.fstab': mock_emt,
|
|
|
|
'mount.set_fstab': mock}):
|
|
|
|
comt = ('Swap {0} already active'.format(name))
|
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
|
|
|
|
|
|
|
comt = ('Swap /mnt/sdb already active. '
|
|
|
|
'Added new entry to the fstab.')
|
|
|
|
ret.update({'comment': comt, 'result': True,
|
|
|
|
'changes': {'persist': 'new'}})
|
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
|
|
|
|
|
|
|
comt = ('Swap /mnt/sdb already active. '
|
|
|
|
'Updated the entry in the fstab.')
|
|
|
|
ret.update({'comment': comt, 'result': True,
|
|
|
|
'changes': {'persist': 'update'}})
|
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
|
|
|
|
|
|
|
comt = ('Swap /mnt/sdb already active. '
|
|
|
|
'However, the fstab was not found.')
|
|
|
|
ret.update({'comment': comt, 'result': False,
|
|
|
|
'changes': {}})
|
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
2015-05-22 10:38:15 +00:00
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
with patch.dict(mount.__grains__, {'os': 'AIX'}):
|
|
|
|
with patch.dict(mount.__salt__, {'mount.swaps': mock_swp,
|
|
|
|
'mount.filesystems': mock_aixfs,
|
|
|
|
'file.is_link': mock_f}):
|
|
|
|
with patch.dict(mount.__opts__, {'test': True}):
|
|
|
|
comt = ('Swap {0} already active'.format(name))
|
|
|
|
ret.update({'comment': comt, 'result': True})
|
2015-05-22 10:38:15 +00:00
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
with patch.dict(mount.__opts__, {'test': False}):
|
2018-07-27 17:35:40 +00:00
|
|
|
comt = ('Swap {0} already active. swap not present'
|
|
|
|
' in /etc/filesystems on AIX.'.format(name))
|
2018-07-27 16:40:17 +00:00
|
|
|
ret.update({'comment': comt, 'result': False})
|
2015-05-22 10:38:15 +00:00
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
with patch.dict(mount.__salt__, {'mount.filesystems': mock_emt,
|
|
|
|
'mount.set_filesystems': mock}):
|
2018-07-27 17:35:40 +00:00
|
|
|
comt = ('Swap {0} already active. swap not present'
|
|
|
|
' in /etc/filesystems on AIX.'.format(name))
|
2018-07-27 16:40:17 +00:00
|
|
|
ret.update({'comment': comt, 'result': False})
|
|
|
|
self.assertDictEqual(mount.swap(name), ret)
|
|
|
|
|
2015-05-22 10:38:15 +00:00
|
|
|
# 'unmounted' function tests: 1
|
|
|
|
|
|
|
|
def test_unmounted(self):
|
|
|
|
'''
|
|
|
|
Test to verify that a device is not mounted
|
|
|
|
'''
|
|
|
|
name = '/mnt/sdb'
|
|
|
|
device = '/dev/sdb5'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': None,
|
|
|
|
'comment': '',
|
|
|
|
'changes': {}}
|
|
|
|
|
|
|
|
mock_f = MagicMock(return_value=False)
|
2018-07-27 16:40:17 +00:00
|
|
|
mock_t = MagicMock(return_value=True)
|
2015-05-22 10:38:15 +00:00
|
|
|
mock_dev = MagicMock(return_value={name: {'device': device}})
|
|
|
|
mock_fs = MagicMock(return_value={name: {'device': name}})
|
|
|
|
mock_mnt = MagicMock(side_effect=[{name: {}}, {}, {}, {}])
|
2018-07-27 17:35:40 +00:00
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
name3 = os.path.realpath('/mnt/jfs2')
|
|
|
|
device3 = '/dev/hd1'
|
|
|
|
fstype3 = 'jfs2'
|
|
|
|
opts3 = ['']
|
|
|
|
mock_mnta = MagicMock(return_value={name3: {'device': device3, 'opts': opts3}})
|
|
|
|
mock_aixfs = MagicMock(return_value={name: {'dev': name3, 'fstype': fstype3}})
|
2018-07-27 17:35:40 +00:00
|
|
|
mock_delete_cache = MagicMock(return_value=True)
|
2018-07-27 16:40:17 +00:00
|
|
|
|
2015-05-22 10:38:15 +00:00
|
|
|
comt3 = ('Mount point /mnt/sdb is unmounted but needs to be purged '
|
|
|
|
'from /etc/auto_salt to be made persistent')
|
2018-07-27 16:40:17 +00:00
|
|
|
|
2015-05-22 10:38:15 +00:00
|
|
|
with patch.dict(mount.__grains__, {'os': 'Darwin'}):
|
|
|
|
with patch.dict(mount.__salt__, {'mount.active': mock_mnt,
|
|
|
|
'mount.automaster': mock_fs,
|
|
|
|
'file.is_link': mock_f}):
|
|
|
|
with patch.dict(mount.__opts__, {'test': True}):
|
|
|
|
comt = ('Mount point {0} is mounted but should not '
|
|
|
|
'be'.format(name))
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(mount.unmounted(name, device), ret)
|
|
|
|
|
|
|
|
comt = ('Target was already unmounted. '
|
2018-07-27 16:40:17 +00:00
|
|
|
'fstab entry for device {0} not found'.format(device))
|
2015-05-22 10:38:15 +00:00
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(mount.unmounted(name, device,
|
|
|
|
persist=True), ret)
|
|
|
|
|
|
|
|
with patch.dict(mount.__salt__,
|
|
|
|
{'mount.automaster': mock_dev}):
|
|
|
|
ret.update({'comment': comt3, 'result': None})
|
|
|
|
self.assertDictEqual(mount.unmounted(name, device,
|
|
|
|
persist=True), ret)
|
|
|
|
|
|
|
|
comt = ('Target was already unmounted')
|
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(mount.unmounted(name, device), ret)
|
|
|
|
|
2018-07-27 16:40:17 +00:00
|
|
|
with patch.dict(mount.__grains__, {'os': 'AIX'}):
|
|
|
|
with patch.dict(mount.__salt__, {'mount.active': mock_mnta,
|
|
|
|
'mount.filesystems': mock_aixfs,
|
|
|
|
'file.is_link': mock_f}):
|
|
|
|
with patch.dict(mount.__opts__, {'test': True}):
|
|
|
|
comt = ('Target was already unmounted')
|
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(mount.unmounted(name, device), ret)
|
|
|
|
|
|
|
|
comt = ('Target was already unmounted. '
|
|
|
|
'fstab entry for device /dev/sdb5 not found')
|
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(mount.unmounted(name, device,
|
|
|
|
persist=True), ret)
|
|
|
|
|
|
|
|
with patch.dict(mount.__salt__,
|
|
|
|
{'mount.filesystems': mock_dev}):
|
|
|
|
comt = ('Mount point {0} is mounted but should not '
|
|
|
|
'be'.format(name3))
|
2018-07-27 17:35:40 +00:00
|
|
|
ret.update({'comment': comt, 'result': None, 'name': name3})
|
2018-07-27 16:40:17 +00:00
|
|
|
self.assertDictEqual(mount.unmounted(name3, device3,
|
|
|
|
persist=True), ret)
|
2018-07-27 17:35:40 +00:00
|
|
|
|
|
|
|
with patch.dict(mount.__opts__, {'test': False}), \
|
|
|
|
patch.dict(mount.__salt__, {'mount.umount': mock_t,
|
|
|
|
'mount.delete_mount_cache': mock_delete_cache}):
|
|
|
|
comt = ('Target was successfully unmounted')
|
|
|
|
ret.update({'comment': comt, 'result': True,
|
|
|
|
'name': name3, 'changes': {'umount': True}})
|
2018-07-27 16:40:17 +00:00
|
|
|
self.assertDictEqual(mount.unmounted(name3, device3), ret)
|
|
|
|
|
2015-05-22 10:38:15 +00:00
|
|
|
# 'mod_watch' function tests: 1
|
|
|
|
|
|
|
|
def test_mod_watch(self):
|
|
|
|
'''
|
|
|
|
Test the mounted watcher, called to invoke the watch command.
|
|
|
|
'''
|
|
|
|
name = '/mnt/sdb'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': True,
|
2018-01-26 13:11:50 +00:00
|
|
|
'comment': 'Watch not supported in unmount at this time',
|
2015-05-22 10:38:15 +00:00
|
|
|
'changes': {}}
|
|
|
|
|
|
|
|
self.assertDictEqual(mount.mod_watch(name, sfun='unmount'), ret)
|