Beispiel #1
0
    def test_conf(self):
        '''
        Test for Parse GRUB conf file
        '''
        file_data = IOError(errno.EACCES, 'Permission denied')
        with patch('salt.utils.files.fopen', mock_open(read_data=file_data)), \
                patch.object(grub_legacy, '_detect_conf', return_value='A'):
            self.assertRaises(CommandExecutionError, grub_legacy.conf)

        file_data = salt.utils.stringutils.to_str('\n'.join(
            ['#', 'A B C D,E,F G H']))
        with patch('salt.utils.files.fopen', mock_open(read_data=file_data)), \
                patch.object(grub_legacy, '_detect_conf', return_value='A'):
            conf = grub_legacy.conf()
            assert conf == {'A': 'B C D,E,F G H', 'stanzas': []}, conf
    def test_conf(self):
        """
        Test for Parse GRUB conf file
        """
        file_data = IOError(errno.EACCES, "Permission denied")
        with patch(
            "salt.utils.files.fopen", mock_open(read_data=file_data)
        ), patch.object(grub_legacy, "_detect_conf", return_value="A"):
            self.assertRaises(CommandExecutionError, grub_legacy.conf)

        file_data = salt.utils.stringutils.to_str("\n".join(["#", "A B C D,E,F G H"]))
        with patch(
            "salt.utils.files.fopen", mock_open(read_data=file_data)
        ), patch.object(grub_legacy, "_detect_conf", return_value="A"):
            conf = grub_legacy.conf()
            assert conf == {"A": "B C D,E,F G H", "stanzas": []}, conf
Beispiel #3
0
    def test_conf(self):
        '''
        Test for Parse GRUB conf file
        '''
        mock = MagicMock(side_effect=IOError('foo'))
        with patch('salt.utils.fopen', mock):
            with patch.object(grub_legacy, '_detect_conf', return_value='A'):
                self.assertRaises(CommandExecutionError, grub_legacy.conf)

        file_data = '\n'.join(['#', 'A B C D,E,F G H'])
        with patch('salt.utils.fopen',
                   mock_open(read_data=file_data), create=True) as f_mock:
            f_mock.return_value.__iter__.return_value = file_data.splitlines()
            with patch.object(grub_legacy, '_detect_conf', return_value='A'):
                self.assertEqual(grub_legacy.conf(),
                                 {'A': 'B C D,E,F G H', 'stanzas': []})
Beispiel #4
0
    def test_conf(self):
        '''
        Test for Parse GRUB conf file
        '''
        mock = MagicMock(side_effect=IOError('foo'))
        with patch('salt.utils.files.fopen', mock):
            with patch.object(grub_legacy, '_detect_conf', return_value='A'):
                self.assertRaises(CommandExecutionError, grub_legacy.conf)

        file_data = salt.utils.stringutils.to_str('\n'.join(['#', 'A B C D,E,F G H']))
        with patch('salt.utils.files.fopen',
                   mock_open(read_data=file_data), create=True) as f_mock:
            f_mock.return_value.__iter__.return_value = file_data.splitlines()
            with patch.object(grub_legacy, '_detect_conf', return_value='A'):
                self.assertEqual(grub_legacy.conf(),
                                 {'A': 'B C D,E,F G H', 'stanzas': []})