def test_mounted_multiple_mounts(self): """ Test to verify that a device is mounted. """ name = "/mnt/nfs1" device = "localhost:/mnt/nfsshare" fstype = "nfs4" name2 = "/mnt/nfs2" device2 = "localhost:/mnt/nfsshare" fstype2 = "nfs4" ret = {"name": name, "result": False, "comment": "", "changes": {}} mock = MagicMock( side_effect=[ "new", "present", "new", "change", "bad config", "salt", "present", ] ) 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": [], "superopts": []}} ) mock_read_cache = MagicMock(return_value={}) mock_write_cache = MagicMock(return_value=True) mock_user = MagicMock(return_value={"uid": 510}) mock_group = MagicMock(return_value={"gid": 100}) mock_str = MagicMock(return_value="salt") mock_fstab_config = ["localhost:/mnt/nfsshare /mnt/nfs1 nfs defaults 0 0"] # Test no change for uid provided as a name #25293 with patch.dict(mount.__grains__, {"os": "CentOS"}): with patch.dict(mount.__opts__, {"test": True}): 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, "user.info": mock_user, "group.info": mock_group, }, ): with patch.object(os.path, "exists", mock_t): comt = "/mnt/nfs2 would be mounted" ret.update({"name": name2, "result": None}) ret.update({"comment": comt, "changes": {}}) self.assertDictEqual( mount.mounted(name2, device2, fstype2, opts=[]), ret )
def test_mounted(self): ''' Test to verify that a device is mounted. ''' name = '/mnt/sdb' device = '/dev/sdb5' fstype = 'xfs' name2 = '/mnt/cifs' device2 = '//SERVER/SHARE/' fstype2 = 'cifs' opts2 = ['noowners'] superopts2 = ['uid=510', 'gid=100', 'username=cifsuser', 'domain=cifsdomain'] ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=['new', 'present', 'new', 'change', 'bad config', 'salt', 'present']) 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': [], 'superopts': []}, name2: {'device': device2, 'opts': opts2, 'superopts': superopts2}}) mock_emt = MagicMock(return_value={}) mock_str = MagicMock(return_value='salt') mock_user = MagicMock(return_value={'uid': 510}) mock_group = MagicMock(return_value={'gid': 100}) umount1 = ("Forced unmount because devices don't match. " "Wanted: /dev/sdb6, current: /dev/sdb5, /dev/sdb5") with patch.dict(mount.__grains__, {'os': 'Darwin'}): with patch.dict(mount.__salt__, {'mount.active': mock_mnt, 'cmd.run_all': mock_ret, 'mount.umount': mock_f}): 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}): comt = ('Unable to unmount /mnt/sdb: False.') 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) comt = ('Unable to unmount') ret.update({'comment': comt, 'result': None, 'changes': {'umount': umount1}}) self.assertDictEqual(mount.mounted(name, '/dev/sdb6', fstype, opts=[]), ret) with patch.dict(mount.__salt__, {'mount.active': mock_emt, 'mount.mount': mock_str, 'mount.set_automaster': mock}): with patch.dict(mount.__opts__, {'test': True}): comt = ('{0} does not exist and would not be created'.format(name)) 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) with patch.dict(mount.__opts__, {'test': True}): comt = ('{0} does not exist and would neither be created nor mounted. ' '{0} needs to be written to the fstab in order to be made persistent.'.format(name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) with patch.dict(mount.__opts__, {'test': False}): comt = ('{0} not present and not mounted. ' 'Entry already exists in the fstab.'.format(name)) ret.update({'comment': comt, 'result': True}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) comt = ('{0} not present and not mounted. ' 'Added new entry to the fstab.'.format(name)) ret.update({'comment': comt, 'result': True, 'changes': {'persist': 'new'}}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) comt = ('{0} not present and not mounted. ' 'Updated the entry in the fstab.'.format(name)) ret.update({'comment': comt, 'result': True, 'changes': {'persist': 'update'}}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) comt = ('{0} not present and not mounted. ' 'However, the fstab was not found.'.format(name)) ret.update({'comment': comt, 'result': False, 'changes': {}}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) comt = ('{0} not present and not mounted'.format(name)) ret.update({'comment': comt, 'result': True, 'changes': {}}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) # 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, '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): comt = 'Target was already mounted. ' + \ 'Entry already exists in the fstab.' ret.update({'name': name2, 'result': True}) ret.update({'comment': comt, 'changes': {}}) self.assertDictEqual(mount.mounted(name2, device2, fstype2, opts=['uid=user1', 'gid=group1']), ret)
def test_mounted(self): ''' Test to verify that a device is mounted. ''' name = '/mnt/sdb' device = '/dev/sdb5' fstype = 'xfs' name2 = '/mnt/cifs' device2 = '//SERVER/SHARE/' fstype2 = 'cifs' opts2 = ['noowners'] superopts2 = [ 'uid=510', 'gid=100', 'username=cifsuser', 'domain=cifsdomain' ] ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[ 'new', 'present', 'new', 'change', 'bad config', 'salt', 'present' ]) 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': [], 'superopts': [] }, name2: { 'device': device2, 'opts': opts2, 'superopts': superopts2 } }) mock_emt = MagicMock(return_value={}) mock_str = MagicMock(return_value='salt') mock_user = MagicMock(return_value={'uid': 510}) mock_group = MagicMock(return_value={'gid': 100}) umount1 = ("Forced unmount because devices don't match. " "Wanted: /dev/sdb6, current: /dev/sdb5, /dev/sdb5") with patch.dict(mount.__grains__, {'os': 'Darwin'}): with patch.dict( mount.__salt__, { 'mount.active': mock_mnt, 'cmd.run_all': mock_ret, 'mount.umount': mock_f }): 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}): comt = ('Unable to unmount /mnt/sdb: False.') 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) comt = ('Unable to unmount') ret.update({ 'comment': comt, 'result': None, 'changes': { 'umount': umount1 } }) self.assertDictEqual( mount.mounted(name, '/dev/sdb6', fstype, opts=[]), ret) with patch.dict( mount.__salt__, { 'mount.active': mock_emt, 'mount.mount': mock_str, 'mount.set_automaster': mock }): with patch.dict(mount.__opts__, {'test': True}): comt = ('{0} does not exist and would not be created'. format(name)) 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) with patch.dict(mount.__opts__, {'test': True}): comt = ( '{0} does not exist and would neither be created nor mounted. ' '{0} needs to be written to the fstab in order to be made persistent.' .format(name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) with patch.dict(mount.__opts__, {'test': False}): comt = ( '{0} not present and not mounted. ' 'Entry already exists in the fstab.'.format(name)) ret.update({'comment': comt, 'result': True}) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) comt = ('{0} not present and not mounted. ' 'Added new entry to the fstab.'.format(name)) ret.update({ 'comment': comt, 'result': True, 'changes': { 'persist': 'new' } }) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) comt = ('{0} not present and not mounted. ' 'Updated the entry in the fstab.'.format(name)) ret.update({ 'comment': comt, 'result': True, 'changes': { 'persist': 'update' } }) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) comt = ( '{0} not present and not mounted. ' 'However, the fstab was not found.'.format(name)) ret.update({ 'comment': comt, 'result': False, 'changes': {} }) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) comt = ('{0} not present and not mounted'.format(name)) ret.update({ 'comment': comt, 'result': True, 'changes': {} }) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) # 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, '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): comt = 'Target was already mounted. ' + \ 'Entry already exists in the fstab.' ret.update({'name': name2, 'result': True}) ret.update({'comment': comt, 'changes': {}}) self.assertDictEqual( mount.mounted(name2, device2, fstype2, opts=['uid=user1', 'gid=group1']), ret)
def test_mounted(self): """ Test to verify that a device is mounted. """ name = os.path.realpath("/mnt/sdb") device = os.path.realpath("/dev/sdb5") fstype = "xfs" name2 = os.path.realpath("/mnt/cifs") device2 = "//SERVER/SHARE/" fstype2 = "cifs" opts2 = ["noowners"] superopts2 = ["uid=510", "gid=100", "username=cifsuser", "domain=cifsdomain"] name3 = os.path.realpath("/mnt/jfs2") device3 = "/dev/hd1" fstype3 = "jfs2" opts3 = [""] superopts3 = ["uid=510", "gid=100", "username=jfs2user", "domain=jfs2sdomain"] ret = {"name": name, "result": False, "comment": "", "changes": {}} mock = MagicMock( side_effect=[ "new", "present", "new", "change", "bad config", "salt", "present", ] ) 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": [], "superopts": []}, name2: {"device": device2, "opts": opts2, "superopts": superopts2}, name3: {"device": device3, "opts": opts3, "superopts": superopts3}, } ) mock_aixfs_retn = MagicMock(return_value="present") mock_emt = MagicMock(return_value={}) mock_str = MagicMock(return_value="salt") mock_user = MagicMock(return_value={"uid": 510}) mock_group = MagicMock(return_value={"gid": 100}) mock_read_cache = MagicMock(return_value={}) mock_write_cache = MagicMock(return_value=True) with patch.dict(mount.__grains__, {"os": "Darwin"}): with patch.dict( mount.__salt__, { "mount.active": mock_mnt, "cmd.run_all": mock_ret, "mount.umount": mock_f, }, ), patch("os.path.exists", MagicMock(return_value=True)): 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}): comt = "Unable to unmount {0}: False.".format(name) 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) umount1 = ( "Forced unmount because devices don't match. " "Wanted: {0}, current: {1}, {1}".format( os.path.realpath("/dev/sdb6"), device ) ) comt = "Unable to unmount" ret.update( { "comment": comt, "result": None, "changes": {"umount": umount1}, } ) self.assertDictEqual( mount.mounted( name, os.path.realpath("/dev/sdb6"), fstype, opts=[] ), ret, ) with patch.dict( mount.__salt__, { "mount.active": mock_emt, "mount.mount": mock_str, "mount.set_automaster": mock, }, ): with patch.dict(mount.__opts__, {"test": True}), patch( "os.path.exists", MagicMock(return_value=False) ): comt = "{0} does not exist and would not be created".format( name ) 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 ) with patch.dict(mount.__opts__, {"test": True}), patch( "os.path.exists", MagicMock(return_value=False) ): comt = ( "{0} does not exist and would neither be created nor mounted. " "{0} needs to be written to the fstab in order to be made persistent.".format( name ) ) ret.update({"comment": comt, "result": None}) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret ) with patch.dict(mount.__opts__, {"test": False}), patch( "os.path.exists", MagicMock(return_value=False) ): comt = ( "{0} not present and not mounted. " "Entry already exists in the fstab.".format(name) ) ret.update({"comment": comt, "result": True}) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret ) comt = ( "{0} not present and not mounted. " "Added new entry to the fstab.".format(name) ) ret.update( { "comment": comt, "result": True, "changes": {"persist": "new"}, } ) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret ) comt = ( "{0} not present and not mounted. " "Updated the entry in the fstab.".format(name) ) ret.update( { "comment": comt, "result": True, "changes": {"persist": "update"}, } ) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret ) comt = ( "{0} not present and not mounted. " "However, the fstab was not found.".format(name) ) ret.update({"comment": comt, "result": False, "changes": {}}) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret ) comt = "{0} not present and not mounted".format(name) ret.update({"comment": comt, "result": True, "changes": {}}) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret ) # 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, "mount.read_mount_cache": mock_read_cache, "mount.write_mount_cache": mock_write_cache, "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): comt = "Target was already mounted. Entry already exists in the fstab." ret.update({"name": name2, "result": True}) ret.update({"comment": comt, "changes": {}}) self.assertDictEqual( mount.mounted( name2, device2, fstype2, opts=["uid=user1", "gid=group1"], ), ret, ) 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, )
def test_mounted(self): ''' Test to verify that a device is mounted. ''' name = '/mnt/sdb' device = '/dev/sdb5' fstype = 'xfs' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=['new', 'present', 'new', 'change', 'bad config', 'salt']) 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': [], 'superopts': []}}) mock_emt = MagicMock(return_value={}) mock_str = MagicMock(return_value='salt') umount1 = ("Forced unmount because devices don't match. " "Wanted: /dev/sdb6, current: /dev/sdb5, /dev/sdb5") with patch.dict(mount.__grains__, {'os': 'Darwin'}): with patch.dict(mount.__salt__, {'mount.active': mock_mnt, 'cmd.run_all': mock_ret, 'mount.umount': mock_f}): 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}): comt = ('Unable to unmount /mnt/sdb: False.') 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) comt = ('Unable to unmount') ret.update({'comment': comt, 'result': None, 'changes': {'umount': umount1}}) self.assertDictEqual(mount.mounted(name, '/dev/sdb6', fstype, opts=[]), ret) with patch.dict(mount.__salt__, {'mount.active': mock_emt, 'mount.mount': mock_str, 'mount.set_automaster': mock}): with patch.dict(mount.__opts__, {'test': True}): comt = ('{0} will be created and mounted'.format(name)) 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) with patch.dict(mount.__opts__, {'test': True}): comt = ('{0} needs to be ' 'written to the fstab in order to be ' 'made persistent'.format(name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) with patch.dict(mount.__opts__, {'test': False}): comt = ('/mnt/sdb not mounted. Entry already ' 'exists in the fstab.') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) comt = ('/mnt/sdb not mounted. ' 'Added new entry to the fstab.') ret.update({'comment': comt, 'result': True, 'changes': {'persist': 'new'}}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) comt = ('/mnt/sdb not mounted. ' 'Updated the entry in the fstab.') ret.update({'comment': comt, 'result': True, 'changes': {'persist': 'update'}}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) comt = ('/mnt/sdb not mounted. ' 'However, the fstab was not found.') ret.update({'comment': comt, 'result': False, 'changes': {}}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret) comt = ('/mnt/sdb not mounted') ret.update({'comment': comt, 'result': True, 'changes': {}}) self.assertDictEqual(mount.mounted(name, device, fstype, mount=False), ret)
def test_mounted(self): ''' Test to verify that a device is mounted. ''' name = '/mnt/sdb' device = '/dev/sdb5' fstype = 'xfs' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[ 'new', 'present', 'new', 'change', 'bad config', 'salt' ]) 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': [], 'superopts': [] } }) mock_emt = MagicMock(return_value={}) mock_str = MagicMock(return_value='salt') umount1 = ("Forced unmount because devices don't match. " "Wanted: /dev/sdb6, current: /dev/sdb5, /dev/sdb5") with patch.dict(mount.__grains__, {'os': 'Darwin'}): with patch.dict( mount.__salt__, { 'mount.active': mock_mnt, 'cmd.run_all': mock_ret, 'mount.umount': mock_f }): 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}): comt = ('Unable to unmount /mnt/sdb: False.') 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) comt = ('Unable to unmount') ret.update({ 'comment': comt, 'result': None, 'changes': { 'umount': umount1 } }) self.assertDictEqual( mount.mounted(name, '/dev/sdb6', fstype, opts=[]), ret) with patch.dict( mount.__salt__, { 'mount.active': mock_emt, 'mount.mount': mock_str, 'mount.set_automaster': mock }): with patch.dict(mount.__opts__, {'test': True}): comt = ('{0} will be created and mounted'.format(name)) 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) with patch.dict(mount.__opts__, {'test': True}): comt = ('{0} needs to be ' 'written to the fstab in order to be ' 'made persistent'.format(name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) with patch.dict(mount.__opts__, {'test': False}): comt = ('/mnt/sdb not mounted. Entry already ' 'exists in the fstab.') ret.update({'comment': comt, 'result': True}) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) comt = ('/mnt/sdb not mounted. ' 'Added new entry to the fstab.') ret.update({ 'comment': comt, 'result': True, 'changes': { 'persist': 'new' } }) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) comt = ('/mnt/sdb not mounted. ' 'Updated the entry in the fstab.') ret.update({ 'comment': comt, 'result': True, 'changes': { 'persist': 'update' } }) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) comt = ('/mnt/sdb not mounted. ' 'However, the fstab was not found.') ret.update({ 'comment': comt, 'result': False, 'changes': {} }) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret) comt = ('/mnt/sdb not mounted') ret.update({ 'comment': comt, 'result': True, 'changes': {} }) self.assertDictEqual( mount.mounted(name, device, fstype, mount=False), ret)