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

restartcheck: fix python 3 bytestring breakage #50757

Merged

Conversation

10ne1
Copy link
Contributor

@10ne1 10ne1 commented Dec 5, 2018

In python 2, bytes is an alias for str and b'foo' == 'foo' so this code
used to work, but in python 3 bytes is a separate type, b'foo' != 'foo'
so pth.startswith() errors because of the type mismatch:

"Passed invalid arguments: startswith first arg must be bytes or a
tuple of bytes, not str."

Fix this by converting bytes to an unicode string so the code works in
both v2 and v3.

Signed-off-by: Ioan-Adrian Ratiu adrian.ratiu@ni.com

What does this PR do?

See above.

What issues does this PR fix or reference?

No github issue: it was found during downstream NILinuxRT testing.

Previous Behavior

Function restartcheck was run only on python 2.

New Behavior

Updated to python 3 and restartcheck broke because of the str/bytes type difference.

Tests written?

No

Commits signed with GPG?

No

In python 2, bytes is an alias for str and b'foo' == 'foo' so this code
used to work, but in python 3 bytes is a separate type, b'foo' != 'foo'
so pth.startswith() errors because of the type mismatch:

"Passed invalid arguments: startswith first arg must be bytes or a
tuple of bytes, not str."

Fix this by converting bytes to an unicode string so the code works in
both v2 and v3.

Signed-off-by: Ioan-Adrian Ratiu <adrian.ratiu@ni.com>
@10ne1 10ne1 force-pushed the dev/aratiu/restartcheck-fix-python3-bytestring branch from a373648 to 9831191 Compare December 5, 2018 13:52
Copy link
Contributor

@rares-pop rares-pop left a comment

Choose a reason for hiding this comment

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

LGTM! BTW - this should be backported in 2018.3 too.

@dwoz dwoz merged commit 1e3d0f0 into saltstack:develop Dec 5, 2018
@10ne1 10ne1 deleted the dev/aratiu/restartcheck-fix-python3-bytestring branch December 6, 2018 11:02
garethgreenaway added a commit to garethgreenaway/salt that referenced this pull request Sep 19, 2019
dwoz added a commit that referenced this pull request Dec 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants