

@mock.patch('bareon.utils.grub.guess_grub')
@mock.patch('bareon.utils.grub.os.chmod')
@mock.patch('bareon.utils.grub.utils.execute')
def test_grub1_mbr_install_differs_boot(self, mock_exec, mock_chmod, mock_guess):
    mock_guess.return_value = '/sbin/grub'
    mock_chmod.return_value = ('stdout', 'stderr')
    batch = 'device (hd0) /dev/foo\n'
    batch += 'geometry (hd0) 130 255 63\n'
    batch += 'device (hd1) /dev/bar\n'
    batch += 'geometry (hd1) 130 255 63\n'
    batch += 'root (hd1,0)\n'
    batch += 'setup (hd0)\n'
    batch += 'quit\n'
    script = 'cat /tmp/grub.batch | /sbin/grub --no-floppy --batch'
    mock_open = mock.mock_open()
    with mock.patch('bareon.utils.grub.open', new=mock_open, create=True):
        gu.grub1_mbr('/dev/foo', '/dev/bar', '0', chroot='/target')
    self.assertEqual(mock_open.call_args_list, [mock.call('/target/tmp/grub.batch', 'wt', encoding='utf-8'), mock.call('/target/tmp/grub.sh', 'wt', encoding='utf-8')])
    mock_open_file = mock_open()
    self.assertEqual(mock_open_file.write.call_args_list, [mock.call(batch), mock.call(script)])
    mock_chmod.assert_called_once_with('/target/tmp/grub.sh', 493)
    mock_exec.assert_called_once_with('chroot', '/target', '/tmp/grub.sh', run_as_root=True, check_exit_code=[0])

dataset/ETHPy150Open openstack/bareon/bareon/tests/test_grub_utils.py TestGrubUtils.test_grub1_mbr_install_differs_boot/VarMisuse@46/106 `mock_exec`->`mock_chmod`