Esempio n. 1
0
    def test_load(self):
        '''
        Tests to loads specified kernel module.
        '''
        mod = 'cheese'
        err_msg = 'Module too moldy, refusing to load'
        mock_persist = MagicMock(return_value=set([mod]))
        mock_lsmod = MagicMock(return_value=[{
            'size': 100,
            'module': None,
            'depcount': 10,
            'deps': None
        }])
        mock_run_all_0 = MagicMock(return_value={'retcode': 0})
        mock_run_all_1 = MagicMock(return_value={
            'retcode': 1,
            'stderr': err_msg
        })

        with patch('salt.modules.kmod._set_persistent_module', mock_persist):
            with patch('salt.modules.kmod.lsmod', mock_lsmod):
                with patch.dict(kmod.__salt__,
                                {'cmd.run_all': mock_run_all_0}):
                    self.assertEqual([mod], kmod.load(mod, True))

                with patch.dict(kmod.__salt__,
                                {'cmd.run_all': mock_run_all_1}):
                    self.assertEqual(
                        'Error loading module {0}: {1}'.format(mod, err_msg),
                        kmod.load(mod))
Esempio n. 2
0
    def test_load(self):
        '''
        Tests to loads specified kernel module.
        '''
        mock_ret = [{'size': 100, 'module': None, 'depcount': 10, 'deps': None}]
        with patch('salt.modules.kmod.lsmod', MagicMock(return_value=mock_ret)):
            mock = MagicMock(return_value={'retcode': 0})
            with patch.dict(kmod.__salt__, {'cmd.run_all': mock}):
                self.assertEqual(['lp'], kmod.load('lp', True))

            mock = MagicMock(return_value={'retcode': 1})
            with patch.dict(kmod.__salt__, {'cmd.run_all': mock}):
                self.assertEqual('Module abc not found', kmod.load('abc'))
Esempio n. 3
0
    def test_load(self):
        """
        Tests to loads specified kernel module.
        """
        mock_ret = [{"size": 100, "module": None, "depcount": 10, "deps": None}]
        with patch("salt.modules.kmod.lsmod", MagicMock(return_value=mock_ret)):
            mock = MagicMock(return_value={"retcode": 0})
            with patch.dict(kmod.__salt__, {"cmd.run_all": mock}):
                self.assertEqual(["lp"], kmod.load("lp", True))

            mock = MagicMock(return_value={"retcode": 1})
            with patch.dict(kmod.__salt__, {"cmd.run_all": mock}):
                self.assertEqual("Module abc not found", kmod.load("abc"))
Esempio n. 4
0
    def test_load(self):
        """
        Tests to loads specified kernel module.
        """
        mod = "cheese"
        err_msg = "Module too moldy, refusing to load"
        mock_persist = MagicMock(return_value=set([mod]))
        mock_lsmod = MagicMock(
            return_value=[{"size": 100, "module": None, "depcount": 10, "deps": None}]
        )
        mock_run_all_0 = MagicMock(return_value={"retcode": 0})
        mock_run_all_1 = MagicMock(return_value={"retcode": 1, "stderr": err_msg})

        with patch("salt.modules.kmod._set_persistent_module", mock_persist):
            with patch("salt.modules.kmod.lsmod", mock_lsmod):
                with patch.dict(kmod.__salt__, {"cmd.run_all": mock_run_all_0}):
                    self.assertEqual([mod], kmod.load(mod, True))

                with patch.dict(kmod.__salt__, {"cmd.run_all": mock_run_all_1}):
                    self.assertEqual(
                        "Error loading module {0}: {1}".format(mod, err_msg),
                        kmod.load(mod),
                    )
Esempio n. 5
0
    def test_load(self):
        '''
        Tests to loads specified kernel module.
        '''
        mod = 'cheese'
        err_msg = 'Module too moldy, refusing to load'
        mock_persist = MagicMock(return_value=set([mod]))
        mock_lsmod = MagicMock(return_value=[{'size': 100,
                                              'module': None,
                                              'depcount': 10,
                                              'deps': None}])
        mock_run_all_0 = MagicMock(return_value={'retcode': 0})
        mock_run_all_1 = MagicMock(return_value={'retcode': 1,
                                                 'stderr': err_msg})

        with patch('salt.modules.kmod._set_persistent_module', mock_persist):
            with patch('salt.modules.kmod.lsmod', mock_lsmod):
                with patch.dict(kmod.__salt__, {'cmd.run_all': mock_run_all_0}):
                    self.assertEqual([mod], kmod.load(mod, True))

                with patch.dict(kmod.__salt__, {'cmd.run_all': mock_run_all_1}):
                    self.assertEqual('Error loading module {0}: {1}'.format(mod, err_msg),
                                     kmod.load(mod))