Skip to content

Commit

Permalink
rhui: change how configs are accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Hecko committed Oct 5, 2024
1 parent cfee78b commit 5499427
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
from leapp.exceptions import StopActorExecutionError
from leapp.libraries.common import rhsm, rhui
from leapp.libraries.common.config import version
import leapp.configs.common.rhui as rhui_config_lib
from leapp.configs.common.rhui import ( # Import all config fields so we are not using their name attributes directly
RhuiEnabledTargetRepositories,
RhuiCloudProvider,
RhuiCloudVariant,
RhuiSourcePkgs,
RhuiTargetPkgs,
RhuiUpgradeFiles,
RhuiUseConfig,
)
from leapp.libraries.stdlib import api
from leapp.models import (
CopyFile,
Expand All @@ -21,6 +31,7 @@
TargetUserSpacePreupgradeTasks
)


MatchingSetup = namedtuple('MatchingSetup', ['family', 'description'])


Expand Down Expand Up @@ -319,7 +330,8 @@ def inform_about_upgrade_with_rhui_without_no_rhsm():


def emit_rhui_setup_tasks_based_on_config(rhui_config_dict):
files_to_copy_into_overlay = [CopyFile(src=key, dst=value) for key, value in rhui_config_dict['upgrade_files']]
config_upgrade_files = rhui_config_dict[RhuiUpgradeFiles.name]
files_to_copy_into_overlay = [CopyFile(src=key, dst=value) for key, value in config_upgrade_files.items()]
preinstall_tasks = TargetRHUIPreInstallTasks(files_to_copy_into_overlay=files_to_copy_into_overlay)

target_client_setup_info = TargetRHUISetupInfo(
Expand All @@ -329,33 +341,34 @@ def emit_rhui_setup_tasks_based_on_config(rhui_config_dict):
)

rhui_info = RHUIInfo(
provider=rhui_config_dict['cloud_provider'],
variant=rhui_config_dict['image_variant'],
provider=rhui_config_dict[RhuiCloudProvider.name],
variant=rhui_config_dict[RhuiCloudVariant.name],
src_client_pkg_names=list(),
target_client_pkg_names=rhui_config_dict['target_clients_names'],
target_client_pkg_names=rhui_config_dict[RhuiTargetPkgs.name],
target_client_setup_info=target_client_setup_info
)
api.produce(rhui_info)


def request_configured_repos_to_be_enabled(rhui_config):
custom_repos = [CustomTargetRepository(repoid=repoid) for repoid in rhui_config['enabled_target_repositories']]
config_repos_to_enable = rhui_config[RhuiEnabledTargetRepositories.name]
custom_repos = [CustomTargetRepository(repoid=repoid) for repoid in config_repos_to_enable]
if custom_repos:
target_repos = TargetRepositories(custom_repos=custom_repos)
target_repos = TargetRepositories(custom_repos=custom_repos, rhel_repos=[])
api.produce(target_repos)


def process():
rhui_config = api.current_actor().config['rhui']
expected_fields = (
'target_clients', 'source_clients', 'image_variant',
'cloud_provider', 'upgrade_files', 'enabled_target_repositories'
)
rhui_config = api.current_actor().config[rhui_config_lib.RHUI_CONFIG_SECTION]

if all(expected_field in rhui_config for expected_field in expected_fields):
if rhui_config[RhuiUseConfig.name]:
api.current_logger().info('Skipping RHUI upgrade auto-configuration - using provided config instead.')
emit_rhui_setup_tasks_based_on_config(rhui_config)
produce_rpms_to_install_into_target(set(rhui_config['source_clients']), set(rhui_config['target_clients']))

src_clients = set(rhui_config[RhuiSourcePkgs.name])
target_clients = set(rhui_config[RhuiTargetPkgs.name])
produce_rpms_to_install_into_target(src_clients, target_clients)

request_configured_repos_to_be_enabled(rhui_config)
return

Expand Down
48 changes: 37 additions & 11 deletions repos/system_upgrade/common/configs/rhui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@
from leapp.models import fields


class RhuiSourcePkg(Config):
section = "rhui"
RHUI_CONFIG_SECTION = 'rhui'

# @Note(mhecko): We use to distinguish config instantiated from default values that we should ignore
# # Maybe we could make all config values None and detect it that way, but then we cannot
# # give the user an example how the config should look like.
class RhuiUseConfig(Config):
section = RHUI_CONFIG_SECTION
name = "use_config"
type_ = fields.Boolean(default=False)
default = False
description = """
Use values provided in the configuration file to override leapp's decisions.
"""


class RhuiSourcePkgs(Config):
section = RHUI_CONFIG_SECTION
name = "source_clients"
type_ = fields.List(fields.String(default=["rhui"]))
default = ["rhui"]
Expand All @@ -21,10 +36,10 @@ class RhuiSourcePkg(Config):
"""


class RhuiTargetPkg(Config):
section = "rhui"
class RhuiTargetPkgs(Config):
section = RHUI_CONFIG_SECTION
name = "target_clients"
type_ = fields.List(fields.String(default=["rhui"]))
type_ = fields.List(fields.String(), default=["rhui"])
default = ["rhui"]
description = """
The name of the target RHUI client RPM (to be installed on the system).
Expand All @@ -33,7 +48,7 @@ class RhuiTargetPkg(Config):


class RhuiCloudProvider(Config):
section = "rhui"
section = RHUI_CONFIG_SECTION
name = "cloud_provider"
type_ = fields.String(default="rhui")
default = "provider"
Expand All @@ -53,7 +68,7 @@ class RhuiCloudProvider(Config):
# @Note(mhecko): We likely don't need this. We need the variant primarily to grab files from a correct directory
# in leapp-rhui-<provider> folders.
class RhuiCloudVariant(Config):
section = "rhui"
section = RHUI_CONFIG_SECTION
name = "image_variant"
type_ = fields.String(default="ordinary")
default = "ordinary"
Expand All @@ -72,9 +87,10 @@ class RhuiCloudVariant(Config):


class RhuiUpgradeFiles(Config):
section = "rhui"
section = RHUI_CONFIG_SECTION
name = "upgrade_files"
type_ = fields.StringMap(fields.String())
default = dict()
description = """
A mapping from source file paths to the destination where should they be
placed in the upgrade container.
Expand All @@ -87,7 +103,7 @@ class RhuiUpgradeFiles(Config):


class RhuiEnabledTargetRepositories(Config):
section = "rhui"
section = RHUI_CONFIG_SECTION
name = "enabled_target_repositories"
type_ = fields.List(fields.String())
description = """
Expand All @@ -96,5 +112,15 @@ class RhuiEnabledTargetRepositories(Config):
The repositories to be enabled need to be either in the repofiles givin within `upgrade_files` option,

Check failure on line 112 in repos/system_upgrade/common/configs/rhui.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

givin ==> giving, given
or in repofiles present on the source system.
"""

all_rhui_cfg = (RhuiTargetPkg, RhuiUpgradeFiles, RhuiEnabledTargetRepositories, RhuiCloudProvider)
default = list()


all_rhui_cfg = (
RhuiTargetPkgs,
RhuiUpgradeFiles,
RhuiEnabledTargetRepositories,
RhuiCloudProvider,
RhuiCloudVariant,
RhuiSourcePkgs,
RhuiUseConfig
)

0 comments on commit 5499427

Please sign in to comment.