Exemple #1
0
def main():
    """
    DistMigration load new kernel for kexec reboot

    Loads the new kernel/initrd after migration for system reboot
    """
    root_path = Defaults.get_system_root_path()

    target_kernel = os.sep.join([root_path, Defaults.get_target_kernel()])
    target_initrd = os.sep.join([root_path, Defaults.get_target_initrd()])
    kexec_boot_data = '/var/tmp/kexec'
    Path.create(kexec_boot_data)
    shutil.copy(target_initrd, kexec_boot_data)
    try:
        log.info('Running kernel load service')
        log.info('Loading the target kernel')
        Command.run([
            'kexec', '--load', target_kernel, '--initrd',
            os.sep.join([kexec_boot_data,
                         os.path.basename(target_initrd)]), '--command-line',
            _get_cmdline(os.path.basename(target_kernel))
        ])
    except Exception as issue:
        log.error('Kernel load service raised exception: {0}', format(issue))
        raise DistMigrationKernelRebootException(
            'Failed to load kernel/initrd into memory: {0}'.format(issue))
Exemple #2
0
def main():
    """
    DistMigration load new kernel for kexec reboot

    Loads the new kernel/initrd after migration for system reboot
    """
    Logger.setup()
    log = logging.getLogger(Defaults.get_migration_log_name())
    if not MigrationConfig().is_soft_reboot_requested():
        log.info('skipping kexec --load (hard reboot requested)')
        return

    root_path = Defaults.get_system_root_path()

    target_kernel = os.sep.join([root_path, Defaults.get_target_kernel()])
    target_initrd = os.sep.join([root_path, Defaults.get_target_initrd()])
    kexec_boot_data = '/var/tmp/kexec'
    Path.create(kexec_boot_data)
    shutil.copy(target_initrd, kexec_boot_data)
    try:
        log.info('Running kernel load service')
        log.info('Loading the target kernel')
        Command.run([
            'kexec', '--load', target_kernel, '--initrd',
            os.sep.join([kexec_boot_data,
                         os.path.basename(target_initrd)]),
            '--kexec-file-syscall', '--command-line',
            _get_cmdline(os.path.basename(target_kernel))
        ])
    except Exception as issue:
        log.error('Kernel load service raised exception: {0}'.format(issue))
        raise DistMigrationKernelRebootException(
            'Failed to load kernel/initrd into memory: {0}'.format(issue))
Exemple #3
0
 def test_get_cmd_line_linuxefi(self, mock_path_exists, mock_logger_setup):
     mock_path_exists.return_value = True
     with open('../data/fake_grub_linuxefi.cfg') as fake_grub:
         fake_grub_data = fake_grub.read()
     with patch('builtins.open', create=True) as mock_open:
         mock_open.return_value = MagicMock(spec=io.IOBase)
         file_handle = mock_open.return_value.__enter__.return_value
         file_handle.read.return_value = fake_grub_data
         grub_cmd_content = \
             'root=UUID=ec7aaf92-30ea-4c07-991a-4700177ce1b8 ' + \
             'splash root=UUID=ec7aaf92-30ea-4c07-991a-4700177ce1b8 rw'
         result = _get_cmdline(
             os.path.basename(Defaults.get_target_kernel()))
         mock_open.assert_called_once_with(
             '/system-root/boot/grub2/grub.cfg')
         assert result == grub_cmd_content