Handle multiple sub prompts for network_cli connection (#35361)

* Handle multiple sub prompts for network_cli connection

Fixes #35349

*  Check if the same prompt is repeated in consecutive window
   if it is repeated it indicates there is problem with answer
   provided
*  In that case report error to user

* Fix CI failure

* Fixes #35349

*  Add prompt_retry count to control max number of times
   to expect the same prompt before it error's out

*  Make required changes in ios and eos terminal plugin to handle
   wrong enable password correctly and return proper error
   message to user.

*  Check if the same prompt is repeated in consecutive window
   if it is repeated it indicates there is the problem with an answer
   provided

*  In that case report error to user
This commit is contained in:
Ganesh Nalawade 2018-01-31 18:33:23 +05:30 committed by GitHub
parent 63639abb01
commit 9aadd8704a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 20 deletions

View file

@ -37,6 +37,7 @@ class TerminalModule(TerminalBase):
re.compile(br"% ?Error"),
# re.compile(br"^% \w+", re.M),
re.compile(br"% ?Bad secret"),
re.compile(br"[\r\n%] Bad passwords"),
re.compile(br"invalid input", re.I),
re.compile(br"(?:incomplete|ambiguous) command", re.I),
re.compile(br"connection timed out", re.I),
@ -65,15 +66,15 @@ class TerminalModule(TerminalBase):
# an r string and use to_text to ensure it's text on both py2 and py3.
cmd[u'prompt'] = to_text(r"[\r\n]password: $", errors='surrogate_or_strict')
cmd[u'answer'] = passwd
cmd[u'prompt_retry_check'] = True
try:
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
prompt = self._get_prompt()
if not prompt.endswith(b'#'):
if prompt is None or not prompt.endswith(b'#'):
raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)
except AnsibleConnectionFailure:
except AnsibleConnectionFailure as e:
prompt = self._get_prompt()
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s]' % prompt)
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s] with error: %s' % (prompt, e.message))
def on_unbecome(self):
prompt = self._get_prompt()