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

replica-conncheck: improve error msg + logging #276

Closed
wants to merge 2 commits into from

Conversation

tkrizek
Copy link
Contributor

@tkrizek tkrizek commented Nov 28, 2016

Replica conncheck may fail for other reasons then network
misconfiguration. For example, an incorrect admin password might be
provided. Since conncheck is ran as a separate script in quiet mode,
no insightful error message can be displayed.

User is instead pointed to the logs, which were also improved to contain
the usual on screen messages.

https://fedorahosted.org/freeipa/ticket/6497

@stlaz stlaz self-assigned this Nov 28, 2016
print_info("\nThe following list of ports use UDP protocol and would need to be")
print_info("checked manually:")
root_logger.info(("\nThe following list of ports use UDP protocol"
"and would need to be"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the double parentheses are just a typo, right?

print_info("checked manually:")
root_logger.info(("\nThe following list of ports use UDP protocol"
"and would need to be"))
root_logger.info("checked manually:")
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, you can squash this into previous info() call.


# create listeners
print_info("Start listening on required ports for remote master check")
root_logger.info(("Start listening on required ports for remote "
"master check"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Double parentheses again? Is there really some reason to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To join the multiline string.

Copy link
Contributor Author

@tkrizek tkrizek Nov 28, 2016

Choose a reason for hiding this comment

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

And it turns out they are not needed when the string is an argument for a function call :) I'll remove them.

raise RuntimeError((
'Could not SSH to remote host.\n'
'See /var/log/ipareplica-conncheck.log for more '
'information.'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Here as well.

raise RuntimeError("Remote master check failed with following error message(s):\n%s" % stderr)
raise RuntimeError(
("Remote master check failed with following "
"error message(s):\n%s" % stderr))
Copy link
Contributor

Choose a reason for hiding this comment

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

^^

"the listening part after the test."))
root_logger.info("")
root_logger.info(("Please run the following command on "
"remote master:"))
Copy link
Contributor

Choose a reason for hiding this comment

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

^^


print_info("/usr/sbin/ipa-replica-conncheck " + " ".join(remote_check_opts))
root_logger.info("/usr/sbin/ipa-replica-conncheck " +
" ".join(remote_check_opts))
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be merged into the previous message.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, use str.format() here instead of '+'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fiixed

("The following UDP ports could not be verified as open: %s\n"
"This can happen if they are already bound to an application\n"
"and ipa-replica-conncheck cannot attach own UDP responder.")
% ", ".join(str(port.port) for port in ports_udp_warning))
Copy link
Contributor

Choose a reason for hiding this comment

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

NOTE: using str.format() would help you remove the double parentheses here as well but you don't have to do it as the old '%' way is used in most of the other messages here.

for line in result.error_output.splitlines():
print(' %s' % line)
raise RuntimeError('Could not SSH to remote host.')
root_logger.debug(result.error_output)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason not to print the output to stdout as it used to be?

Copy link
Contributor Author

@tkrizek tkrizek Nov 30, 2016

Choose a reason for hiding this comment

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

It is purely a debug information (~50-100 lines), so I don't see the reason why it should be displayed to the user. Since previously the function lacked any reasonable logging, I think it was decided to simply print this debug info out, as the rest of the messages.

Since this patch adds logging to the function, I think the proper place for this information is the log. If the command fails, the user is prompted to check the log (if it fails during replica installation) where he can find this info.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, that's the explanation I was looking for, thanks.

sys.exit(1)
except RuntimeError as e:
sys.exit(e)
root_logger.error('ERROR: ' + str(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use '+' in strings, use str.format().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@stlaz
Copy link
Contributor

stlaz commented Dec 2, 2016

Needs rebase.

Tomas Krizek added 2 commits December 2, 2016 12:28
Replica conncheck may fail for other reasons then network
misconfiguration. For example, an incorrect admin password might be
provided. Since conncheck is ran as a separate script in quiet mode,
no insightful error message can be displayed.

https://fedorahosted.org/freeipa/ticket/6497
Make sure all messages displayed on screen to the user can be found
in the log as well. The messages are also logged if the script is ran
in quiet mode.

https://fedorahosted.org/freeipa/ticket/6497
sys.exit(1)
except RuntimeError as e:
sys.exit(e)
root_logger.error('ERROR: {ex}'.format(ex=e))
Copy link
Contributor

Choose a reason for hiding this comment

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

NOTE: The 'ERROR' prefix was not here before, however it increases awareness that there was an error so I'm fine with keeping it.

@stlaz
Copy link
Contributor

stlaz commented Dec 5, 2016

Seems to work fine, ACK.

@stlaz stlaz added the ack Pull Request approved, can be merged label Dec 5, 2016
@MartinBasti MartinBasti added the pushed Pull Request has already been pushed label Dec 6, 2016
@MartinBasti MartinBasti closed this Dec 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged pushed Pull Request has already been pushed
Projects
None yet
3 participants