diff --git a/lib/ansible/modules/network/junos/junos_scp.py b/lib/ansible/modules/network/junos/junos_scp.py index 4d6b880ce7..e03f71aafa 100644 --- a/lib/ansible/modules/network/junos/junos_scp.py +++ b/lib/ansible/modules/network/junos/junos_scp.py @@ -86,7 +86,7 @@ changed: """ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.junos.junos import junos_argument_spec, get_param -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native try: from jnpr.junos import Device @@ -117,9 +117,8 @@ def connect(module): device = Device(host, **kwargs) device.open() device.timeout = get_param(module, 'timeout') or 10 - except ConnectError: - exc = get_exception() - module.fail_json('unable to connect to %s: %s' % (host, str(exc))) + except ConnectError as exc: + module.fail_json('unable to connect to %s: %s' % (host, to_native(exc))) return device @@ -158,7 +157,7 @@ def main(): if not HAS_PYEZ: module.fail_json( msg='junos-eznc is required but does not appear to be installed. ' - 'It can be installed using `pip install junos-eznc`' + 'It can be installed using `pip install junos-eznc`' ) result = dict(changed=True) @@ -170,7 +169,7 @@ def main(): transfer_files(module, device) except Exception as ex: module.fail_json( - msg=str(ex) + msg=to_native(ex) ) finally: try: diff --git a/lib/ansible/modules/network/panos/panos_query_rules.py b/lib/ansible/modules/network/panos/panos_query_rules.py index c52636c414..294bf6b2ce 100644 --- a/lib/ansible/modules/network/panos/panos_query_rules.py +++ b/lib/ansible/modules/network/panos/panos_query_rules.py @@ -142,7 +142,6 @@ RETURN = ''' ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.basic import get_exception try: import pan.xapi diff --git a/test/sanity/code-smell/no-get-exception.sh b/test/sanity/code-smell/no-get-exception.sh index d6e56e6a6d..ba6448ec25 100755 --- a/test/sanity/code-smell/no-get-exception.sh +++ b/test/sanity/code-smell/no-get-exception.sh @@ -7,27 +7,11 @@ get_exception=$(find . -path ./test/runner/.tox -prune \ -o -path ./lib/ansible/module_utils/pycompat24.py -prune \ -o -path ./lib/ansible/module_utils/basic.py -prune \ - -o -path ./lib/ansible/modules/storage/netapp -prune \ - -o -path ./lib/ansible/modules/packaging/os/apt.py -prune \ - -o -path ./lib/ansible/modules/packaging/os/apt_repository.py -prune \ - -o -path ./lib/ansible/modules/packaging/os/yum_repository.py -prune \ -o -path ./lib/ansible/modules/network/panos -prune \ -o -path ./lib/ansible/modules/network/junos/junos_facts.py -prune \ - -o -path ./lib/ansible/modules/network/junos/junos_scp.py -prune \ -o -path ./lib/ansible/modules/network/junos/junos_package.py -prune \ - -o -path ./lib/ansible/modules/network/vyos/vyos_command.py -prune \ - -o -path ./lib/ansible/modules/network/fortios/fortios_address.py -prune \ -o -path ./lib/ansible/modules/network/cloudengine/ce_file_copy.py -prune \ - -o -path ./lib/ansible/modules/network/aos/aos_blueprint_param.py -prune \ - -o -path ./lib/ansible/modules/network/aos/aos_blueprint.py -prune \ - -o -path ./lib/ansible/modules/network/aos/aos_blueprint_virtnet.py -prune \ - -o -path ./lib/ansible/modules/network/eos/eos_command.py -prune \ - -o -path ./lib/ansible/modules/files/xattr.py -prune \ - -o -path ./lib/ansible/modules/files/acl.py -prune \ -o -path ./lib/ansible/modules/system -prune \ - -o -path ./lib/ansible/modules/web_infrastructure/jenkins_plugin.py -prune \ - -o -path ./lib/ansible/modules/web_infrastructure/taiga_issue.py -prune \ - -o -path ./lib/ansible/modules/web_infrastructure/htpasswd.py -prune \ -o -name '*.py' -type f -exec grep -H 'get_exception' '{}' '+') basic_failed=0