Exception.message gone in 3.x (#18221)

* Exception.message gone in 3.x
This commit is contained in:
Nathaniel Case 2016-10-28 13:48:16 -04:00 committed by GitHub
parent 0bc35354ce
commit 4a067c3f50
3 changed files with 10 additions and 8 deletions

View file

@ -35,6 +35,7 @@ from ansible.module_utils.network import add_argument, register_transport, to_li
from ansible.module_utils.netcli import Command from ansible.module_utils.netcli import Command
from ansible.module_utils.shell import CliBase from ansible.module_utils.shell import CliBase
from ansible.module_utils.urls import fetch_url, url_argument_spec from ansible.module_utils.urls import fetch_url, url_argument_spec
from ansible.module_utils._text import to_native
EAPI_FORMATS = ['json', 'text'] EAPI_FORMATS = ['json', 'text']
@ -88,7 +89,7 @@ class EosConfigMixin(object):
self.execute(['no configure session %s' % session]) self.execute(['no configure session %s' % session])
except NetworkError: except NetworkError:
exc = get_exception() exc = get_exception()
if 'timeout trying to send command' in exc.message: if 'timeout trying to send command' in to_native(exc):
# try to get control back and get out of config mode # try to get control back and get out of config mode
if isinstance(self, Cli): if isinstance(self, Cli):
self.execute(['\x03', 'end']) self.execute(['\x03', 'end'])

View file

@ -32,6 +32,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import env_fallback, get_exception from ansible.module_utils.basic import env_fallback, get_exception
from ansible.module_utils.netcli import Cli, Command from ansible.module_utils.netcli import Cli, Command
from ansible.module_utils.netcfg import Config from ansible.module_utils.netcfg import Config
from ansible.module_utils._text import to_native
NET_TRANSPORT_ARGS = dict( NET_TRANSPORT_ARGS = dict(
host=dict(required=True), host=dict(required=True),
@ -105,7 +106,7 @@ class NetworkModule(AnsibleModule):
self.fail_json(msg='Unknown transport or no default transport specified') self.fail_json(msg='Unknown transport or no default transport specified')
except (TypeError, NetworkError): except (TypeError, NetworkError):
exc = get_exception() exc = get_exception()
self.fail_json(msg=exc.message) self.fail_json(msg=to_native(exc))
if connect_on_load: if connect_on_load:
self.connect() self.connect()
@ -151,7 +152,7 @@ class NetworkModule(AnsibleModule):
self.params['port'], self.params['transport'])) self.params['port'], self.params['transport']))
except NetworkError: except NetworkError:
exc = get_exception() exc = get_exception()
self.fail_json(msg=exc.message) self.fail_json(msg=to_native(exc))
def disconnect(self): def disconnect(self):
try: try:
@ -160,7 +161,7 @@ class NetworkModule(AnsibleModule):
self.log('disconnected from %s' % self.params['host']) self.log('disconnected from %s' % self.params['host'])
except NetworkError: except NetworkError:
exc = get_exception() exc = get_exception()
self.fail_json(msg=exc.message) self.fail_json(msg=to_native(exc))
def register_transport(transport, default=False): def register_transport(transport, default=False):
def register(cls): def register(cls):

View file

@ -32,6 +32,7 @@ except ImportError:
from ansible.module_utils.basic import get_exception from ansible.module_utils.basic import get_exception
from ansible.module_utils.network import NetworkError from ansible.module_utils.network import NetworkError
from ansible.module_utils.six.moves import StringIO from ansible.module_utils.six.moves import StringIO
from ansible.module_utils._text import to_native
ANSI_RE = [ ANSI_RE = [
re.compile(r'(\x1b\[\?1h\x1b=)'), re.compile(r'(\x1b\[\?1h\x1b=)'),
@ -51,7 +52,6 @@ class ShellError(Exception):
def __init__(self, msg, command=None): def __init__(self, msg, command=None):
super(ShellError, self).__init__(msg) super(ShellError, self).__init__(msg)
self.message = msg
self.command = command self.command = command
@ -155,7 +155,7 @@ class Shell(object):
raise ShellError("timeout trying to send command: %s" % cmd) raise ShellError("timeout trying to send command: %s" % cmd)
except socket.error: except socket.error:
exc = get_exception() exc = get_exception()
raise ShellError("problem sending command to host: %s" % exc.message) raise ShellError("problem sending command to host: %s" % to_native(exc))
return responses return responses
def close(self): def close(self):
@ -228,7 +228,7 @@ class CliBase(object):
except ShellError: except ShellError:
exc = get_exception() exc = get_exception()
raise NetworkError( raise NetworkError(
msg='failed to connect to %s:%s' % (host, port), exc=str(exc) msg='failed to connect to %s:%s' % (host, port), exc=to_native(exc)
) )
self._connected = True self._connected = True
@ -247,7 +247,7 @@ class CliBase(object):
return self.shell.send(commands) return self.shell.send(commands)
except ShellError: except ShellError:
exc = get_exception() exc = get_exception()
raise NetworkError(exc.message, commands=commands) raise NetworkError(to_native(exc), commands=commands)
def run_commands(self, commands): def run_commands(self, commands):
return self.execute(to_list(commands)) return self.execute(to_list(commands))