Connection-side, the expection is AnsibleConnectionFailure (#40658)

This commit is contained in:
Nathaniel Case 2018-05-24 09:43:59 -04:00 committed by GitHub
parent 9e2a59885e
commit c04d0ebc23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View file

@ -24,8 +24,8 @@ import time
from itertools import chain
from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.common.utils import to_list
from ansible.plugins.cliconf import CliconfBase, enable_mode
from ansible.plugins.connection.network_cli import Connection as NetworkCli
@ -128,7 +128,12 @@ class Cliconf(CliconfBase):
elif command == 'EOF' and multiline:
multiline = False
try:
out = self.get(command, prompt, answer, multiline)
except AnsibleConnectionFailure as e:
if check_rc:
raise
out = getattr(e, 'err', e)
if out is not None:
try:
@ -152,7 +157,7 @@ class Cliconf(CliconfBase):
try:
self.run_commands(commands)
except ConnectionError:
except AnsibleConnectionFailure:
self.close_session(session)
raise

View file

@ -23,8 +23,8 @@ import json
from itertools import chain
from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes, to_text
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.common.utils import to_list
from ansible.plugins.cliconf import CliconfBase
from ansible.plugins.connection.network_cli import Connection as NetworkCli
@ -115,10 +115,10 @@ class Cliconf(CliconfBase):
try:
out = self.get(cmd)
except ConnectionError as e:
except AnsibleConnectionFailure as e:
if check_rc:
raise
out = e
out = getattr(e, 'err', e)
try:
out = to_text(out, errors='surrogate_or_strict').strip()