@@ -282,27 +282,6 @@ def prepare_target_userspace(context, userspace_dir, enabled_repos, packages):
282
282
raise StopActorExecutionError (message = message , details = details )
283
283
284
284
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
-
306
285
def _query_rpm_for_pkg_files (context , pkgs ):
307
286
files_owned_by_rpm = set ()
308
287
rpm_query_result = context .call (['rpm' , '-ql' ] + pkgs , split = True )
@@ -405,48 +384,37 @@ def _prep_repository_access(context, target_userspace):
405
384
"""
406
385
target_etc = os .path .join (target_userspace , 'etc' )
407
386
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' )
408
388
409
389
_copy_certificates (context , target_userspace )
410
390
411
391
if not rhsm .skip_rhsm ():
412
392
run (['rm' , '-rf' , os .path .join (target_etc , 'rhsm' )])
413
393
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
419
401
with mounting .NspawnActions (base_dir = target_userspace ) as target_context :
420
402
files_owned_by_rpms = _get_files_owned_by_rpms (target_context , '/etc/yum.repos.d' )
421
403
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
423
406
run (['mv' , target_yum_repos_d , backup_yum_repos_d ])
424
- context .copytree_from ('/etc/yum.repos.d' , target_yum_repos_d )
425
407
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 )
443
411
444
- # -> copy expected files back
412
+ # Copy back files owned by some RPM
445
413
for fname in files_owned_by_rpms :
446
414
api .current_logger ().debug ('Copy the backed up repo file: {}' .format (fname ))
447
415
run (['mv' , os .path .join (backup_yum_repos_d , fname ), os .path .join (target_yum_repos_d , fname )])
448
416
449
- # -> remove the backed up dir
417
+ # Cleanup - remove the backed up dir
450
418
run (['rm' , '-rf' , backup_yum_repos_d ])
451
419
452
420
0 commit comments