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

View file

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