Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RHUI configuration #1142

Merged
merged 8 commits into from
Nov 13, 2024
Merged

Add RHUI configuration #1142

merged 8 commits into from
Nov 13, 2024

Conversation

abadger
Copy link
Member

@abadger abadger commented Nov 7, 2023

Add configuration options for leapp's RHUI handling and RPM transactions.

RHUI Configuration

Example of RHUI configuration:

rhui:
  use_config : True
  source_clients: [ rh-amazon-rhui-client ]
  target_clients: [ rh-amazon-rhui-client ]
  cloud_provider: aws
  upgrade_files:
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/leapp-aws.repo : /etc/yum.repos.d/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/rhui-client-config-server-9.crt : /etc/pki/rhui/product/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/rhui-client-config-server-9.key : /etc/pki/rhui/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/content-rhel9.crt : /etc/pki/rhui/product/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/content-rhel9.key : /etc/pki/rhui/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/cdn.redhat.com-chain.crt : /etc/pki/rhui/product/
  rhui_target_repositories_to_use:
    - rhel-9-appstream-rhui-rpms
    - rhel-9-baseos-rhui-rpms

Leapp reads the configuration, checking the use_config field to know whether the values from config should be used, instead of leapp's decision routines. If use_config=True, leapp will not do any automatic decisions about RHUI whatsoever. Therefore, the configured values determine what leapp will do.

The following configuration options are added:

Configuration field Description
source_clients RHUI clients to uninstall during the upgrade
target_clients RHUI clients to install during the upgrade
cloud_provider so that leapp knows it is running on cloud
upgrade_files mapping of paths of files on the source system to the corresponding destinations in the scratch container. Once the target container is set up, the files provided by the target client are used and the files from upgrade_files are removed.
enabled_target_repositories a list of repositories to enable. Functions the same way as using leapp --enablerepo

Known limitations

Using a repofile withing upgrade_files that uses different repoids than the target client(s) in combination with enable_target_repositories causes DNF transaction check to fail.

Jira refs:

Acceptance criteria for RHUI configuration:

  • It is possible to use config to upgrade unknown regions
  • Should make HA upgrades on AWS possible (achieved by a leapp-rhui-aws-ha that does not require)
  • Make rhui_repositories a required field (or rename to target_repoids_to_enable)
  • Make sure that repomapping does not error on unknown cloud providers.
    • Using cloud_provider = 'some_random_provider has been tried (with enabled_target_repositories), there were no problems - no code modifications are required.
  • Remove defaults - require user to supply everything

Copy link

github-actions bot commented Nov 7, 2023

Thank you for contributing to the Leapp project!

Please note that every PR needs to comply with the Leapp Guidelines and must pass all tests in order to be mergeable.
If you want to request a review or rebuild a package in copr, you can use following commands as a comment:

  • review please @oamg/developers to notify leapp developers of the review request
  • /packit copr-build to submit a public copr build using packit

Packit will automatically schedule regression tests for this PR's build and latest upstream leapp build. If you need a different version of leapp from PR#42, use /packit test oamg/leapp#42

It is possible to schedule specific on-demand tests as well. Currently 2 test sets are supported, beaker-minimal and kernel-rt, both can be used to be run on all upgrade paths or just a couple of specific ones.
To launch on-demand tests with packit:

  • /packit test --labels kernel-rt to schedule kernel-rt tests set for all upgrade paths
  • /packit test --labels beaker-minimal-8.9to9.3,kernel-rt-8.9to9.3 to schedule kernel-rt and beaker-minimal test sets for 8.9->9.3 upgrade path

[Deprecated] To launch on-demand regression testing public members of oamg organization can leave the following comment:

  • /rerun to schedule basic regression tests using this pr build and latest upstream leapp build as artifacts
  • /rerun 42 to schedule basic regression tests using this pr build and leapp*PR42* as artifacts
  • /rerun-sst to schedule sst tests using this pr build and latest upstream leapp build as artifacts
  • /rerun-sst 42 to schedule sst tests using this pr build and leapp*PR42* as artifacts

Please open ticket in case you experience technical problem with the CI. (RH internal only)

Note: In case there are problems with tests not being triggered automatically on new PR/commit or pending for a long time, please contact leapp-infra.

@abadger abadger marked this pull request as draft November 7, 2023 11:16
Comment on lines 20 to 32
class Transaction_ToKeep(Config):
section = "transaction"
name = "to_keep"
type_ = fields.List(fields.String(), default=[
"leapp",
"python2-leapp",
"python3-leapp",
"leapp-repository",
"snactor",
])
description = """
List of packages to be kept in the upgrade transaction.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to think why it cannot be same as with models? I mean:

Suggested change
class Transaction_ToKeep(Config):
section = "transaction"
name = "to_keep"
type_ = fields.List(fields.String(), default=[
"leapp",
"python2-leapp",
"python3-leapp",
"leapp-repository",
"snactor",
])
description = """
List of packages to be kept in the upgrade transaction.
"""
class Transaction_ToKeep(Config):
section = "transaction"
to_keep = fields.List(fields.String(), default=[
"leapp",
"python2-leapp",
"python3-leapp",
"leapp-repository",
"snactor",
])
"""
List of packages to be kept in the upgrade transaction.
"""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we've settled on yaml as the actual file system format, I think that loading more information into fields will be fine (default and type_). to_keep and the docstring treatment were things I didn't know about. I think they'll be fine too.

One ramification of relying on fields (I think in any incarnation) is that we should allow mapping values. I heard that those were specifically excluded from the present fields because they were considered too complex and unnecessary for Models. I do not think those are true for config values. Yaml has dictionaries as basic data types and in cases where you want to group record-style information, yaml mappings make the most sense.

hosts:
    balancer.example.com: 192.168.100.2
    git.example.com: 192.168.100.3

I don't know if we'll want to keep field.Mapping (or field.Dict) from being used in models or not care now that we have a need for it for a different purpose.

Copy link
Member

@pirat89 pirat89 Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abadger I was thinking about that during weekend, as I think I misunderstood you originally after reading this your comment and the example. I thought that this problem is addressed by fields.JSON which we can allow for configs to not be so strict. However, thinking about that, I think you provided totally valid point about having something like a Map/Mapping/Dict field, which could have variable keys (like hosts, where we do not know number of such items, nor specific keys itself). But we could on the other hand still define what will be values like in case of other fields. So the use for the example above, I could imagine to allow something like:

class MyConfig(Config):
    hosts = fields.Mapping(fields.String)  # or e.g. fields.Mapping(value_type=fields.String)

Where we can define what will be values, hence the key is expected to be always string (no sure whether we would need anything else for keys than string). For the completness, I can imagine we could resolve it also differently, but usually it would lead to some magical tweaks around serialisation/deserialisation, or little bit worse UX, e.g. to require user to write config like:

hosts:
    - hostname: balancer.example.com
    - ip: 192.168.100.3

Which is doable and still kind of reasonable, but thinking about the trade-off, it make sense to me to be less strict here. The benefix of the "Mapping" field is, that we can still define properly structure of expected values, so the only unknown it's value/number of the key(s), which in this case it's not so problematic. In case of the JSON field, it's completely unknown (nor key, nor value) and reduce our possibilities of the validation much more.

@abadger Do I understand correctly your idea?


Just to provide context why we usually do not allow fields.JSON in Models inside our official repositories. It's because the JSON field cannot be verified for the content. From the point, we can verify the structure is JSON, but we cannot verify it contains particular fields / content inside, so the structure can vary and we couldn't guarantee that part of this structure will be always a specific key/item (due to bugs, or changes in actor that produce a particular msg, so some other actors - e.g. custom ones - could start to be broken without clean visibility of the problem). Having strict structure in models, provides clear definition of the content and people can easily see it.

@abadger abadger force-pushed the actor-config branch 2 times, most recently from bee18dd to 08fb1e6 Compare July 8, 2024 05:06
@abadger
Copy link
Member Author

abadger commented Sep 12, 2024

/packit test oamg/leapp#870

3 similar comments
@abadger
Copy link
Member Author

abadger commented Sep 12, 2024

/packit test oamg/leapp#870

@abadger
Copy link
Member Author

abadger commented Sep 12, 2024

/packit test oamg/leapp#870

@abadger
Copy link
Member Author

abadger commented Sep 12, 2024

/packit test oamg/leapp#870

@abadger abadger force-pushed the actor-config branch 7 times, most recently from 4e4ad3a to 40260c0 Compare September 13, 2024 09:01
@abadger abadger force-pushed the actor-config branch 12 times, most recently from 4af8f20 to 98630ff Compare September 19, 2024 09:39
@MichalHe
Copy link
Member

/packit copr-build

@bparry02
Copy link

I was able to upgrade RHEL 8 to 9 x86 successfully using a personal RHUI and custom source and target client RPM names. Well done team!

leapp-0.18.0-0.20241020152857414426.pr870.2.ge2f13b4.el8.noarch
leapp-deps-el9-5.0.9-0.202410231928Z.356a5b37.pr_1142.el9.noarch
leapp-repository-deps-el9-5.0.9-0.202410231928Z.356a5b37.pr_1142.el9.noarch
leapp-upgrade-el8toel9-0.21.0-0.20241023192831897106.pr1142.34.g356a5b37.el8.noarch
python3-leapp-0.18.0-0.20241020152857414426.pr870.2.ge2f13b4.el8.noarch

I did try RHEL 7to8 as well, but ran into the glob error mentioned in the description of leapp PR 870.

@pirat89 pirat89 added the enhancement New feature or request label Oct 25, 2024
@pirat89 pirat89 added this to the 8.10/9.6 milestone Oct 25, 2024
@MichalHe MichalHe marked this pull request as ready for review October 29, 2024 19:04
@MichalHe MichalHe changed the title Add RHUI and RPM Transaction configuration Add RHUI configuration Nov 10, 2024
@pirat89
Copy link
Member

pirat89 commented Nov 11, 2024

added a squash commit modifying %files section covering correct mark of configuration files in the actor_conf.d directory (if any are present in future, provided by the rpm) and making the directory part of the rpm, to fix:

# rpm -qf /etc/leapp/actor_conf.d/
file /etc/leapp/actor_conf.d is not owned by any package

Copy link
Member

@pirat89 pirat89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichalHe lgtm, just the schema should be updated to be more consistent regarding defaults (see comments). Also I will try to do the upgrade with updated config yet as we discussed.

also, do not forget to drop the config file from the rpm and polish commits
(including better explanation in the commit updating target user spaces creator actor, speaking about the check of removal files based on whether they are owned by rpm or not)

repos/system_upgrade/common/configs/rhui.py Outdated Show resolved Hide resolved
repos/system_upgrade/common/configs/rhui.py Outdated Show resolved Hide resolved
repos/system_upgrade/common/configs/rhui.py Show resolved Hide resolved
@pirat89
Copy link
Member

pirat89 commented Nov 13, 2024

tested manually for IPU 7 -> 8 and 8 -> 9 on RHUI AWS.

Note, config for IPU 7 -> 8 on AWS looks like this:

rhui:
  use_config : True
  source_clients: [ rh-amazon-rhui-client ]
  target_clients: [ rh-amazon-rhui-client ]
  cloud_provider: aws
  upgrade_files:
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/amazon-id.py: /usr/lib/python2.7/site-packages/dnf-plugins/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/leapp-aws.repo : /etc/yum.repos.d/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/cdn.redhat.com-chain.crt : /etc/pki/rhui/product/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/content-rhel8.crt : /etc/pki/rhui/product/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/content-rhel8.key : /etc/pki/rhui
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/rhui-client-config-server-8.crt : /etc/pki/rhui/product/
    /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/aws/rhui-client-config-server-8.key : /etc/pki/rhui
  rhui_target_repositories_to_use:
    - rhel-8-appstream-rhui-rpms
    - rhel-8-baseos-rhui-rpms

The leapp actors configuration feature is present since
leapp-framework 6.0. Update the dependencies to ensure the correct
version of the framework is installed on the system.

Also, leapp requirements have been updated - requiring python3-PyYAML
as it requires YAML parser, bumping leapp-framework-dependencies to 6.
Address the change in leapp-deps metapackage to satisfy leapp
dependencies during the upgrade process.
@pirat89 pirat89 force-pushed the actor-config branch 2 times, most recently from 0b7058f to 05f15b2 Compare November 13, 2024 14:11
@pirat89
Copy link
Member

pirat89 commented Nov 13, 2024

@MichalHe I've drop the tmp commits. Also I made one small change. I'Ve added etc/leapp/actor_confid.d dir to the repo (with .gitkeep file) and ensure that if someone adds a file into the repo e.g. because we decide to have the config part of the rpm (livemode one?) it's automatically part of the rpm. (iow keeping the change from one of removed commits).

Also added a commit that ensures that all .gitkeep files are deleted when building rpm. so they are not installed then.

pirat89
pirat89 previously approved these changes Nov 13, 2024
Copy link
Member

@pirat89 pirat89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. I made some small changes (see my comment above). It's prepared for the merge, but let's wait for finished tests. Note that one of 8 -> 9 tests seems to be broken, so if the "rhsm" related test is the only one that's failing, it's ok to be merged.

Michal Hecko and others added 7 commits November 13, 2024 19:23
Add additional build steps to the specfile that create the actor
configuration directory. The directory is owned by the package, so
it gets removed when the user uninstalls leapp.

Also prepared some comment lines for future when we will want to
include some configuration files as part of the rpm.
We have several .gitkeep files in the repo as we want to have some
directories present in git however these directories are empty
otherwise. This is common hack to achieve this, but we do not want
to have these files really in the resulting RPMs. So we just remove
them.
Load actor configuration when running `leapp upgrade` or `leapp
preupgrade`. The configuration is loaded, saved to leapp's DB,
and remains available to all actors via framework's global variable.
Introduce a common configuration definition for RHUI related decisions.
The configuration has an atomic nature - if the user wants to overwrite
leapp's decisions, he/she must overwrite all of them. Essentially, all
fields of the RHUI_SETUPS cloud map entry can be configured. Almost no
non-empty defaults are provided, as no reasonable defaults can be given.
This is due to all setup parameters are different from provider to
provider. Therefore, default values are empty values, so that it can
later be detected by an actor whether all fields of the RHUI config
has been filled.

Jira ref: RHEL-56251
Extend the check_rhui actor to read user-provided RHUI configuration.
If the provided configuration values say that the user wants to
overrwrite leapp's decisions, then the patch checks whether all values
are provided. If so, corresponding RHUIInfo message is produced. The
only implemented safe-guards are those that prevent the user from
accidentaly specifying a non-existing file to be copied into the
scrach container during us preparing to download target userspace
content. If the user provides only some of the configuration values
the upgrade is terminated early with an error, providing quick feedback
about misconfiguration. The patch has been designed to allow development
of upgrades on previously unknown clouds (clouds without an entry in
RHUI_SETUPS).

Jira ref: RHEL-56251
Extend the CurrentActorMocked class to accept a `config` value,
allowing developers to mock actors that rely on configuration.
A library function `_make_default_config` is also introduced,
allowing to instantiate default configs from config schemas.
We copy files into the target userspace when setting up target
repository content. If this file is named equally as some of the
files installed by the target RHUI client installed during early
phases of target userspace setup process, we would delete it in
cleanup. Therefore, if we copy a repofile named /etc/yum.repos.d/X.repo
and the target client also owns a file /etc/yum.repos.d/X.repo, we
would remove it, making the container loose access to target content.
This patch prevents us from blindly deleting files, keeping files that
are owned by some RPM (usually that would be the target RHUI client).
@pirat89 pirat89 merged commit 0147bc2 into oamg:main Nov 13, 2024
24 of 26 checks passed
@pirat89 pirat89 added the changelog-checked The merger/reviewer checked the changelog draft document and updated it when relevant label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-checked The merger/reviewer checked the changelog draft document and updated it when relevant enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants