

@unittest2.skip('Fix after cray rebase')
@mock.patch('bareon.utils.grub.guess_grub2_conf')
@mock.patch('bareon.utils.grub.guess_grub2_mkconfig')
@mock.patch('bareon.utils.grub.utils.execute')
@mock.patch('bareon.utils.grub.guess_grub2_default')
def test_grub2_cfg(self, mock_def, mock_exec, mock_mkconfig, mock_conf):
    mock_def.return_value = '/etc/default/grub'
    mock_open.return_value = '/sbin/grub-mkconfig'
    mock_conf.return_value = '/boot/grub/grub.cfg'
    orig_content = 'foo\nGRUB_CMDLINE_LINUX="kernel-params-orig"\nbar'
    with mock.patch('bareon.utils.grub.open', new=mock.mock_open(read_data=orig_content), create=True) as mock_open:
        mock_open.return_value = mock.MagicMock(spec=io.IOBase)
        handle = mock_open.return_value.__enter__.return_value
        handle.__iter__.return_value = StringIO(orig_content)
        gu.grub2_cfg(kernel_params='kernel-params-new', chroot='/target', grub_timeout=10)
        self.assertEqual(mock_open.call_args_list, [mock.call('/target/etc/default/grub'), mock.call('/target/etc/default/grub', 'wt', encoding='utf-8')])
    gu.grub2_cfg(kernel_params='kernel-params-new', chroot='/target', grub_timeout=10)
    mock_exec.assert_called_once_with('chroot', '/target', '/sbin/grub-mkconfig', '-o', '/boot/grub/grub.cfg', run_as_root=True)

dataset/ETHPy150Open openstack/bareon/bareon/tests/test_grub_utils.py TestGrubUtils.test_grub2_cfg/VarMisuse@64/158 `mock_mkconfig`->`mock_open`