Fixes prompt doubling issue that impacted missing ios enable password prompts. (#33794)

* Fixes a prompt doubling issue that impacted missing ios enable password prompts.

Due to get_prompt sending a '\n' the prompts became doubled and out-of-sync with what
was expected.  This caused the enable command prompts to be missed.
Also added verification that on_become succeeded to reach enable prompt.

* Moved prompt doubling comment per shippable
pull/33842/merge
bdowling 7 years ago committed by Nathaniel Case
parent 3c0a84349b
commit d59bba4652

@ -69,7 +69,10 @@ class TerminalBase(with_metaclass(ABCMeta, object)):
:returns: A byte string of the prompt :returns: A byte string of the prompt
""" """
self._exec_cli_command(b'\n') # do not send '\n' here, exec_cli_command sends '\r' already,
# doing so causes double prompts.
self._exec_cli_command(b'')
return self._connection._matched_prompt return self._connection._matched_prompt
def on_open_shell(self): def on_open_shell(self):

@ -65,8 +65,12 @@ class TerminalModule(TerminalBase):
try: try:
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict')) self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
prompt = self._get_prompt()
if not prompt.endswith(b'#'):
raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)
except AnsibleConnectionFailure: except AnsibleConnectionFailure:
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode') prompt = self._get_prompt()
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s]' % prompt)
def on_unbecome(self): def on_unbecome(self):
prompt = self._get_prompt() prompt = self._get_prompt()

Loading…
Cancel
Save