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

Dnf automatic email on error #2005

Conversation

derickdiaz
Copy link
Contributor

The changes implemented in this PR are for: #1918

The changes allows the emitters to invoke when a DNF error occurs. I tested this out by setting the email_via = command_email and command_format = "echo {subject} {body} > /tmp/dnf_error" in the /etc/dnf/automatic.conf file. When I removed by GPG keys from the enabled repositories and run the def-automatic command it created the error file with the error description.

@pep8speaks
Copy link

pep8speaks commented Oct 17, 2023

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

Line 374:59: E711 comparison to None should be 'if cond is not None:'

Comment last updated at 2023-10-27 17:00:30 UTC

@m-blaha
Copy link
Member

m-blaha commented Oct 17, 2023

Please, could you squash the commits? You can keep adding yourself to authors in a separate one.

@derickdiaz derickdiaz force-pushed the dnf-automatic-email-on-error branch from 803d258 to e48f562 Compare October 17, 2023 10:58
@derickdiaz
Copy link
Contributor Author

@m-blaha I squashed all the commits. Unfortunately, adding my name to the author's file was not a separate commit.

@derickdiaz derickdiaz force-pushed the dnf-automatic-email-on-error branch from e48f562 to 14882a9 Compare October 17, 2023 11:02
@m-blaha
Copy link
Member

m-blaha commented Oct 17, 2023

@m-blaha I squashed all the commits. Unfortunately, adding my name to the author's file was not a separate commit.

No worries, it's much better now. Thank you.

Copy link
Member

@jan-kolarik jan-kolarik left a comment

Choose a reason for hiding this comment

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

The changes themselves look good to me. But I am not sure if we want this as the default behavior, meaning sending error reports to all clients, including the existing ones, which will experience a change in behavior. Perhaps we can provide a configuration option, such as send_error_messages? @j-mracek, please what are your thoughts on this?

dnf/automatic/main.py Outdated Show resolved Hide resolved
@@ -367,9 +368,13 @@ def main(args):
exit_code = os.waitstatus_to_exitcode(os.system(conf.commands.reboot_command))
if exit_code != 0:
logger.error('Error: reboot command returned nonzero exit code: %d', exit_code)
emitters.notify_error('Error: reboot command returned nonzero exit code: %d', exit_code)
emitters.commit()
Copy link
Member

Choose a reason for hiding this comment

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

I think that result of calling emitters.commit() multiple times (here and on line#364) will be sending multiple emails. Is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is possible that the emitter would commit twice in the case updated were applied successfully and the reboot command does not work. I could put an else statement and move the emitters.commit() in line 364 within the else statement.

Another problem I see is if a reboot error occurs, the emitter would only show that a reboot was unsuccessful instead of including the updates that were applied.

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 okay with that. Unless I missed something, it means that if there's an issue with rebooting, it will send an extra error email. This happens only if the user has enabled send_error_messages, which is not the default setting.

@@ -72,14 +78,20 @@ def notify_downloaded(self):
assert self._available_msg
self._downloaded = True

def notify_error(self, msg):
self._error = True
self._error_msg = msg
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have error == True, but no message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily. It's possible to leave an empty string as the msg variable; however, when the _prepare_msg function is called, "An error has occurred on <system_name>" will be the first thing on the error message before appending the body. If needed, I can add a default value to self._error_msg but it would be a generic error message.

@j-mracek
Copy link
Contributor

The changes themselves look good to me. But I am not sure if we want this as the default behavior, meaning sending error reports to all clients, including the existing ones, which will experience a change in behavior. Perhaps we can provide a configuration option, such as send_error_messages? @j-mracek, please what are your thoughts on this?

Yes, such a change in stable might be a problem. I think it could be covered by configuration option and configuration might be modified for particular downstream, or the patch might be reverted in stable downstreams and only delivered to rawhide. According to your comment it looks like that the configuration should be used only temporary. But what's you @jan-kolarik preferences as a release master?

@jan-kolarik
Copy link
Member

The changes themselves look good to me. But I am not sure if we want this as the default behavior, meaning sending error reports to all clients, including the existing ones, which will experience a change in behavior. Perhaps we can provide a configuration option, such as send_error_messages? @j-mracek, please what are your thoughts on this?

Yes, such a change in stable might be a problem. I think it could be covered by configuration option and configuration might be modified for particular downstream, or the patch might be reverted in stable downstreams and only delivered to rawhide. According to your comment it looks like that the configuration should be used only temporary. But what's you @jan-kolarik preferences as a release master?

It makes more sense to me not to have it enabled by default and allow users to enable this feature from the configuration. The reason is that DNF Automatic has been available for several years, and as far as I know, there haven't been any requests for such a feature. I consider it more of a 'nice-to-have' option. Additionally, existing users would not be affected.

@derickdiaz derickdiaz force-pushed the dnf-automatic-email-on-error branch from a89c07a to 7c3cf97 Compare October 19, 2023 10:48
doc/automatic.rst Outdated Show resolved Hide resolved
@jan-kolarik
Copy link
Member

LGTM, just please fix that typo in the man pages. We can merge it then if no one is against it. 🙂

@jan-kolarik jan-kolarik merged commit 6229c1d into rpm-software-management:master Nov 15, 2023
3 checks passed
@derickdiaz derickdiaz deleted the dnf-automatic-email-on-error branch November 15, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants