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) mock_dev = MagicMock(return_value={name: {'device': device}}) mock_fs = MagicMock(return_value={name: {'device': name}}) mock_mnt = MagicMock(side_effect=[{name: {}}, {}, {}, {}]) comt3 = ('Mount point /mnt/sdb is unmounted but needs to be purged ' 'from /etc/auto_salt to be made persistent') 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. ' '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.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)
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) mock_dev = MagicMock(return_value={name: {'device': device}}) mock_fs = MagicMock(return_value={name: {'device': name}}) mock_mnt = MagicMock(side_effect=[{name: {}}, {}, {}, {}]) comt3 = ('Mount point /mnt/sdb is unmounted but needs to be purged ' 'from /etc/auto_salt to be made persistent') 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. ' '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.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)
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) mock_t = MagicMock(return_value=True) mock_dev = MagicMock(return_value={name: {"device": device}}) mock_fs = MagicMock(return_value={name: {"device": name}}) mock_mnt = MagicMock(side_effect=[{name: {}}, {}, {}, {}]) 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}}) mock_delete_cache = MagicMock(return_value=True) comt3 = ( "Mount point /mnt/sdb is unmounted but needs to be purged " "from /etc/auto_salt to be made persistent" ) 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. " "fstab entry for device {0} not found".format(device) ) 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) 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 ) ret.update({"comment": comt, "result": None, "name": name3}) self.assertDictEqual( mount.unmounted(name3, device3, persist=True), ret ) 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}, } ) self.assertDictEqual(mount.unmounted(name3, device3), ret)
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) mock_t = MagicMock(return_value=True) mock_dev = MagicMock(return_value={name: {'device': device}}) mock_fs = MagicMock(return_value={name: {'device': name}}) mock_mnt = MagicMock(side_effect=[{name: {}}, {}, {}, {}]) 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 }}) mock_delete_cache = MagicMock(return_value=True) comt3 = ('Mount point /mnt/sdb is unmounted but needs to be purged ' 'from /etc/auto_salt to be made persistent') 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. ' 'fstab entry for device {0} not found'.format(device)) 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) 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)) ret.update({ 'comment': comt, 'result': None, 'name': name3 }) self.assertDictEqual( mount.unmounted(name3, device3, persist=True), ret) 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 } }) self.assertDictEqual( mount.unmounted(name3, device3), ret)