diff --git a/repos/system_upgrade/common/actors/cloud/checkrhui/libraries/checkrhui.py b/repos/system_upgrade/common/actors/cloud/checkrhui/libraries/checkrhui.py index 2b877bffad..e776f100ff 100644 --- a/repos/system_upgrade/common/actors/cloud/checkrhui/libraries/checkrhui.py +++ b/repos/system_upgrade/common/actors/cloud/checkrhui/libraries/checkrhui.py @@ -28,6 +28,7 @@ def customize_rhui_setup_for_gcp(provider, setup_info): # The google-cloud.repo repofile provides the repoid with target clients, however, the repoid is the same across # all rhel versions, therefore, we need to remove the source google-cloud.repo to enable correct target one. setup_info.preinstall_tasks.files_to_remove.append('/etc/yum.repos.d/google-cloud.repo') + setup_info.are_clients_sufficient = False def produce_rhui_info_for_provider(provider): diff --git a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py index ba71938ad1..dd3a2f7e29 100644 --- a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py +++ b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py @@ -564,6 +564,14 @@ def _get_rhui_available_repoids(context, cloud_repo): return set(repoids) +def get_copy_location_from_copy_in_task(context, copy_task): + basename = os.path.basename(copy_task.src) + dest_in_container = context.full_path(copy_task.dst) + if os.path.isdir(dest_in_container): + return os.path.join(copy_task.dst, basename) + return copy_task.dst + + def _get_rh_available_repoids(context, indata): """ RH repositories are provided either by RHSM or are stored in the expected repo file provided by @@ -582,12 +590,6 @@ def is_repofile(path): def extract_repoid_from_line(line): return line.split(':', maxsplit=1)[1].strip() - def get_full_dest(copy_task): - basename = os.path.basename(copy_task.src) - dest = copy_task.dst - full_dest = dest if dest.endswith('.repo') else os.path.join(context.full_path(dest), basename) - return full_dest - target_ver = api.current_actor().configuration.version.target setup_tasks = indata.rhui_info.target_client_setup_info.preinstall_tasks.files_to_copy_in @@ -598,7 +600,10 @@ def get_full_dest(copy_task): # Exclude also repofiles used to setup the target rhui access as on some platforms the repos provided by # the client are not sufficient to install the client into target userspace (GCP) rhui_setup_repofile_tasks = [task for task in setup_tasks if task.src.endswith('repo')] - rhui_setup_repofiles = {get_full_dest(copy_task) for copy_task in rhui_setup_repofile_tasks} + rhui_setup_repofiles = ( + get_copy_location_from_copy_in_task(context, copy_task) for copy_task in rhui_setup_repofile_tasks + ) + rhui_setup_repofiles = {context.full_path(repofile) for repofile in rhui_setup_repofiles} foreign_repofiles = all_repofiles - client_repofiles - rhui_setup_repofiles @@ -862,6 +867,16 @@ def install_target_rhui_client_if_needed(context, indata): context.makedirs(os.path.dirname(copy_info.dst), exists_ok=True) context.call(['cp', copy_info.src, copy_info.dst]) + # If the clients are sufficient to access target RHUI then remove copied repofiles so that + # there are no duplicit repoids + if setup_info.are_clients_sufficient: + files_owned_by_clients = _query_rpm_for_pkg_files(context, indata.target_client_pkg_names) + + for copy_task in setup_info.preinstall_tasks.files_to_copy_in: + dest = get_copy_location_from_copy_in_task(context, copy_task) + if dest not in files_owned_by_clients: + context.remove(dest) + @suppress_deprecation(TMPTargetRepositoriesFacts) def perform(): diff --git a/repos/system_upgrade/common/models/rhuiinfo.py b/repos/system_upgrade/common/models/rhuiinfo.py index df18c6859f..a21144bcac 100644 --- a/repos/system_upgrade/common/models/rhuiinfo.py +++ b/repos/system_upgrade/common/models/rhuiinfo.py @@ -7,7 +7,7 @@ class TargetRHUIPreInstallTasks(Model): topic = SystemInfoTopic files_to_remove = fields.List(fields.String(), default=[]) - """Files to remove from the source system in order to setup target RHUI acces""" + """Files to remove from the source system in order to setup target RHUI access""" files_to_copy_in = fields.List(fields.Model(CopyFile), default=[]) """Files to copy into the scratch (overlayfs) container in order to setup target RHUI access"""