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

make BECOME-SUCCESS check handle when there is additional output pref… #54562

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
3 participants
@spion06
Copy link

spion06 commented Mar 28, 2019

…ixes

SUMMARY

When executing the reboot module via sudo commands there are cases when text can be prepended before the BECOME-SUCCESS message. For example when using SSSD for authentication and your password is close to expiring the command output will be prefixed with something like Your password will expire in 3 day(s). In my cause this caused the reboot module to incorrectly think that the node has rebooted even though it is still in the process of shutting down.

This PR slightly modifies the _strip_success_message method to use the same regex pattern that is used during the substitution to see if it needs to remove BECOME-SUCCESS. This will only remove the first occurrence of BECOME-SUCCESS but will also match a string before it. The regex is greedy so it won't replace anything past the first match. I also limited the match to the first 100 characters of the string so that the entire string doesn't need to be parsed to determine if the substitution should occur.

I didn't notice any existing unit tests for this but I will add some if requested.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

action

ADDITIONAL INFORMATION
>>> data='\r\nYour password will expire in 2 day(s).\r\nBECOME-SUCCESS-vemijwlktzishirbgrkygkhujthdmosf\r\n\r\n{"chang'
# current pattern
>>> pattern = re.compile(r'^((\r)?\n)?BECOME-SUCCESS.*(\r)?\n')
>>> data='\r\nYour password will expire in 2 day(s).\r\nBECOME-SUCCESS-vemijwlktzishirbgrkygkhujthdmosf\r\n\r\n{"chang'
# current pattern with strip
>>> re.sub(pattern, '', data.strip())
'Your password will expire in 2 day(s).\r\nBECOME-SUCCESS-vemijwlktzishirbgrkygkhujthdmosf\r\n\r\n{"chang'
# current pattern with lstrip
>>> re.sub(pattern, '', data.lstrip())
'Your password will expire in 2 day(s).\r\nBECOME-SUCCESS-vemijwlktzishirbgrkygkhujthdmosf\r\n\r\n{"chang'
# current pattern without strip
>>> re.sub(pattern, '', data)
'\r\nYour password will expire in 2 day(s).\r\nBECOME-SUCCESS-vemijwlktzishirbgrkygkhujthdmosf\r\n\r\n{"chang'

# new pattern
>>> pattern = re.compile(r'^(.*(\r)?\n)?BECOME-SUCCESS.*(\r)?\n')
# new pattern with lstrip
>>> re.sub(pattern, '', data.lstrip())
'\r\n{"chang'
# new pattern without strip
>>> re.sub(pattern, '', data)
'\r\nYour password will expire in 2 day(s).\r\nBECOME-SUCCESS-vemijwlktzishirbgrkygkhujthdmosf\r\n\r\n{"chang'
# new pattern with lstrip and multiple BECOME-SUCCESS strings
>>> re.sub(pattern, '', (data + data).lstrip())
'\r\n{"chang\r\nYour password will expire in 2 day(s).\r\nBECOME-SUCCESS-vemijwlktzishirbgrkygkhujthdmosf\r\n\r\n{"chang'

before: https://gist.github.com/spion06/3b358e20ae447d76a4489d7738bfc16b#file-broken-txt

after: https://gist.github.com/spion06/3b358e20ae447d76a4489d7738bfc16b#file-fixed-txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.