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

Roll back Satellite provisioning if subscription attempt fails with e… #3651

Conversation

M4rtinK
Copy link
Contributor

@M4rtinK M4rtinK commented Oct 13, 2021

…rror

Previously Satellite provisioning was only rolled back when the
"Unregister" button has been pressed.

Turns out this is not sufficient, as provisioning happens quite early,
yet the registration and subscription attempt can still end with an
error. The system will then be provisioned for Satellite, but not
registered to it, so no "Unregister" button would be available to
roll back the provisioning.

So instead, make sure Satellite provisioning is always rolled back
if registration to satellite fails in one of tis phases.

And while we are at it refactor the RHSM config dict flattening method
to a function in an utility module and cover all the new and changed
code with unit tests.

Resolves: rhbz#2010865

@pep8speaks
Copy link

pep8speaks commented Oct 13, 2021

Hello @M4rtinK! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-10-20 15:29:53 UTC

@M4rtinK M4rtinK force-pushed the rhel-9-rollback_satellite_provisioning_on_failure branch from dd42b0c to 8958202 Compare October 13, 2021 16:40
@M4rtinK
Copy link
Contributor Author

M4rtinK commented Oct 13, 2021

/kickstart-test --testtype smoke


def nested_dict_test(self):
"""Test the flattening function can handle a nested dict being passed."""
self.assertEqual(flatten_rhsm_nested_dict({"foo": {"bar": "baz"}}), {"foo.bar": "baz"})
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it weird that we have to do this step. Could the RHSM service eventually provide a new API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, its a bit strange that the API is asymmetric like this - that GetAll() returns a nested dict and SetAll() only accepts the flat one. I'll try to ask them about that on one of our future meetings - we might be the only users of the SetAll() API, so I guess they could just change it if they agree with the suggestion.

Copy link
Contributor

@VladimirSlavik VladimirSlavik left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you!

# make the register task throw an exception
register_task.return_value.run_with_signals.side_effect = RegistrationError()
# run the main task, epxect registration error
with self.assertRaises(RegistrationError):
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to use pytest.raises, the self.assert* stuff will eventually go away.

Copy link
Member

Choose a reason for hiding this comment

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

Leave it as it is. I have to take this into account after I'll create switch to pytest on rhel-9 branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leave it as it is. I have to take this into account after I'll create switch to pytest on rhel-9 branch.

ACK

rhsm_register_server_proxy=rhsm_register_server,
organization='foo_org',
activation_keys=['key1', 'key2', 'key3']

Copy link
Contributor

Choose a reason for hiding this comment

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

All register_task calls in this file have an empty line after the parameters. Not sure if that is something to change though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed! Must have been some sort of copy-paste error, lets fix it. :)

Copy link
Member

@jkonecny12 jkonecny12 left a comment

Choose a reason for hiding this comment

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

Please also fix https://github.com/rhinstaller/anaconda/blob/rhel-9/pyanaconda/modules/subscription/runtime.py#L757 docstring in this commit. It's not really related but it makes a bad issues in syntax highlighting and setting a new bug on this would be too cumbersome.

Copy link
Member

@jkonecny12 jkonecny12 left a comment

Choose a reason for hiding this comment

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

None of the below are blockers. Just a notes.

# Red Hat, Inc.
#

def flatten_rhsm_nested_dict(nested_dict):
Copy link
Member

Choose a reason for hiding this comment

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

I'm still thinking if this shouldn't be an object of RHSM configuration with flatten method.

Copy link
Contributor Author

@M4rtinK M4rtinK Oct 18, 2021

Choose a reason for hiding this comment

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

Ideally we can coordinate with RHSM team to have the Set* and Get* methods use the same dictionary format, as suggested by @poncovka , then we don't need any conversion at all.

@@ -1325,7 +1325,9 @@ def provision_system_for_satellite_download_error_test(self, download_task):
@patch("pyanaconda.core.util.restart_service")
@patch("pyanaconda.modules.subscription.runtime.RunSatelliteProvisioningScriptTask")
@patch("pyanaconda.modules.subscription.runtime.DownloadSatelliteProvisioningScriptTask")
def provision_sat_run_error_test(self, download_task, run_script_task, restart_service):
@patch("pyanaconda.modules.subscription.runtime.BackupRHSMConfBeforeSatelliteProvisioningTask")
def provision_sat_run_error_test(self, backup_task, download_task, run_script_task,
Copy link
Member

Choose a reason for hiding this comment

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

I don't much like the sat abbreviation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid sometimes its hard to not hit the line length limits without such shortenings. Also IIRC I've see similar abbreviation being used by the RHSM team, so at least we are consistent. :)

Copy link
Member

Choose a reason for hiding this comment

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

I would really like to have satellite instead of sat here for a few reasons:

  • easy to find in results by grep/search
  • you are using satellite word below in the test names so this is not really consistent with the rest of the change
  • the few characters you will save here won't really help you because even now the parameters are split to two lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, changed. :)

Comment on lines +888 to +897
# Run the task and flatten the returned configuration
# (so that it can be fed to SetAll()) now, so we don't have to do that later.
flat_rhsm_configuration = {}
nested_rhsm_configuration = backup_task.run()
if nested_rhsm_configuration:
flat_rhsm_configuration = flatten_rhsm_nested_dict(nested_rhsm_configuration)
self._config_backup_callback(flat_rhsm_configuration)
# also store a copy in this task, in case we encounter an error and need to roll-back
# when this task is still running
self._rhsm_configuration = flat_rhsm_configuration
Copy link
Member

Choose a reason for hiding this comment

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

I don't like how this method is bigger and bigger. I think it would like a bit more love and abstraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of this is blocked by the payload not yet being modular, but some improvements are planed already for the upstream version, especially related to the unsightly bucket of callbacks we need to pass there at the moment.

@M4rtinK
Copy link
Contributor Author

M4rtinK commented Oct 18, 2021

Please also fix https://github.com/rhinstaller/anaconda/blob/rhel-9/pyanaconda/modules/subscription/runtime.py#L757 docstring in this commit. It's not really related but it makes a bad issues in syntax highlighting and setting a new bug on this would be too cumbersome.

Fixed. :)

@M4rtinK M4rtinK force-pushed the rhel-9-rollback_satellite_provisioning_on_failure branch from 8958202 to d393d92 Compare October 18, 2021 13:55
@M4rtinK
Copy link
Contributor Author

M4rtinK commented Oct 18, 2021

/kickstart-test --testtype smoke

@M4rtinK M4rtinK force-pushed the rhel-9-rollback_satellite_provisioning_on_failure branch from d393d92 to 1f7ffbc Compare October 20, 2021 11:37
@M4rtinK
Copy link
Contributor Author

M4rtinK commented Oct 20, 2021

/kickstart-test --testtype smoke

…rror

Previously Satellite provisioning was only rolled back when the
"Unregister" button has been pressed.

Turns out this is not sufficient, as provisioning happens quite early,
yet the registration and subscription attempt can still end with an
error. The system will then be provisioned for Satellite, but not
registered to it, so no "Unregister" button would be available to
roll back the provisioning.

So instead, make sure Satellite provisioning is always rolled back
if registration to satellite fails in one of tis phases.

And while we are at it refactor the RHSM config dict flattening method
to a function in an utility module and cover all the new and changed
code with unit tests.

Resolves: rhbz#2010865
@M4rtinK M4rtinK force-pushed the rhel-9-rollback_satellite_provisioning_on_failure branch from 1f7ffbc to ccafafc Compare October 20, 2021 15:29
@M4rtinK
Copy link
Contributor Author

M4rtinK commented Oct 20, 2021

/kickstart-test --testtype smoke

Copy link
Member

@jkonecny12 jkonecny12 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@M4rtinK M4rtinK added the ready to merge The PR can be merged. It should have all BZ flags required for releasing set (usually release+). label Oct 25, 2021
@rvykydal rvykydal merged commit b9ee598 into rhinstaller:rhel-9 Nov 2, 2021
@M4rtinK
Copy link
Contributor Author

M4rtinK commented Sep 8, 2022

This can be ported to Fedora only once Satellite support has been ported.

@M4rtinK M4rtinK added the blocked Don't merge this pull request! label Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Don't merge this pull request! port to Fedora ready to merge The PR can be merged. It should have all BZ flags required for releasing set (usually release+). rhel-9
6 participants