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

SDN check: Ignore node's canonical name #9511

Conversation

Miciah
Copy link
Contributor

@Miciah Miciah commented Aug 9, 2018

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 (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.

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 9, 2018
@Miciah
Copy link
Contributor Author

Miciah commented Aug 9, 2018

@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():
Copy link
Member

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

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. Thanks!

'''
}

return { 'rc': 2 }
Copy link
Member

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 '}'

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. Thanks!

check = SDNCheck(execute_module, None)
assert check.resolve_address('foo') == '1.2.3.4'
with pytest.raises(OpenShiftCheckException):
check.resolve_address('baz')

Copy link
Member

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

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. Thanks!

@Miciah Miciah force-pushed the sdn-check-ignore-node's-canonical-name branch from d41c0d2 to 2d36442 Compare August 10, 2018 15:07
@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 10, 2018
@vrutkovs
Copy link
Member

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 10, 2018
Copy link

@ramr ramr left a 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'].
Copy link

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']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Fixed.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2018
@ironcladlou
Copy link
Contributor

/retest

@Miciah Miciah force-pushed the sdn-check-ignore-node's-canonical-name branch from 2d36442 to eccffcb Compare August 13, 2018 16:18
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2018
@Miciah
Copy link
Contributor Author

Miciah commented Aug 13, 2018

Pushed a fix for the typo in the comment.

@ironcladlou
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2018
Copy link

@pravisankar pravisankar left a comment

Choose a reason for hiding this comment

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

LGTM

@ironcladlou
Copy link
Contributor

/retest

2 similar comments
@ironcladlou
Copy link
Contributor

/retest

@ironcladlou
Copy link
Contributor

/retest

@ironcladlou
Copy link
Contributor

Looks like a legit failure? https://travis-ci.org/openshift/openshift-ansible/jobs/415525261

@Miciah Miciah force-pushed the sdn-check-ignore-node's-canonical-name branch from eccffcb to d6bd406 Compare August 15, 2018 20:38
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 15, 2018
@Miciah
Copy link
Contributor Author

Miciah commented Aug 15, 2018

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.
@Miciah Miciah force-pushed the sdn-check-ignore-node's-canonical-name branch from d6bd406 to 0ed00c7 Compare August 15, 2018 20:43
@Miciah
Copy link
Contributor Author

Miciah commented Aug 15, 2018

/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)

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

Copy link
Contributor Author

@Miciah Miciah Aug 16, 2018

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.

Copy link
Contributor

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.

@ironcladlou
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 16, 2018
@openshift-ci-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 03d98d8 into openshift:master Aug 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants