Skip to content

Commit

Permalink
rhui: do not bootstrap target client on aws
Browse files Browse the repository at this point in the history
  • Loading branch information
mhecko committed Feb 15, 2024
1 parent 5518ae0 commit b602f22
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 147 in repos/system_upgrade/common/actors/cloud/checkrhui/libraries/checkrhui.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

neccessary ==> necessary
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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


Expand Down Expand Up @@ -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

Expand All @@ -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

Check failure on line 1154 in repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

neccessary ==> necessary
# files into the leapp-rhui-<provider> packages.
api.current_logger().debug('Bootstrapping target RHUI client is disabled, leapp will rely '
'only on files budled in leapp-rhui-<provider> package.')
return

cmd = ['dnf', '-y']

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions repos/system_upgrade/common/models/rhuiinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-<provider> will be used to access target content.
"""

class RHUIInfo(Model):
"""
Expand Down

0 comments on commit b602f22

Please sign in to comment.