Ejemplo n.º 1
0
    def test_is_fuse_exec(self):
        '''
        Returns true if the command passed is a fuse mountable application
        '''
        with patch.object(salt.utils.path, 'which', return_value=None):
            self.assertFalse(mount.is_fuse_exec('cmd'))

        def _ldd_side_effect(cmd, *args, **kwargs):
            '''
            Neither of these are full ldd output, but what is_fuse_exec is
            looking for is 'libfuse' in the ldd output, so these examples
            should be sufficient enough to test both the True and False cases.
            '''
            return {
                'ldd cmd1': textwrap.dedent('''\
                    linux-vdso.so.1 (0x00007ffeaf5fb000)
                    libfuse3.so.3 => /usr/lib/libfuse3.so.3 (0x00007f91e66ac000)
                    '''),
                'ldd cmd2': textwrap.dedent('''\
                    linux-vdso.so.1 (0x00007ffeaf5fb000)
                    ''')
            }[cmd]
        which_mock = MagicMock(side_effect=lambda x: x)
        ldd_mock = MagicMock(side_effect=_ldd_side_effect)
        with patch.object(salt.utils.path, 'which', which_mock):
            with patch.dict(mount.__salt__, {'cmd.run': _ldd_side_effect}):
                self.assertTrue(mount.is_fuse_exec('cmd1'))
                self.assertFalse(mount.is_fuse_exec('cmd2'))
Ejemplo n.º 2
0
def test_is_fuse_exec():
    """
    Returns true if the command passed is a fuse mountable application
    """
    with patch.object(salt.utils.path, "which", return_value=None):
        assert not mount.is_fuse_exec("cmd")

    def _ldd_side_effect(cmd, *args, **kwargs):
        """
        Neither of these are full ldd output, but what is_fuse_exec is
        looking for is 'libfuse' in the ldd output, so these examples
        should be sufficient enough to test both the True and False cases.
        """
        return {
            "ldd cmd1":
            textwrap.dedent("""\
                linux-vdso.so.1 (0x00007ffeaf5fb000)
                libfuse3.so.3 => /usr/lib/libfuse3.so.3 (0x00007f91e66ac000)
                """),
            "ldd cmd2":
            textwrap.dedent("""\
                linux-vdso.so.1 (0x00007ffeaf5fb000)
                """),
        }[cmd]

    which_mock = MagicMock(side_effect=lambda x: x)
    ldd_mock = MagicMock(side_effect=_ldd_side_effect)
    with patch.object(salt.utils.path, "which", which_mock):
        with patch.dict(mount.__salt__, {"cmd.run": _ldd_side_effect}):
            assert mount.is_fuse_exec("cmd1")
            assert not mount.is_fuse_exec("cmd2")
Ejemplo n.º 3
0
    def test_is_fuse_exec(self):
        '''
        Returns true if the command passed is a fuse mountable application
        '''
        with patch.object(salt.utils, 'which', return_value=None):
            self.assertFalse(mount.is_fuse_exec('cmd'))

        with patch.object(salt.utils, 'which', return_value=True):
            self.assertFalse(mount.is_fuse_exec('cmd'))

        mock = MagicMock(side_effect=[1, 0])
        with patch.object(salt.utils, 'which', mock):
            self.assertFalse(mount.is_fuse_exec('cmd'))
Ejemplo n.º 4
0
    def test_is_fuse_exec(self):
        '''
        Returns true if the command passed is a fuse mountable application
        '''
        with patch.object(salt.utils, 'which', return_value=None):
            self.assertFalse(mount.is_fuse_exec('cmd'))

        with patch.object(salt.utils, 'which', return_value=True):
            self.assertFalse(mount.is_fuse_exec('cmd'))

        mock = MagicMock(side_effect=[1, 0])
        with patch.object(salt.utils, 'which', mock):
            self.assertFalse(mount.is_fuse_exec('cmd'))
Ejemplo n.º 5
0
    def test_is_fuse_exec(self):
        '''
        Returns true if the command passed is a fuse mountable application
        '''
        # Return False if fuse doesn't exist
        with patch('salt.utils.which', return_value=None):
            self.assertFalse(mount.is_fuse_exec('cmd'))

        # Return CommandNotFoundError if fuse exists, but ldd doesn't exist
        with patch('salt.utils.which', side_effect=[True, False]):
            self.assertRaises(CommandNotFoundError, mount.is_fuse_exec, 'cmd')

        # Return False if fuse exists, ldd exists, but libfuse is not in the
        # return
        with patch('salt.utils.which', side_effect=[True, True]):
            mock = MagicMock(return_value='not correct')
            with patch.dict(mount.__salt__, {'cmd.run': mock}):
                self.assertFalse(mount.is_fuse_exec('cmd'))

        # Return True if fuse exists, ldd exists, and libfuse is in the return
        with patch('salt.utils.which', side_effect=[True, True]):
            mock = MagicMock(return_value='contains libfuse')
            with patch.dict(mount.__salt__, {'cmd.run': mock}):
                self.assertTrue(mount.is_fuse_exec('cmd'))