Skip to content

Commit 4fb9981

Browse files
author
mhecko
committed
userspacegen: perserve custom repositories
1 parent 203558a commit 4fb9981

File tree

1 file changed

+15
-47
lines changed
  • repos/system_upgrade/common/actors/targetuserspacecreator/libraries

1 file changed

+15
-47
lines changed

repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -282,27 +282,6 @@ def prepare_target_userspace(context, userspace_dir, enabled_repos, packages):
282282
raise StopActorExecutionError(message=message, details=details)
283283

284284

285-
def _get_all_rhui_pkgs():
286-
"""
287-
Return the list of rhui packages
288-
289-
Currently, do not care about what rhui we have, release, etc.
290-
Just take all packages. We need them just for the purpose of filtering
291-
what files we have to remove (see _prep_repository_access) and it's ok
292-
for us to use whatever rhui rpms (the relevant rpms catch the problem,
293-
the others are just taking bytes in memory...). It's a hot-fix. We are going
294-
to refactor the library later completely..
295-
"""
296-
upg_path = rhui.get_upg_path()
297-
pkgs = []
298-
for rhui_map in rhui.RHUI_CLOUD_MAP[upg_path].values():
299-
for key in rhui_map.keys():
300-
if not key.endswith('pkg'):
301-
continue
302-
pkgs.append(rhui_map[key])
303-
return pkgs
304-
305-
306285
def _query_rpm_for_pkg_files(context, pkgs):
307286
files_owned_by_rpm = set()
308287
rpm_query_result = context.call(['rpm', '-ql'] + pkgs, split=True)
@@ -405,48 +384,37 @@ def _prep_repository_access(context, target_userspace):
405384
"""
406385
target_etc = os.path.join(target_userspace, 'etc')
407386
target_yum_repos_d = os.path.join(target_etc, 'yum.repos.d')
387+
backup_yum_repos_d = os.path.join(target_etc, 'yum.repos.d.backup')
408388

409389
_copy_certificates(context, target_userspace)
410390

411391
if not rhsm.skip_rhsm():
412392
run(['rm', '-rf', os.path.join(target_etc, 'rhsm')])
413393
context.copytree_from('/etc/rhsm', os.path.join(target_etc, 'rhsm'))
414-
# NOTE: we cannot just remove the original target yum.repos.d dir
415-
# as e.g. in case of RHUI a special RHUI repofiles are installed by a pkg
416-
# when the target userspace container is created. Removing these files we loose
417-
# RHUI target repositories. So ...->
418-
# -> detect such a files...
394+
395+
# NOTE: We cannot just remove the target yum.repos.d dir and replace it with yum.repos.d from the scratch
396+
# # that we've used to obtain the new DNF stack and install it into the target userspace. Although
397+
# # RHUI clients are being installed in both scratch and target containers, users can request their package
398+
# # to be installed into target userspace that might add some repos to yum.repos.d that are not in scratch.
399+
400+
# Detect files that are owned by some RPM - these cannot be deleted
419401
with mounting.NspawnActions(base_dir=target_userspace) as target_context:
420402
files_owned_by_rpms = _get_files_owned_by_rpms(target_context, '/etc/yum.repos.d')
421403

422-
# -> backup the orig dir & install the new one
404+
# Backup the target yum.repos.d so we can always copy the files installed by some RPM back into yum.repos.d
405+
# when we modify it
423406
run(['mv', target_yum_repos_d, backup_yum_repos_d])
424-
context.copytree_from('/etc/yum.repos.d', target_yum_repos_d)
425407

426-
# -> find old rhui repo files (we have to remove these as they cause duplicates)
427-
rhui_pkgs = _get_all_rhui_pkgs()
428-
old_files_owned_by_rhui_rpms = _get_files_owned_by_rpms(context, '/etc/yum.repos.d', rhui_pkgs)
429-
for fname in old_files_owned_by_rhui_rpms:
430-
api.current_logger().debug('Remove the old repofile: {}'.format(fname))
431-
run(['rm', '-f', os.path.join(target_yum_repos_d, fname)])
432-
# .. continue: remove our leapp rhui repo file (do not care if we are on rhui or not)
433-
for rhui_map in rhui.gen_rhui_files_map().values():
434-
for item in rhui_map:
435-
if item[1] != rhui.YUM_REPOS_PATH:
436-
continue
437-
target_leapp_repofile = os.path.join(target_yum_repos_d, item[0])
438-
if not os.path.isfile(target_leapp_repofile):
439-
continue
440-
# we found it!!
441-
run(['rm', '-f', target_leapp_repofile])
442-
break
408+
# Copy the yum.repos.d from scratch - preserve any custom repositories. No need to clean-up old RHUI clients,
409+
# we swap them for the new RHUI client in scratch (so the old one is not installed).
410+
context.copytree_from('/etc/yum.repos.d', target_yum_repos_d)
443411

444-
# -> copy expected files back
412+
# Copy back files owned by some RPM
445413
for fname in files_owned_by_rpms:
446414
api.current_logger().debug('Copy the backed up repo file: {}'.format(fname))
447415
run(['mv', os.path.join(backup_yum_repos_d, fname), os.path.join(target_yum_repos_d, fname)])
448416

449-
# -> remove the backed up dir
417+
# Cleanup - remove the backed up dir
450418
run(['rm', '-rf', backup_yum_repos_d])
451419

452420

0 commit comments

Comments
 (0)