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

[RHELC-1033, RHELC-1036, RHELC-1006] Stop uninstalling subscription-mananager and unregistering the system by default #869

Merged
merged 6 commits into from
Sep 7, 2023

Conversation

abadger
Copy link
Member

@abadger abadger commented Jul 20, 2023

Make subscription from within convert2rhel optional.

Previously, we would unregister a system if it was registered and then re-register with
subscription-manager. The only time we didn't do this would be when the user specified --no-rhsm
but that does too much. It causes convert2rhel to avoid the use of subscription-manager altogether
(it doesn't install the package or configure the RHEL repos) For our purposes, we just don't want to
replace the registration if the system already has one.

The strategy we're implementing here is:

  • If the user specifies (username and password) or (activation_key and organization) then (re)register the system.
  • If not, then attempt to do the conversion without registering the system first.

There are several distinct changes made to enable this functionality:

  • subscription.{subscribe_system,rollback}() were moved ito a RestorableChange (called
    RestorableSystemSubscription). This is mainly because deciding whether to unregister the system
    in case of a rollback now needs to have some saved state to know whether we registered it in the
    first place.
  • replace_subscription_manager() no longer unregisters the system as part of uninstalling the
    current subscription-manager packages and installing the RHEL ones.
  • A new property was added to toolopts, should_subscribe. This property tells whether the user has
    specified options which ask us to (re)register the system or not.
  • In pre_ponr_changes/subscription.py we now use should_subscribe to decide whether to (re)subscribe
    the system instead of only no_rhsm. We also use RestorableSystemSubscribe instead of calling
    subscribe_system().
  • In main.py we no longer have to call subscription.rollback() because the backup framework
    (backup.backup_control.pop_all()) will take care of rolling back the subscription.

Things that still need to be done:

  • Check all locations where no_rhsm is used to make sure that they shouldn't use
    toolopts.should_subscribe instead.
  • Ask mbocek about the commit message for bfcf149 to confirm
    whether removing unregistration from sub-man is okay
    • Test that a host that is subscribed and has its subscription-manager package removed and then the
      RHEL versions installed will keep the pre-uninstall registration and
    • The conclusion is that the host stays registered on the rhsm server but locally, the registration information is saved in /etc/rhsm/rhsm.conf.rpmsave when the subscription-manager package is removed. This .rpmsave file would need to be restored when the new package is installed.
    • Rather than attempt to restore /etc/rhsm/rhsm.conf, we can try to implement: https://issues.redhat.com/browse/RHELC-1036 as doing that will mean we don't have to uninstall the package at all.
  • Update unittests: The removal of several functions will break a of of tests.
  • Add new unittests
  • Check whether rollback needs to have its order changed. Unsubscribing the system happened pretty
    early before while backup_control.pop_all() is run as the last item. We may need to
    pop_all() to be one of the first things run on rollback or even add more of the ad hoc
    rollback functions into the backup framework so that they can be done in a specific order.

Jira Issues: RHELC-1033, RHELC-1036, [RHELC-1006] (https://issues.redhat.com/browse/RHELC-1006)

Checklist

  • PR has been tested manually in a VM (either author or reviewer)
  • Jira issue has been made public if possible
  • [RHELC-] is part of the PR title
  • GitHub label has been added to help with Release notes
  • PR title explains the change from the user's point of view
  • Code and tests are documented properly
  • The commits are squashed to as few commits as possible (without losing data)
  • When merged: Jira issue has been updated to Release Pending if relevant

@abadger abadger added the kind/feature New feature or request label Jul 20, 2023
@abadger abadger marked this pull request as draft July 20, 2023 06:11
@bocekm
Copy link
Member

bocekm commented Jul 26, 2023

Test that a host that is subscribed and has its subscription-manager package removed and then the RHEL versions installed will keep the pre-uninstall registration

# dnf remove subscription-manager
Erasing          : subscription-manager-1.28.36-2.el8.x86_64
warning: /etc/rhsm/rhsm.conf saved as /etc/rhsm/rhsm.conf.rpmsave
# dnf install subscription-manager
# subscription-manager identity
Invalid Credentials (HTTP error code 401: Unauthorized)
# cp /etc/rhsm/rhsm.conf.rpmsave /etc/rhsm/rhsm.conf
# subscription-manager identity
system identity: 102956fb-5b77-4e02-9e81-72e08ee16ade
name: <redacted>.redhat.com
org name: <redacted>
org ID: <redacted>

The registration is retained. Just the conf needs to be restored manually. At least in my case because the conf contained hostname = http://subscription.rhsm.stage.redhat.com/.

Comment on lines 408 to 440
elif not tool_opts.should_subscribe:
loggerinst.warning(
"Ignoring the --serverurl option. It has no effect when no credentials to subscribe the system were given."
)
Copy link
Member

Choose a reason for hiding this comment

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

If we deprecate the no_rhsm option, we will just remove the above statement and use this one?

I'm wondering if it is not easier to merge the two issues right now and remove the no_rhsm option.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I' working on adding norhsm into the mix now, then working on unittests afterthat.

Copy link
Member Author

Choose a reason for hiding this comment

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

So actually, it is --keep-rhsm that is being deprecated, not --no-rhsm. So the above code is still present.

@@ -78,6 +75,29 @@ def set_opts(self, supported_opts):
if value is not None and hasattr(self, key):
setattr(self, key, value)

@property
def should_subscribe(self):
Copy link
Member

Choose a reason for hiding this comment

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

This feels to me that it shouldn't belong here... This feels that it should be placed in the subscription.py module, but, we are using this same property in another part of the toolopts as well, so I'm not sure how to feel about it.

I see how useful the property is here, but still, it feels to be that it should belong to subscription.py, as we are not really taking the CLI option and parsing it to assign with the global toolopts object, but rather, we are saying "take those already defined CLI options and made a decision with it".

Any thoughts? I'm cool to leave the property here, but still, I think I should bring this comment just to make sure there is nothing we can do to move it to a "more appropriate module".

Copy link
Member Author

Choose a reason for hiding this comment

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

I have the same uncertainty as you here. I think asking the question "Should I subscribe" does feel like it should be answered by subscription.py. OTOH, I think that toolopts.py should definitely not import subscription. So I think that leaves us with these choices:

  • Just have the code here and public.
  • Put code which does this check in both toolopts.py (private, just for validating the other arguments) and subscription.py (for public consumption by other code).
  • Put the code into a "utils" module. Note that this would be a separate file from the current utils so that utils can keep the stdlib as its only dependency. (Maybe making utils into a directory and making a subscription module inside of that.) I started down this path so I know it's workable; I backed it out because it is more intrusive

The first of these is what is currently implemented. The last one is my preference if we think this belongs somewhere else.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

The last one is also my preference given the options. I agree that the solution 2 is not anywhere near to be the best one... I wouldn't mind leaving the code as-is, but if you can implement the last option, then I think it would look better for maintainability.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have moved this although I went with a variation on solution 2 that doesn't duplicate the body of the code. I implemented should_subscribe as a private function in toolopts.py so that it can be used there. Then I created a public identifier for should_subscribe in subscription.py which just references the private function with appropriate arguments.

The reason I decided not to do utils isn't technical but maintainability. I couldn't figure out a good way to show people that utils.py only requires the stdlib but subscription_utils.py would require convert2rhel.toolopts. If I named it toolopts_utils.py to signify that it required toolopts, then we would have the same feeling that it belonged in something related to subscriptions, not in something related to toolopts.

@r0x0d
Copy link
Member

r0x0d commented Aug 2, 2023

Not related, but if you can take care of that, would be nice:

https://github.com/abadger/convert2rhel/blob/pr/abadger/869/convert2rhel/subscription.py#L23 not being used

RHSM product certificate. This is the reason that we need to call this function.
"""
cmd = ["subscription-manager", "refresh"]
output, ret_code = utils.run_subprocess(cmd, print_output=True)
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to show the output after executing the command or is it only by debug purposes?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. This is fixed.

Copy link
Member

@r0x0d r0x0d left a comment

Choose a reason for hiding this comment

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

Finished my review, code looks code, but I think it is also good to take another review later, after more modifications.

Couldn't find any problems with the current implementation.

@bocekm bocekm changed the title [RHELC-1033] Make (re)subscribing the system optional [RHELC-1033, RHELC-1036] Make (re)subscribing the system optional Aug 15, 2023
convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/subscription.py Fixed Show fixed Hide fixed
@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Patch coverage: 91.43% and project coverage change: -0.25% ⚠️

Comparison is base (fb6b4a9) 94.34% compared to head (633f22b) 94.10%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #869      +/-   ##
==========================================
- Coverage   94.34%   94.10%   -0.25%     
==========================================
  Files          41       41              
  Lines        4053     4142      +89     
  Branches      715      737      +22     
==========================================
+ Hits         3824     3898      +74     
- Misses        159      173      +14     
- Partials       70       71       +1     
Flag Coverage Δ
centos-linux-7 89.47% <91.43%> (-0.14%) ⬇️
centos-linux-8 90.05% <91.43%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
...nvert2rhel/actions/pre_ponr_changes/transaction.py 100.00% <ø> (ø)
convert2rhel/systeminfo.py 96.89% <ø> (ø)
convert2rhel/backup.py 92.88% <39.13%> (-6.13%) ⬇️
convert2rhel/main.py 89.47% <50.00%> (-2.37%) ⬇️
...vert2rhel/actions/pre_ponr_changes/subscription.py 94.11% <90.00%> (-5.89%) ⬇️
convert2rhel/pkghandler.py 95.27% <98.50%> (+0.35%) ⬆️
...t2rhel/actions/pre_ponr_changes/handle_packages.py 100.00% <100.00%> (ø)
convert2rhel/actions/system_checks/dbus.py 100.00% <100.00%> (ø)
convert2rhel/cert.py 100.00% <100.00%> (+4.54%) ⬆️
convert2rhel/subscription.py 90.48% <100.00%> (+0.54%) ⬆️
... and 1 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/cert.py Fixed Show fixed Hide fixed
convert2rhel/unit_tests/cert_test.py Fixed Show fixed Hide fixed
convert2rhel/unit_tests/cert_test.py Fixed Show fixed Hide fixed
convert2rhel/unit_tests/conftest.py Fixed Show fixed Hide fixed
@abadger abadger marked this pull request as ready for review August 22, 2023 06:13
@abadger abadger force-pushed the subscription-not-needed branch 5 times, most recently from b918127 to 6f70c86 Compare August 22, 2023 09:47
@abadger abadger added need-integration-tests tests/all Run the full test suite. Equivalent to `/packit test`. labels Aug 22, 2023
@has-bot
Copy link
Member

has-bot commented Aug 22, 2023

/packit test


@oamg/conversions-qe please review results and provide ack.

"""
# Check whether any package owns the certificate file. It is
# possible that a new rpm package was installed after we copied the
# certificate into place which owns the certificate. If that is
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# certificate into place which owns the certificate. If that is
# certificate into place which owns the certificate. If that is

@abadger
Copy link
Member Author

abadger commented Sep 6, 2023

I have a fix for the unittest failure. I'm waiting for integration tests before pushing that. (I'll push it at the same time as the fix for integration tests on Oracle7)

@abadger is this the issue that you wanted to fix?

>       assert expected_dependencies == remove_repository_files_packages_instance.dependencies
E       AssertionError: assert ('BACKUP_REDH...P_REPOSITORY') == ('BACKUP_REDHA...SUBSCRIPTION')
E         Right contains one more item: 'PRE_SUBSCRIPTION'
E         Use -v to get the full diff

convert2rhel/unit_tests/actions/pre_ponr_changes/handle_packages_test.py:276: AssertionError

Nope, this is new (I merged all of my unittest fixes already.

A couple notes on this one:

  • It is simple, just need the listed fields in the unittest to mirror the dependencies in the Action
  • When we were porting the checks to Actions, Rodolfo and I discussed whether these sort of tests, which asserts that certain attributes are set to the constants we expect, were appropriate to unittest or if we shouldn't. In the end I tried to google for what other developers thought of it and it seemed like they were adding these sorts of things into their unittests but there wasn't a compelling argument for it. If anyone in convert2rhel has some reasons for or against doing this, we can revisit whether these belong in tests.

loggerinst.critical("The subscription-manager package is not installed correctly.")
if not pkghandler.get_installed_pkg_information("subscription-manager"):
loggerinst.critical(
"The subscription-manager package is not installed correctly. You could try manually installing it before running convert2rhel"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"The subscription-manager package is not installed correctly. You could try manually installing it before running convert2rhel"
"The subscription-manager package is not installed correctly. You could try manually installing it before running convert2rhel"



# subscription is the natural place to look for should_subscribe but it
# is needed by toolopts. So define it as a private function in toolopts but
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# is needed by toolopts. So define it as a private function in toolopts but
# is needed by toolopts. So define it as a private function in toolopts but

@danmyway
Copy link
Member

danmyway commented Sep 6, 2023

/packit test

Signed-off-by: Daniel Diblik <ddiblik@redhat.com>
@danmyway
Copy link
Member

danmyway commented Sep 6, 2023

/packit test

tests/integration/conftest.py Show resolved Hide resolved

# Validate it matches with UUID prior to the conversion
assert original_registration_uuid == post_c2r_registration_uuid
del os.environ["C2R_TESTS_CHECK_RHSM_UUID_MATCH"]
Copy link
Member

Choose a reason for hiding this comment

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

I do not like the fact that we are deleting the environment variable in a function (fixture) that was set outside this function. Due to time limitations, I would keep it as it is, but in the future, I would prefer that we parametrize our fixtures so we do not rely on environment variables. This way we would get rid of all these and just stick with regular parameters of the function. This could be done using the indirect parametrization (https://docs.pytest.org/en/7.1.x/example/parametrize.html#indirect-parametrization)

Copy link
Member

Choose a reason for hiding this comment

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

I agree, with that.
Even asserting for the uuids in the fixture is sketchy considering when the assertion error is raised, the test itself passes, but there is an Error in the fixture teardown.
If you don't mind, please create an issue to cover this @kokesak , thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@danmyway
Copy link
Member

danmyway commented Sep 7, 2023

/packit test

* address review comment
* tweak incomplete_rollback_in_analyze test to not be any action
  dependent, just validate the envar related message

Signed-off-by: Daniel Diblik <ddiblik@redhat.com>
@danmyway
Copy link
Member

danmyway commented Sep 7, 2023

/packit test --labels non-destructive

@danmyway
Copy link
Member

danmyway commented Sep 7, 2023

all destructive tests are have passed previously

+--------------------------------------+-----------------------------+--------------------------------------------------+--------+
| UUID                                 | Target                      | Test Plan                                        | Result |
+--------------------------------------+-----------------------------+--------------------------------------------------+--------+
| c0e597da-c7c1-49f4-b616-e5995f374389 | OL8.8-x86_64-HVM-2023-06-21 |                                                  |        |
|                                      |                             | changed_grub_invalid                             | PASSED |
|                                      |                             | changed_grub_valid                               | PASSED |
|                                      |                             | changed_yum_conf                                 | PASSED |
|                                      |                             | kernel_boot_files_corrupted_initramfs_file       | PASSED |
|                                      |                             | kernel_boot_files_missing_initramfs_and_vmlinuz  | PASSED |
|                                      |                             | language_test                                    | PASSED |
|                                      |                             | missing_os_release                               | PASSED |
|                                      |                             | system_up_to_date                                | PASSED |
| 5015976c-8de9-4663-b041-d98132de13fb | OL7.9-x86_64-HVM-2023-01-05 |                                                  |        |
|                                      |                             | changed_grub_invalid                             | PASSED |
|                                      |                             | changed_grub_valid                               | PASSED |
|                                      |                             | changed_yum_conf                                 | PASSED |
|                                      |                             | kernel_boot_files_corrupted_initramfs_file       | PASSED |
|                                      |                             | kernel_boot_files_missing_initramfs_and_vmlinuz  | PASSED |
|                                      |                             | language_test                                    | PASSED |
|                                      |                             | latest_kernel_check_skip                         | PASSED |
|                                      |                             | missing_os_release                               | PASSED |
|                                      |                             | one_kernel_scenario                              | PASSED |
|                                      |                             | remove_excld_pkgs_epel7                          | PASSED |
|                                      |                             | system_up_to_date                                | PASSED |
| 328c87dd-edac-450b-80ea-32526a4ba035 | CentOS-7-latest             |                                                  |        |
|                                      |                             | changed_grub_invalid                             | PASSED |
|                                      |                             | changed_grub_valid                               | PASSED |
|                                      |                             | changed_yum_conf                                 | PASSED |
|                                      |                             | kernel_boot_files_corrupted_initramfs_file       | PASSED |
|                                      |                             | kernel_boot_files_missing_initramfs_and_vmlinuz  | PASSED |
|                                      |                             | language_test                                    | PASSED |
|                                      |                             | latest_kernel_check_skip                         | PASSED |
|                                      |                             | missing_os_release                               | PASSED |
|                                      |                             | one_kernel_scenario                              | PASSED |
|                                      |                             | remove_excld_pkgs_epel7                          | PASSED |
|                                      |                             | system_up_to_date                                | PASSED |
| 68d9f4d5-f992-4b1d-892e-7d7c86c61b28 | OL8.8-x86_64-HVM-2023-06-21 |                                                  |        |
|                                      |                             | activation_key                                   | PASSED |
|                                      |                             | custom_repos                                     | PASSED |
|                                      |                             | rhsm                                             | PASSED |
|                                      |                             | satellite                                        | PASSED |
|                                      |                             | convert_offline_systems                          | PASSED |
|                                      |                             | resolve_dependency                               | PASSED |
|                                      |                             | single_yum_transaction_check_for_latest_packages | PASSED |
|                                      |                             | single_yum_transaction_mismatch_errors           | PASSED |
|                                      |                             | yum_distro_sync                                  | PASSED |
| 91c68b25-0bdc-45a1-a05c-babe8b0ec069 | CentOS-8-latest             |                                                  |        |
|                                      |                             | activation_key                                   | PASSED |
|                                      |                             | custom_repos                                     | PASSED |
|                                      |                             | pre_registered_system                            | PASSED |
|                                      |                             | rhsm                                             | PASSED |
|                                      |                             | satellite                                        | PASSED |
|                                      |                             | convert_offline_systems                          | PASSED |
|                                      |                             | resolve_dependency                               | PASSED |
|                                      |                             | single_yum_transaction_check_for_latest_packages | PASSED |
|                                      |                             | single_yum_transaction_mismatch_errors           | PASSED |
|                                      |                             | yum_distro_sync                                  | PASSED |
| 43728305-b4a1-493c-a5b5-6f35eaa9b124 | CentOS-8-latest             |                                                  |        |
|                                      |                             | changed_grub_invalid                             | PASSED |
|                                      |                             | changed_grub_valid                               | PASSED |
|                                      |                             | changed_yum_conf                                 | PASSED |
|                                      |                             | config_file                                      | PASSED |
|                                      |                             | kernel-core-only                                 | PASSED |
|                                      |                             | kernel_boot_files_corrupted_initramfs_file       | PASSED |
|                                      |                             | kernel_boot_files_missing_initramfs_and_vmlinuz  | PASSED |
|                                      |                             | language_test                                    | PASSED |
|                                      |                             | missing_os_release                               | PASSED |
|                                      |                             | remove_excld_pkgs_epel8                          | PASSED |
|                                      |                             | removed_pkgs_centos_85                           | PASSED |
|                                      |                             | system_up_to_date                                | PASSED |
| 95e10287-30b7-44bf-8a83-fb7733d046a0 | OL7.9-x86_64-HVM-2023-01-05 |                                                  |        |
|                                      |                             | activation_key                                   | PASSED |
|                                      |                             | custom_repos                                     | PASSED |
|                                      |                             | rhsm                                             | PASSED |
|                                      |                             | satellite                                        | PASSED |
|                                      |                             | resolve_dependency                               | PASSED |
|                                      |                             | single_yum_transaction_all_errors                | PASSED |
|                                      |                             | single_yum_transaction_check_for_latest_packages | PASSED |
|                                      |                             | yum_distro_sync                                  | PASSED |
| 3b0435df-68f6-4037-8e62-b2e68623b2fd | CentOS-7-latest             |                                                  |        |
|                                      |                             | activation_key                                   | PASSED |
|                                      |                             | custom_repos                                     | PASSED |
|                                      |                             | pre_registered_system                            | PASSED |
|                                      |                             | rhsm                                             | PASSED |
|                                      |                             | satellite                                        | PASSED |
|                                      |                             | convert_offline_systems                          | PASSED |
|                                      |                             | resolve_dependency                               | PASSED |
|                                      |                             | single_yum_transaction_check_for_latest_packages | PASSED |
|                                      |                             | single_yum_transaction_excld_pkgs                | PASSED |
|                                      |                             | yum_distro_sync                                  | PASSED |
+--------------------------------------+-----------------------------+--------------------------------------------------+--------+

@bocekm bocekm merged commit 65f7c48 into oamg:main Sep 7, 2023
14 of 24 checks passed
@Venefilyn Venefilyn changed the title [RHELC-1033, RHELC-1036] Make (re-)registering the system optional [RHELC-1033, RHELC-1036] Stop uninstalling subscription-mananager and unregistering the system by default Sep 7, 2023
@abadger abadger deleted the subscription-not-needed branch September 7, 2023 14:13
@abadger abadger changed the title [RHELC-1033, RHELC-1036] Stop uninstalling subscription-mananager and unregistering the system by default [RHELC-1033, RHELC-1036, RHELC-1006] Stop uninstalling subscription-mananager and unregistering the system by default Sep 13, 2023
Andrew-ang9 pushed a commit to Andrew-ang9/convert2rhel that referenced this pull request Oct 10, 2023
…amg#869)

* Make subscription from within convert2rhel optional.

Previously, we would unregister a system if it was registered and then re-register with
subscription-manager.  The only time we didn't do this would be when the user specified --no-rhsm
but that does too much.  It causes convert2rhel to avoid the use of subscription-manager altogether
(it doesn't install the package or configure the RHEL repos) For our purposes, we just don't want to
replace the registration if the system already has one.

The strategy we're implementing here is:
* If the user specifies (username and password) or (activation_key and organization) then
  (re)register the system.
* If not, then attempt to do the conversion without registering the system first.

There are several distinct changes made to enable this functionality:
* subscription.{subscribe_system,rollback}() were moved ito a RestorableChange (called
  RestorableSystemSubscription).  This is mainly because deciding whether to unregister the system
  in case of a rollback now needs to have some saved state to know whether we registered it in the
  first place.
* replace_subscription_manager() no longer unregisters the system as part of uninstalling the
  current subscription-manager packages and installing the RHEL ones.
* A new property was added to toolopts, should_subscribe.  This property tells whether the user has
  specified options which ask us to (re)register the system or not.
* In pre_ponr_changes/subscription.py we now use should_subscribe to decide whether to (re)subscribe
  the system instead of only no_rhsm.  We also use RestorableSystemSubscribe instead of calling
  subscribe_system().
* In main.py we no longer have to call subscription.rollback() because the backup framework
  (backup.backup_control.pop_all()) will take care of rolling back the subscription.
* Reviewed places where tool_opts.no_rhsm was used and change places that were used only to
  subscribe the system (as opposed to installing subscription-manager, which is also used for other
  things) to subscription.should_subscribe() instead:

  * actions.pre_ponr_changes.subscription.PreSubscription: This action makes sure that
    /usr/bin/subscription-manager can run so it needs to run even if we don't subscribe the system.
  * actions.system_checks.dbus.DbusIsRunning: We currently only use DBus as part of subscribing the
    system so should_subscribe is appropriate here.
  * toolopts.CLI: use should_subscribe to tell the user we're ignoring the presence of --serverurl.

* Deprecate --keep-rhsm and use a heuristic to decide whether to register with subscription-manager.

  The heuristic is to check whether the user gave us the necessary credentials to register the system
  with subscription-manager.  If so, then we use rhsm to do so.  If not, then we do not attempt to
  register the system.

  Fixes: https://issues.redhat.com/browse/RHELC-1036

* cert.py:
  * make cert.SystemCert() work with the backup system.  Now it will only install the certificate if
    it isn't already present on the system and only remove the certificate if it was convert2rhel
    which installed it.
  * Give SystemCert the ability to install to different directories.  This allows us to use it for
    both the susbcription-manager product certificate and the yum repo certificate (needed for the
    convert2rhel yum repo).
* main.py: Use the backup system to uninstall the certificates if we rollback instead of making
  a manual call to remove it.
* subscription.py:
  * The RestorableChange for registering and unregistering the system no longer needs to check
    keep_rhsm.  We will always unsubscribe the system if we subsribed it but by default we are no
    longer subscribing it in the first place.
  * Remove replace_subscription_manager() and remove_original_subscription_manager() as we don't
    need anything that uninstalls the subscription-manager package from the vendor anymore.
  * Add detect_subscription_manager() to check whether subscription-manager is installed (the
    entrypoint packages that we need for conversion, basically '*subscription-manager*'.)
  * Move a check for whether subscription-manager packages for RHEL have been downloaded
    successfully from replace_subscription_manager() to install_rhel_subscription_manager().
    This entails calling logger.critical() if the rpms are not present.  In the past, we would fail
    in the same way, just at an earlier stage (in replace[..]() instead of install[..]().
  * Move the installation of the redhat-uep.pem for the yum repos into a pre_ponr_change
    instead of here.  It's graduating from a hack to something that we need to ensure is installed.
    (Remove _check_and_install_redhat_uep_pem()).
  * verify_rhsm_installed(): Remove the keep_rhsm check.  Now, we will always fail at this point if
    verify_rhsm_installed() was called and subscription-manager is not installed.  (The equivalent
    check is now done by the caller)
  * download_rhsm_pkgs(): Do not check for keep_rhsm.  Now, when this is called, we will always
    download the packages.  (The equivalent check is now done by the caller)
* toolopts.py: Remove the keep_rhsm toolopts attribute.  When parsing the CLI, warn if --keep-rhsm
  is passed and ignore the option.
* actions/pre_ponr_changes/subscription.py:
  * Create and action for installing yum repo certs with code migrated from
    subscription._check_and_install_redhat_uep_pem()
  * Move installation of the gpg key from the PreSubscription Action and make both Presubscription
    and pre_ponr_changes.transaction.ValidatePackageManagerTransaction depend on it. (TODO from
    r0x0d)
* Now only download and install subscription-manager if they are not already installed.
* Remove an unused namedtuple import
* Remove unused toolopts.credentials_thru_cli
  When the RegistrationCommand was refactored into a class, we stopped
  needing credentials_thru_cli.  Remove that now.
* Make sure subscription-manager knows about the product certificate.
  Add a function to call subscription-manager refresh.  Use it to make sure subscription-manager
  knows about any RHSM product certificate the user may have put on the system since the last time
  subscription-manager refreshed its cache.

* Add subscription-manager package installation to the backup controller.  This is needed so that the
  packages can be uninstalled after we have unregistered the system during rollback.
  Without this change thte tiing was wrong because:
  * some packages (those which were removed) need to be rolled back early (before file rollbacks
    happen)
  * The packages here (installed subscription-manager packages) need to be rolled back later, after
    unregistering the system.
  * Unregistering the system is now handled by the backup framework and the backup framework
    rollback is a single step.

  Since the backup framework rollback can't exist both before and after the other rollback steps,
  adding the subscription-manager package rollbacks to the framework is the only way to fix this.

* Use get_installed_pkg_information() instead of get_installed_pkg_objects() for
  subscription-manager installation. On RHEL8, those two functions deal with architecture
  specification differently.  Using get_installed_pkg_information everywhere gives the right answer
  on both RHEL7 and RHEL8.

* Make subscription-manager installation work with old versions of deps.

  We are trying to get convert2rhel to only install the subset of subscription-manager packages
  which it requires.  However, when we do have to install packages, we are getting them from the UBI
  repositories where the version of subscription-manager may need a newer vrsion of dependencies
  than the vendor has. For this reason, we may need to install some dependencies from the UBI
  repositories even though the vendor versions of them are already installed.

  Currently, python-syspurpose and json-c are the only problematic packages so make sure that they
  are added to the install set.

  .. seealso:: Bug report illustrating the version problem:
      oamg#494

* syspurpose and jsonc should not be uninstalled on rollback if they were installed to begin with.

  Fix this by sending both packages to install and packages to update to RestorablePackageSet.  When
  we call restore(), packages which were updated are not uninstalled.  (In the future, we could
  backup and restore those packages).

  The PR fixing this in the past was: oamg#393

Co-authored-by: Rodolfo Olivieri <rodolfo.olivieri3@gmail.com>
Co-authored-by: Michal Bocek <mbocek@redhat.com>
Co-authored-by: E Gustavsson <eric@spytec.se>
Co-authored-by: Martin 'kokesak' Litwora <mlitwora@redhat.com>

* Fix for poor error message when a cert has already been removed in rollback.

If something (for instance, package removal) removes a certificate that we installed, then we will
try to reove the cert during rollback but the file won't exist. Add some code to give a nice message
in this case.

Also fix the integration test test_rhsm_error_logged().  It was checking for a prior bad error
message (an exception).  That won't happen in the same circumstance with the new code so adapt it to fit the new reality.

* Hack to fix the order of rollbacks while we still have items that aren't ported to the backup framework.

* Fix package backup on a pre-registered system

When the system is registered to RHSM before running convert2rhel, the
redhat.repo file is not generated because of the missing RHSM product
cert on non-RHEL system. However convert2rhel installs this cert and
when we do a package backup, the subscription-manager yum plugin
generates the redhat.repo file. Having the RHEL repos defined and
enabled during the package backup causes a failure when accessing the
RHEL repos due to the $releasever being different on RHEL and
RHEL-clones. Besides that, when backing up packages we want to
be accessing only the RHEL-clone repos, not RHEL repos.

Also, fix the check whether the packages to be removed have been really
removed. We were comparing strings to objects which led to a false flag
warning that packages that were in fact removed haven't been removed.

Also, update dependencies of a few Actions to make sure:
- we backup system repos before pkg backup because we're
  using the backed up repos for the pkg backups
- we remove pkgs that contain repofiles only after installing
  sub-man pkgs because the sub-man pkg installation may require
  dependencies from the original vendor repos

---------

Signed-off-by: Daniel Diblik <ddiblik@redhat.com>
Co-authored-by: Rodolfo Olivieri <rodolfo.olivieri3@gmail.com>
Co-authored-by: Michal Bocek <mbocek@redhat.com>
Co-authored-by: E Gustavsson <eric@spytec.se>
Co-authored-by: Martin 'kokesak' Litwora <mlitwora@redhat.com>
Co-authored-by: Daniel Diblik <ddiblik@redhat.com>
r0x0d added a commit to r0x0d/convert2rhel that referenced this pull request Feb 12, 2024
The workaround was introduced in oamg#912 and oamg#869, but it is no longer
necessary as all legacy rollback items are now ported to be an instance
tracked by the backup controller.

Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
r0x0d added a commit to r0x0d/convert2rhel that referenced this pull request Feb 22, 2024
The workaround was introduced in oamg#912 and oamg#869, but it is no longer
necessary as all legacy rollback items are now ported to be an instance
tracked by the backup controller.

Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
r0x0d added a commit to r0x0d/convert2rhel that referenced this pull request Feb 28, 2024
The workaround was introduced in oamg#912 and oamg#869, but it is no longer
necessary as all legacy rollback items are now ported to be an instance
tracked by the backup controller.

Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
r0x0d added a commit to r0x0d/convert2rhel that referenced this pull request Mar 6, 2024
The workaround was introduced in oamg#912 and oamg#869, but it is no longer
necessary as all legacy rollback items are now ported to be an instance
tracked by the backup controller.

Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
Venefilyn pushed a commit that referenced this pull request Mar 7, 2024
The workaround was introduced in #912 and #869, but it is no longer
necessary as all legacy rollback items are now ported to be an instance
tracked by the backup controller.

Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
jochapma pushed a commit to jochapma/convert2rhel that referenced this pull request Mar 11, 2024
The workaround was introduced in oamg#912 and oamg#869, but it is no longer
necessary as all legacy rollback items are now ported to be an instance
tracked by the backup controller.

Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request need-integration-tests tests/all Run the full test suite. Equivalent to `/packit test`.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants