Skip to content

Commit

Permalink
userspacegen: recognize freestanding rhui setups
Browse files Browse the repository at this point in the history
  • Loading branch information
mhecko committed Apr 24, 2023
1 parent dd8d86c commit 7ad0c6d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

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

Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion repos/system_upgrade/common/models/rhuiinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit 7ad0c6d

Please sign in to comment.