mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
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:
parent
63639abb01
commit
9aadd8704a
4 changed files with 37 additions and 20 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue