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
SDN check: Ignore node's canonical name #9511
SDN check: Ignore node's canonical name #9511
Conversation
@pecameron, could you review this one? |
@@ -169,6 +170,31 @@ def execute_module(module_name, args, *_): | |||
|
|||
SDNCheck(execute_module, task_vars).run() | |||
|
|||
def test_resolve_address(): |
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.
/roles/openshift_health_checker/test/sdn_tests.py:173:1: E302 expected 2 blank lines, found 1
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.
Fixed. Thanks!
''' | ||
} | ||
|
||
return { 'rc': 2 } |
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.
./roles/openshift_health_checker/test/sdn_tests.py:192:17: E201 whitespace after '{'
./roles/openshift_health_checker/test/sdn_tests.py:192:25: E202 whitespace before '}'
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.
Fixed. Thanks!
check = SDNCheck(execute_module, None) | ||
assert check.resolve_address('foo') == '1.2.3.4' | ||
with pytest.raises(OpenShiftCheckException): | ||
check.resolve_address('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.
./roles/openshift_health_checker/test/sdn_tests.py:199:1: E302 expected 2 blank lines, found 1
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.
Fixed. Thanks!
d41c0d2
to
2d36442
Compare
/approve |
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
if command_args[0] != '/bin/getent': | ||
raise ValueError('not expecting command: %s' % args.raw_params) | ||
|
||
# The expected command_args is ['/bin/getent', 'ahosts4', 'foo']. |
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 is in a comment .. but typo ahosts4
aka should be ['/bin/getent', 'ahostsv4', 'foo']
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.
Thanks! Fixed.
/retest |
2d36442
to
eccffcb
Compare
Pushed a fix for the typo in the comment. |
/lgtm |
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
/retest |
2 similar comments
/retest |
/retest |
Looks like a legit failure? https://travis-ci.org/openshift/openshift-ansible/jobs/415525261 |
eccffcb
to
d6bd406
Compare
Pushed a fix for an encoding issue that shows up in Python 3. |
When verifying that a node's preferred host name or address resolves to its internal IP address, ignore the canonical name returned by name resolution. In some valid configurations, the node's preferred name or address differs from the canonical name. This change makes the check more consistent with the behavior of the debug.sh script on which the check was based: https://github.com/openshift/openshift-sdn/blob/d55c72b668018492059a862bee06f11745de1f97/hack/debug.sh#L126 This commit also fixes a problem with string encodings and comparisons that shows up on Python 3. This commit fixes bug 1614261. https://bugzilla.redhat.com/show_bug.cgi?id=1614261 * roles/openshift_health_checker/openshift_checks/sdn.py (SDNCheck.read_command_output): Add an optional parameter for UTF-8 encoding (default True). (SDNCheck.resolve_address): Use read_command_output's new parameter to disable UTF-8 encoding. Ignore canonical name in result. * roles/openshift_health_checker/test/sdn_tests.py (test_resolve_address): New test.
d6bd406
to
0ed00c7
Compare
/retest |
@@ -425,15 +427,15 @@ def resolve_address(self, addr): | |||
"""Look up the given IPv4 address using getent.""" | |||
command = ' '.join(['/bin/getent', 'ahostsv4', addr]) | |||
try: | |||
out = self.read_command_output(command) | |||
out = self.read_command_output(command, False) |
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.
We are passing utf8=False here because we have a test case for resolve_address() that runs on incompatible python version?
This seems fragile instead why not detect if the given string result['stdout'] is encodable and act accordingly?
Something like:
try:
output = result['stdout'].encode('utf-8')
except UnicodeEncodeError:
output = result['stdout']
return output
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.
read_command_output
encodes the output as UTF-8 to avoid problems saving log files containing non-ASCII characters. In Python 2, this encoding presents no problems; UTF-8-encoded strings look like regular strings and behave as expected in comparisons:
>>> 'foo'.encode('utf-8')
'foo'
>>> 'foo'.encode('utf-8') == 'foo'
True
In Python 3, encoding the string into UTF-8 produces a "byte string", which looks and behaves differently:
>>> 'foo'.encode('utf-8')
b'foo'
>>> 'foo'.encode('utf-8') == 'foo'
False
When I tested with Python 2, everything was fine. However, CI tests with both Python 2 and Python 3, and in the latter case, the test reveals that resolve_address
is comparing incompatible string types.
An alternative to adding the utf8
parameter would be to use byte strings in resolve_address
. Python 2 has forwards compatibility so that it accepts the byte-string syntax and treats a byte string as a regular string:
>>> b'foo' == 'foo'
True
So we could use record[1] == b'STREAM'
, and it would make no difference on Python 2 (where the code already works properly) and would fix the problem on Python 3 (where encoding the output as UTF-8 turns it into a byte string). However, I decided to add the utf8
parameter instead because it lets us avoid the weird byte-string syntax and the unnecessary encoding.
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 know the unnecessary encoding is a particularly serious issue in this performance context, but I do like the idea of a named parameter rather than the weird byte-string syntax. Not sure either way is "right" but I don't think it's worth debating over style... let's go ahead and fix the bug.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ironcladlou, Miciah, ramr, vrutkovs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
When verifying that a node's preferred host name or address resolves to its internal IP address, ignore the canonical name returned by name resolution. In some valid configurations, the node's preferred name or address differs from the canonical name.
This change makes the check more consistent with the behavior of the
debug.sh
script on which the check was based.This commit also fixes a problem with string encodings and comparisons that shows up on Python 3.
This commit fixes bug 1614261.
https://bugzilla.redhat.com/show_bug.cgi?id=1614261
roles/openshift_health_checker/openshift_checks/sdn.py
(SDNCheck.read_command_output
): Add an optional parameter for UTF-8 encoding (defaultTrue
).(
SDNCheck.resolve_address
): Useread_command_output
's new parameter to disable UTF-8 encoding. Ignore canonical name in result.roles/openshift_health_checker/test/sdn_tests.py
(test_resolve_address
): New test.