def _create_target_userspace(context, packages, files, target_repoids): """Create the target userspace.""" target_path = _get_target_userspace() prepare_target_userspace(context, target_path, target_repoids, list(packages)) _prep_repository_access(context, target_path) with mounting.NspawnActions(base_dir=target_path) as target_context: _copy_files(target_context, files) dnfplugin.install(_get_target_userspace()) # and do not forget to set the rhsm into the container mode again with mounting.NspawnActions(_get_target_userspace()) as target_context: rhsm.set_container_mode(target_context)
def _prepare_transaction(used_repos, target_userspace_info, binds=()): """ Creates the transaction environment needed for the target userspace DNF execution """ target_repoids = set() for message in used_repos: target_repoids.update([repo.repoid for repo in message.repos]) with mounting.NspawnActions(base_dir=target_userspace_info.path, binds=binds) as context: yield context, list(target_repoids), target_userspace_info
def _create_target_userspace(context, packages, target_repoids): """Create the target userspace.""" prepare_target_userspace(context, constants.TARGET_USERSPACE, target_repoids, list(packages)) _prep_repository_access(context, constants.TARGET_USERSPACE) dnfplugin.install(constants.TARGET_USERSPACE) # and do not forget to set the rhsm into the container mode again with mounting.NspawnActions(constants.TARGET_USERSPACE) as target_context: rhsm.set_container_mode(target_context)
def _backup_to_persistent_package_cache(userspace_dir): if get_env('LEAPP_DEVEL_USE_PERSISTENT_PACKAGE_CACHE', None) == '1': # Clean up any dead bodies, just in case run(['rm', '-rf', PERSISTENT_PACKAGE_CACHE_DIR]) if os.path.exists(os.path.join(userspace_dir, 'var', 'cache', 'dnf')): with mounting.NspawnActions( base_dir=userspace_dir) as target_context: target_context.copytree_from('/var/cache/dnf', PERSISTENT_PACKAGE_CACHE_DIR)
def _restore_persistent_package_cache(userspace_dir): if get_env('LEAPP_DEVEL_USE_PERSISTENT_PACKAGE_CACHE', None) == '1': if os.path.exists(PERSISTENT_PACKAGE_CACHE_DIR): with mounting.NspawnActions( base_dir=userspace_dir) as target_context: target_context.copytree_to(PERSISTENT_PACKAGE_CACHE_DIR, '/var/cache/dnf') # We always want to remove the persistent cache here to unclutter the system run(['rm', '-rf', PERSISTENT_PACKAGE_CACHE_DIR])
def _prep_repository_access(context, target_userspace): """ Prepare repository access by copying all relevant certificates and configuration files to the userspace """ target_etc = os.path.join(target_userspace, 'etc') target_yum_repos_d = os.path.join(target_etc, 'yum.repos.d') backup_yum_repos_d = os.path.join(target_etc, 'yum.repos.d.backup') if not rhsm.skip_rhsm(): run(['rm', '-rf', os.path.join(target_etc, 'pki')]) run(['rm', '-rf', os.path.join(target_etc, 'rhsm')]) context.copytree_from('/etc/pki', os.path.join(target_etc, 'pki')) context.copytree_from('/etc/rhsm', os.path.join(target_etc, 'rhsm')) # NOTE: we cannot just remove the original target yum.repos.d dir # as e.g. in case of RHUI a special RHUI repofiles are installed by a pkg # when the target userspace container is created. Removing these files we loose # RHUI target repositories. So ...-> # -> detect such a files... with mounting.NspawnActions(base_dir=target_userspace) as target_context: files_owned_by_rpms = _get_files_owned_by_rpms(target_context, '/etc/yum.repos.d') # -> backup the orig dir & install the new one run(['mv', target_yum_repos_d, backup_yum_repos_d]) context.copytree_from('/etc/yum.repos.d', target_yum_repos_d) # -> find old rhui repo files (we have to remove these as they cause duplicates) rhui_pkgs = _get_all_rhui_pkgs() old_files_owned_by_rhui_rpms = _get_files_owned_by_rpms( context, '/etc/yum.repos.d', rhui_pkgs) for fname in old_files_owned_by_rhui_rpms: api.current_logger().debug('Remove the old repofile: {}'.format(fname)) run(['rm', '-f', os.path.join(target_yum_repos_d, fname)]) # .. continue: remove our leapp rhui repo file (do not care if we are on rhui or not) for rhui_map in rhui.gen_rhui_files_map().values(): for item in rhui_map: if item[1] != rhui.YUM_REPOS_PATH: continue target_leapp_repofile = os.path.join(target_yum_repos_d, item[0]) if not os.path.isfile(target_leapp_repofile): continue # we found it!! run(['rm', '-f', target_leapp_repofile]) break # -> copy expected files back for fname in files_owned_by_rpms: api.current_logger().debug( 'Copy the backed up repo file: {}'.format(fname)) run([ 'mv', os.path.join(backup_yum_repos_d, fname), os.path.join(target_yum_repos_d, fname) ]) # -> remove the backed up dir run(['rm', '-rf', backup_yum_repos_d])
def process(): userspace_info = next(api.consume(TargetUserSpaceInfo), None) with mounting.NspawnActions(base_dir=userspace_info.path) as context: prepare_userspace_for_initram(context) generate_initram_disk(context)