From b602f2244999ce0c09c37dc8bac720a042d90ce4 Mon Sep 17 00:00:00 2001 From: mhecko Date: Thu, 15 Feb 2024 09:56:27 +0100 Subject: [PATCH] rhui: do not bootstrap target client on aws --- .../cloud/checkrhui/libraries/checkrhui.py | 7 +- .../libraries/userspacegen.py | 68 ++++++++++++++----- .../system_upgrade/common/models/rhuiinfo.py | 6 ++ 3 files changed, 63 insertions(+), 18 deletions(-) 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 84ab40e353..83315c3b30 100644 --- a/repos/system_upgrade/common/actors/cloud/checkrhui/libraries/checkrhui.py +++ b/repos/system_upgrade/common/actors/cloud/checkrhui/libraries/checkrhui.py @@ -142,13 +142,18 @@ def customize_rhui_setup_for_aws(rhui_family, setup_info): target_version = version.get_target_major_version() if target_version == '8': - return # The rhel8 plugin is packed into leapp-rhui-aws as we need python2 compatible client + # RHEL8 rh-amazon-rhui-client depends on amazon-libdnf-plugin that depends + # essentially on the entire RHEL8 RPM stack, so we cannot just swap the clients + # The leapp-rhui-aws will provide all neccessary files to access entire RHEL8 content + setup_info.bootstrap_target_client = False + return amazon_plugin_copy_task = CopyFile(src='/usr/lib/python3.9/site-packages/dnf-plugins/amazon-id.py', dst='/usr/lib/python3.6/site-packages/dnf-plugins/') setup_info.postinstall_tasks.files_to_copy.append(amazon_plugin_copy_task) + def produce_rhui_info_to_setup_target(rhui_family, source_setup_desc, target_setup_desc): rhui_files_location = os.path.join(api.get_common_folder_path('rhui'), rhui_family.client_files_folder) diff --git a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py index d917bfd511..afbbd47459 100644 --- a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py +++ b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py @@ -871,7 +871,10 @@ def _get_rh_available_repoids(context, indata): # If we are upgrading a RHUI system, check what repositories are provided by the (already installed) target clients if indata and indata.rhui_info: - files_provided_by_clients = _query_rpm_for_pkg_files(context, indata.rhui_info.target_client_pkg_names) + setup_info = indata.rhui_info.target_client_setup_info + target_content_access_files = set() + if setup_info.bootstrap_target_client: + target_content_access_files = _query_rpm_for_pkg_files(context, indata.rhui_info.target_client_pkg_names) def is_repofile(path): return os.path.dirname(path) == '/etc/yum.repos.d' and os.path.basename(path).endswith('.repo') @@ -884,7 +887,7 @@ def extract_repoid_from_line(line): yum_repos_d = context.full_path('/etc/yum.repos.d') all_repofiles = {os.path.join(yum_repos_d, path) for path in os.listdir(yum_repos_d) if path.endswith('.repo')} - client_repofiles = {context.full_path(path) for path in files_provided_by_clients if is_repofile(path)} + target_access_repofiles = {context.full_path(path) for path in target_content_access_files if is_repofile(path)} # Exclude 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) @@ -894,7 +897,12 @@ def extract_repoid_from_line(line): ) rhui_setup_repofiles = {context.full_path(repofile) for repofile in rhui_setup_repofiles} - foreign_repofiles = all_repofiles - client_repofiles - rhui_setup_repofiles + foreign_repofiles = all_repofiles - target_access_repofiles - rhui_setup_repofiles + + api.current_logger().debug( + 'The following repofiles are considered as unknown to' + ' the target RHUI content setup and will be ignored: {0}'.format(' '.join(foreign_repofiles)) + ) # Rename non-client repofiles so they will not be recognized when running dnf repolist for foreign_repofile in foreign_repofiles: @@ -919,6 +927,9 @@ def extract_repoid_from_line(line): for foreign_repofile in foreign_repofiles: os.rename('{0}.back'.format(foreign_repofile), foreign_repofile) + api.current_logger().debug( + 'The following repofiles are considered as provided by RedHat: {0}'.format(' '.join(rh_repoids)) + ) return rh_repoids @@ -1101,7 +1112,34 @@ def _create_target_userspace(context, packages, files, target_repoids): rhsm.set_container_mode(target_context) -def install_target_rhui_client_if_needed(context, indata): +def _apply_rhui_access_preinstall_tasks(context, rhui_setup_info): + if rhui_setup_info.preinstall_tasks: + api.current_logger().debug('Applying RHUI preinstall tasks.') + preinstall_tasks = rhui_setup_info.preinstall_tasks + + for file_to_remove in preinstall_tasks.files_to_remove: + api.current_logger().debug('Removing {0} from the scratch container.'.format(file_to_remove)) + context.remove(file_to_remove) + + for copy_info in preinstall_tasks.files_to_copy_into_overlay: + api.current_logger().debug( + 'Copying {0} in {1} into the scratch container.'.format(copy_info.src, copy_info.dst) + ) + context.makedirs(os.path.dirname(copy_info.dst), exists_ok=True) + context.copy_to(copy_info.src, copy_info.dst) + + +def _apply_rhui_access_postinstall_tasks(context, rhui_setup_info): + if rhui_setup_info.postinstall_tasks: + api.current_logger().debug('Applying RHUI postinstall tasks.') + for copy_info in rhui_setup_info.postinstall_tasks.files_to_copy: + context.makedirs(os.path.dirname(copy_info.dst), exists_ok=True) + debug_msg = 'Copying {0} to {1} (inside the scratch container).' + api.current_logger().debug(debug_msg.format(copy_info.src, copy_info.dst)) + context.call(['cp', copy_info.src, copy_info.dst]) + + +def setup_target_rhui_access_if_needed(context, indata): if not indata.rhui_info: return @@ -1110,15 +1148,14 @@ def install_target_rhui_client_if_needed(context, indata): _create_target_userspace_directories(userspace_dir) setup_info = indata.rhui_info.target_client_setup_info - if setup_info.preinstall_tasks: - preinstall_tasks = setup_info.preinstall_tasks - - for file_to_remove in preinstall_tasks.files_to_remove: - context.remove(file_to_remove) + _apply_rhui_access_preinstall_tasks(context, setup_info) - for copy_info in preinstall_tasks.files_to_copy_into_overlay: - context.makedirs(os.path.dirname(copy_info.dst), exists_ok=True) - context.copy_to(copy_info.src, copy_info.dst) + if not setup_info.bootstrap_target_client: + # Installation of the target RHUI client is not possible and we bundle all neccessary + # files into the leapp-rhui- packages. + api.current_logger().debug('Bootstrapping target RHUI client is disabled, leapp will rely ' + 'only on files budled in leapp-rhui- package.') + return cmd = ['dnf', '-y'] @@ -1149,10 +1186,7 @@ def install_target_rhui_client_if_needed(context, indata): context.call(cmd, callback_raw=utils.logging_handler, stdin='\n'.join(dnf_transaction_steps)) - if setup_info.postinstall_tasks: - for copy_info in setup_info.postinstall_tasks.files_to_copy: - context.makedirs(os.path.dirname(copy_info.dst), exists_ok=True) - context.call(['cp', copy_info.src, copy_info.dst]) + _apply_rhui_access_postinstall_tasks(context, setup_info) # Do a cleanup so there are not duplicit repoids files_owned_by_clients = _query_rpm_for_pkg_files(context, indata.rhui_info.target_client_pkg_names) @@ -1184,7 +1218,7 @@ def perform(): target_iso = next(api.consume(TargetOSInstallationImage), None) with mounting.mount_upgrade_iso_to_root_dir(overlay.target, target_iso): - install_target_rhui_client_if_needed(context, indata) + setup_target_rhui_access_if_needed(context, indata) target_repoids = _gather_target_repositories(context, indata, prod_cert_path) _create_target_userspace(context, indata.packages, indata.files, target_repoids) diff --git a/repos/system_upgrade/common/models/rhuiinfo.py b/repos/system_upgrade/common/models/rhuiinfo.py index 3eaa482678..0114bb24db 100644 --- a/repos/system_upgrade/common/models/rhuiinfo.py +++ b/repos/system_upgrade/common/models/rhuiinfo.py @@ -36,6 +36,12 @@ class TargetRHUISetupInfo(Model): files_supporting_client_operation = fields.List(fields.String(), default=[]) """A subset of files copied in preinstall tasks that should not be cleaned up.""" + bootstrap_target_client = fields.Boolean(default=True) + """ + Swap the current RHUI client for the target one to facilitate access to the target content. + + When False, only files from the leapp-rhui- will be used to access target content. + """ class RHUIInfo(Model): """