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

Fix erroneous carriage return character (\r) in the output of remote shell script and command actions #4623

Merged
merged 8 commits into from
Apr 10, 2019

Conversation

Kami
Copy link
Member

@Kami Kami commented Apr 8, 2019

Ladies and gentlemen, long time mystery of "erroneous" carriage return characters sometimes found in stdout and stderr of remote runner actions has finally been solved.

While working on and fixing a totally unrelated issue in StackStorm/st2tests#154, I found our that sometimes \r character ends up in action stdout even though the underlying script only prints \n and not \r\n.

It turns out when pty is used, default terminal option is onlcr which translates \n into \r\n (see https://stackoverflow.com/questions/7812142/how-to-toggle-cr-lf-in-gnu-screen and https://linux.die.net/man/1/stty for details).

This is not desired in our remote actions output (in fact, we had a lot of users report such issues in Slack and similar).

It looks like we already tried to resolve that all the way back in 2015 (eca3751), but our solution / workaround for it wasn't complete. We only removed those characters from the end of the string, but we didn't do anything with \r\n in the middle of the string.

TODO

  • Tests
  • Changelog entry

stdout and stderr data with \n when pty is used.

When pty is used, default behavior is to replace all new line characters
\n with \r\n which is almost never desired.
@Kami
Copy link
Member Author

Kami commented Apr 8, 2019

NOTE: We already have end to end test for it in st2tests repo, which wasn't failing due to the bug in our assertion code in st2tests repo which I fixed here - StackStorm/st2tests#154.

Copy link
Contributor

@m4dcoder m4dcoder left a comment

Choose a reason for hiding this comment

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

Any unit tests?

@Kami
Copy link
Member Author

Kami commented Apr 9, 2019

@m4dcoder Yeah there are unit tests in 56dfa1c and existing end to end tests in st2tests repo (which were not failing due to the bug in the assert function in st2tests repo, but I fixed that there).

output = sanitize_output(input_str, uses_pty=False)
self.assertEqual(expected_output, output)

# 2. pty is used, \r\n should be replaced with \n
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be split out into its own test function?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine either way :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I decided to split it into two methods - 3524e05.

When to split the tests and when not to is not always totally clear - when a test needs to be isolated and potentially also requires on setUp and tearDown method to run then it's clear that such tests need to be separate methods, but in scenarios like that it's less clear / needed.

In general, I do agree with you though - I prefer separate methods since it provides more user-friendly test runner output (and unless setUp / tearDown add a huge overhead then there are really no drawbacks).

@Kami Kami added the runners label Apr 10, 2019
@Kami Kami merged commit 27ec31b into master Apr 10, 2019
@Kami Kami deleted the fix_carriage_return_char branch April 10, 2019 08:58
Kami added a commit to StackStorm/st2docs that referenced this pull request Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants