-
Notifications
You must be signed in to change notification settings - Fork 70
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
Fixes #39 - raise warning on unread mails #56
Fixes #39 - raise warning on unread mails #56
Conversation
definitions/checks/unread_mail.rb
Outdated
attr_reader :file_path | ||
|
||
def initialize | ||
@file_path = '/var/spool/mail/root' |
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.
Would it be feasible to retrieve mail spool path from site-specific configuration file /etc/login.defs
? This file defines the default path for MAIL_DIR
, and its value differs based on distro.
On Fedora*
[anurag@coruscant ~]$ cat /etc/redhat-release
Fedora release 25 (Twenty Five)
[anurag@coruscant ~]$ grep ^MAIL_DIR /etc/login.defs
MAIL_DIR /var/spool/mail
[anurag@coruscant ~]$
On Debian*
anurag@ellen:~$ cat /etc/debian_version
wheezy/sid
anurag@ellen:~$ grep ^MAIL_DIR /etc/login.defs
MAIL_DIR /var/mail
anurag@ellen:~$
You may want to retain the default value of /var/spool/mail/root
and fallback to it if the above queries fail.
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.
@gnurag,
Thank you for providing information.
I will go through it and fix the code as per your suggestions.
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.
@gnurag ,
Done with the suggested changes.
Instead of hard-coded path, value of MAIL_DIR
is set as a mailbox path.
This value of MAIL_DIR
is retrieved from config file /etc/login.defs
.
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.
LGTM.
definitions/checks/unread_mail.rb
Outdated
end | ||
|
||
def number_of_mails_present | ||
cmd = "egrep '^Message-Id' #{file_path} | wc -l" |
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.
egrep --count
can provide a count of matching lines, without passing the output to wc for counting.
a77cbac
to
30e445b
Compare
f5cc6bd
to
970843c
Compare
definitions/checks/unread_mail.rb
Outdated
def guidline_steps | ||
<<-EOF | ||
Please follow steps manually to clear root mailbox i.e #{file_path}: | ||
1) To read mails use vim or cat for mailbox file |
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.
What about defining this steps into procedures/system_mailbox
and linking to them from the check
in assertion: this would be really nice user experience, if we listed the file for them, as well as allowed them
to delete that file.
2d8143e
to
b22f01f
Compare
I think, there should be a |
b22f01f
to
cab5e4c
Compare
@swapab, If you still think, this change should be needed, please let me know. |
definitions/checks/unread_mail.rb
Outdated
|
||
def run | ||
if file_exists?(file_path) | ||
mails_count = find_mails_count.to_i |
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.
can move to_i
to the method itself.
Method name can be mails_count
.
can keep the check as is. we'll introduce |
cab5e4c
to
aa80b53
Compare
Ready for review. |
aa80b53
to
0c6ad0c
Compare
@@ -15,18 +15,14 @@ class Check < Executable | |||
# the failure, will be offered to the user when running | |||
# in interactive mode | |||
# | |||
# * +:warn* - issue warning instead of failure: this is less strict check, | |||
# that could be considered as non-critical for continuing with the scenario | |||
# * +:error_type* - error type if wants to override failure |
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.
@iNecas , |
@kgaikwad I tried this on my local setup.
I think the key |
0c6ad0c
to
9b26a52
Compare
@swapab , |
9b26a52
to
ba5a302
Compare
@swapab , Sorry for confusion nothing is broken so far :-) I have overridden this method in both procedures. Now, it will show only procedure's description for this check. |
ba5a302
to
ad0adb8
Compare
ad0adb8
to
fee376e
Compare
Pulled new changes from master and updated the PR. |
@kgaikwad Testing against satellite 6.3 on RHEL 7 gives some error on my setup
and also running system-mailbox-list-mailbox stucked (never ends)
|
fee376e
to
76aea88
Compare
@kgaikwad, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
76aea88
to
10a4185
Compare
Whats the motivation behind this? Can we at least add it to the commit message please. |
0679740
to
9b8e044
Compare
@sean797, updated the commit message. @ntkathole , added |
metadata do | ||
label :unread_mail | ||
description "Check for mails in root's mailbox." | ||
tags :unread_mail |
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.
@kgaikwad We are tagging this check with unread_mail...Currently this check won't run before upgrade unless user run it explicitly ( foreman-maintain health check --label unread-mail ). So I think to this need to add in scenario definitions https://github.com/theforeman/foreman_maintain/blob/master/definitions/scenarios/upgrade_to_satellite_6_3.rb#L23
add_step(Checks:::UnreadMail.new)
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.
@ntkathole ,
It's not intended to be a pre/post upgrade checks. That's why tagged as unread_mail
so that any user can run it explicitly whenever required.
end | ||
|
||
private | ||
|
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.
@kgaikwad, would it make sense to make file_path
and mailbox_dir
lazy so that they are evaluated during the run
instead of initialization? I see two advantages there:
- it takes time during scenario execution when there is already something printed out and scenario can start quicker
- if (hypothetically) if file_path is subject of change in some of the previous steps we won't notice
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.
Yes, make sense! And advantages mentioned are legit.
I will do modifications as suggested.
We have many crons, they end up in root mail folder (or file technically). With this commit it will check for unread mails from root's mailbox. If unread mails, provide steps to list & clear mailbox.
9b8e044
to
7030fcf
Compare
@mbacovsky, @ntkathole, |
Looks good! |
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.
Approved: @mbacovsky feel free to merge unless any more comments.
Whats the motivation behind this? I did ask already but it seems the commit message was updated telling me what this commit does (which is useful 👍 ) but the motivation behind why we are doing it would be nice. Right now, I'm thinking why the hell would we want to warn users about unread mails in root's mailbox!!? from |
I think I was brainstorming but the original ticket is no longer accessible probably because folks disabled issues in this repo - don't know the details. I guess it won't hurt to warn user, but the amount of code written to do one-line check is just worrisome :-) If anyone told me in advance we are gonna deliver 100 lines of code for this, I'd say: please no, just close the idea. |
No description provided.