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
Roll back Satellite provisioning if subscription attempt fails with e… #3651
Conversation
dd42b0c
to
8958202
Compare
/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"}) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'] | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
There was a problem hiding this 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.
There was a problem hiding this 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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, changed. :)
# 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Fixed. :) |
8958202
to
d393d92
Compare
/kickstart-test --testtype smoke |
d393d92
to
1f7ffbc
Compare
/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
1f7ffbc
to
ccafafc
Compare
/kickstart-test --testtype smoke |
There was a problem hiding this 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.
This can be ported to Fedora only once Satellite support has been ported. |
…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