Exemplo n.º 1
0
def generate_initram_disk(context):
    """
    Function to actually execute the initram creation.
    """
    generator_script = api.get_actor_file_path(INITRAM_GEN_SCRIPT_NAME)
    if not generator_script:
        raise StopActorExecutionError(
            message='Mandatory script to generate initram not available.',
            details=_reinstall_leapp_repository_hint())
    modules = _get_dracut_modules()
    copy_dracut_modules(context, modules)
    context.copy_to(generator_script, os.path.join('/',
                                                   INITRAM_GEN_SCRIPT_NAME))
    install_initram_deps(context)
    install_multipath_files(context)
    install_files = _install_files(context)
    # FIXME: issue #376
    context.call([
        '/bin/sh', '-c',
        'LEAPP_ADD_DRACUT_MODULES="{modules}" LEAPP_KERNEL_ARCH={arch} '
        'LEAPP_DRACUT_INSTALL_FILES="{files}" {cmd}'.format(
            modules=','.join([mod.name for mod in modules]),
            arch=api.current_actor().configuration.architecture,
            files=' '.join(install_files),
            cmd=os.path.join('/', INITRAM_GEN_SCRIPT_NAME))
    ])
    copy_boot_files(context)
Exemplo n.º 2
0
def generate_initram_disk(userspace_dir):
    # Copy dracut modules to el8 userspace
    copy_modules(userspace_dir)
    # Copy generate-initram.sh
    run([
        'cp',
        '-a',
        api.get_actor_file_path('generate-initram.sh'),
        userspace_dir
    ])
    run([
        'systemd-nspawn',
        '--register=no',
        '--quiet',
        '-D', userspace_dir,
        '/bin/sh', '/generate-initram.sh'
    ])
Exemplo n.º 3
0
def generate_initram_disk(context):
    """
    Function to actually execute the initram creation.
    """
    generator_script = api.get_actor_file_path(INITRAM_GEN_SCRIPT_NAME)
    if not generator_script:
        raise StopActorExecutionError(
            message='Mandatory script to generate initram not available.',
            details=_reinstall_leapp_repository_hint())
    modules = _get_dracut_modules()
    copy_dracut_modules(context, modules)
    context.copy_to(generator_script, os.path.join('/',
                                                   INITRAM_GEN_SCRIPT_NAME))
    install_initram_deps(context)
    context.call([
        '/bin/sh', '-c', 'LEAPP_ADD_DRACUT_MODULES={modules} {cmd}'.format(
            modules=','.join([mod.name for mod in modules]),
            cmd=os.path.join('/', INITRAM_GEN_SCRIPT_NAME))
    ])
    copy_boot_files(context)
Exemplo n.º 4
0
def prepare_userspace_for_initram(context):
    """
    Prepare the target userspace container to be able to generate init ramdisk

    This includes installation of rpms that are not installed yet. Copying
    files from the host to container, ... So when we start the process of
    the upgrade init ramdisk creation, the environment will be prepared with
    all required data and utilities.

    Note: preparation of dracut modules are handled outside of this function
    """
    packages = set()
    files = []
    _cftuples = set()

    def _update_files(copy_files):
        # add just uniq CopyFile objects to omit duplicate copying of files
        for cfile in copy_files:
            cftuple = (cfile.src, cfile.dst)
            if cftuple not in _cftuples:
                _cftuples.add(cftuple)
                files.append(cfile)

    generator_script = api.get_actor_file_path(INITRAM_GEN_SCRIPT_NAME)
    if not generator_script:
        raise StopActorExecutionError(
            message='Mandatory script to generate initram not available.',
            details=_reinstall_leapp_repository_hint())
    context.copy_to(generator_script, os.path.join('/',
                                                   INITRAM_GEN_SCRIPT_NAME))
    for msg in api.consume(TargetUserSpaceUpgradeTasks):
        packages.update(msg.install_rpms)
        _update_files(msg.copy_files)
    for message in api.consume(RequiredUpgradeInitramPackages):
        packages.update(message.packages)
    # install all required rpms first, so files installed/copied later
    # will not be overwritten during the dnf transaction
    _install_initram_deps(packages)
    _copy_files(context, files)
Exemplo n.º 5
0
def test_actor_all_files_paths(leapp_forked, repository, actor_name):  # noqa; pylint: disable=unused-argument
    with _with_loaded_actor(repository, actor_name) as (definition, actor):
        # API consistency verification
        assert api.files_paths() == actor.files_paths
        assert api.common_files_paths() == actor.common_files_paths
        assert api.actor_files_paths() == actor.actor_files_paths

        # Ensure environment and actor api results are the same
        assert ':'.join(actor.actor_files_paths) == os.getenv('LEAPP_FILES')
        assert ':'.join(
            actor.common_files_paths) == os.getenv('LEAPP_COMMON_FILES')
        assert ':'.join(actor.actor_tools_paths) == os.getenv('LEAPP_TOOLS')
        assert ':'.join(
            actor.common_tools_paths) == os.getenv('LEAPP_COMMON_TOOLS')

        # Here we must ensure that the sorted list of entries are correct
        assert sorted(actor.files_paths) == sorted(
            os.getenv('LEAPP_FILES').split(':') +
            os.getenv('LEAPP_COMMON_FILES').split(':'))

        assert sorted(actor.tools_paths) == sorted(
            os.getenv('LEAPP_TOOLS').split(':') +
            os.getenv('LEAPP_COMMON_TOOLS').split(':'))

        # Ensure LEAPP_FILES/actor_files_paths are really actor private
        for directory in actor.actor_files_paths:
            assert directory.startswith(definition.full_path)

        # Ensure the duplicate is resolvable from the actor private files and the right file
        assert actor.get_actor_file_path('duplicate')
        with open(actor.get_actor_file_path('duplicate')) as f:
            assert f.read().strip() == actor_name + '-actor'

        # Do the same thing with the API
        assert api.get_actor_file_path('duplicate')
        with open(api.get_actor_file_path('duplicate')) as f:
            assert f.read().strip() == actor_name + '-actor'

        # Ensure the duplicate is resolvable from the repository files and the right file
        assert actor.get_common_file_path('duplicate')
        with open(actor.get_common_file_path('duplicate')) as f:
            assert f.read().strip() == 'repository'

        # Do the same thing with the API
        assert api.get_common_file_path('duplicate')
        with open(api.get_common_file_path('duplicate')) as f:
            assert f.read().strip() == 'repository'

        # Ensure tools files api
        assert api.get_common_tool_path('directory/exec_script')
        assert check_output(api.get_common_tool_path(
            'directory/exec_script')).decode('utf-8').strip() == 'repository'
        assert not api.get_common_tool_path('directory/nonexec_script')

        assert api.get_actor_tool_path('directory/exec_script')
        assert check_output(api.get_actor_tool_path('directory/exec_script'))\
            .decode('utf-8').strip() == actor_name + '-actor'
        assert not api.get_actor_tool_path('directory/nonexec_script')

        # Ensure some file is resolvable from the repository files or the actor private files
        assert actor.get_file_path('duplicate')
        assert actor.get_file_path('duplicate') == api.get_file_path(
            'duplicate')

        check_path = 'directory/{}-actor'.format(actor_name)
        assert actor.get_file_path(check_path)
        assert api.get_file_path(check_path) == actor.get_file_path(check_path)

        assert actor.get_file_path('directory/repository')
        assert api.get_file_path(
            'directory/repository') == actor.get_file_path(
                'directory/repository')

        assert not actor.get_common_file_path(
            'directory/{}-actor'.format(actor_name))
        assert not api.get_common_file_path(
            'directory/{}-actor'.format(actor_name))

        assert not actor.get_actor_file_path('directory/repository')
        assert not api.get_actor_file_path('directory/repository')