Update bare exceptions to specify Exception.

This will keep us from accidentally catching program-exiting exceptions
like KeyboardInterupt and SystemExit.
This commit is contained in:
Toshio Kuratomi
2018-09-07 17:59:46 -07:00
parent 5147e792d3
commit 3fba006207
320 changed files with 659 additions and 656 deletions

View File

@@ -117,7 +117,7 @@ def validate_ports(module, ports):
if 'port_num' in item:
try:
item['port_num'] = int(item['port_num'])
except:
except Exception:
module.fail_json(msg="port_num entries in the port definitions must be integers")
else:
module.fail_json(msg="port definitions must define the port_num field")

View File

@@ -108,7 +108,7 @@ def validate_ports(module, ports):
if 'port-number' in item:
try:
item['port-number'] = int(item['port-number'])
except:
except Exception:
module.fail_json(msg="port-number entries in the port definitions must be integers")
else:
module.fail_json(msg="port definitions must define the port-number field")

View File

@@ -137,7 +137,7 @@ def validate_servers(module, servers):
if 'port' in item:
try:
item['port'] = int(item['port'])
except:
except Exception:
module.fail_json(msg="server port definitions must be integers")
else:
module.fail_json(msg="server definitions must define the port field")

View File

@@ -119,7 +119,7 @@ def validate_ports(module, ports):
if 'port' in item:
try:
item['port'] = int(item['port'])
except:
except Exception:
module.fail_json(msg="port definitions must be integers")
else:
module.fail_json(msg="port definitions must define the port field")

View File

@@ -242,7 +242,7 @@ import os
try:
from ansible.module_utils.six.moves.urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
HAS_URLPARSE = True
except:
except Exception:
HAS_URLPARSE = False
# Optional, only used for XML payload
@@ -263,7 +263,7 @@ except ImportError:
try:
import yaml
HAS_YAML = True
except:
except Exception:
HAS_YAML = False
from ansible.module_utils.basic import AnsibleModule

View File

@@ -209,7 +209,7 @@ def asn_pool_absent(module, aos, my_pool):
if not module.check_mode:
try:
my_pool.delete()
except:
except Exception:
module.fail_json(msg="An error occurred, while trying to delete the ASN Pool")
module.exit_json(changed=True,
@@ -240,7 +240,7 @@ def asn_pool_present(module, aos, my_pool):
try:
my_new_pool = create_new_asn_pool(my_pool, margs['name'], margs['ranges'])
my_pool = my_new_pool
except:
except Exception:
module.fail_json(msg="An error occurred while trying to create a new ASN Pool ")
module.exit_json(changed=True,
@@ -271,7 +271,7 @@ def asn_pool(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False
@@ -304,7 +304,7 @@ def asn_pool(module):
my_pool = find_collection_item(aos.AsnPools,
item_name=item_name,
item_id=item_id)
except:
except Exception:
module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")
# ----------------------------------------------------

View File

@@ -234,7 +234,7 @@ def aos_blueprint(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False
@@ -253,7 +253,7 @@ def aos_blueprint(module):
my_blueprint = find_collection_item(aos.Blueprints,
item_name=item_name,
item_id=item_id)
except:
except Exception:
module.fail_json(msg="Unable to find the Blueprint based on name or ID, something went wrong")
# ----------------------------------------------------

View File

@@ -207,7 +207,7 @@ def get_collection_from_param_map(module, aos):
try:
param_map = yaml.safe_load(param_map_json)
except:
except Exception:
module.fail_json(msg="Unable to parse param_map information")
else:
@@ -292,7 +292,7 @@ def blueprint_param(module):
# --------------------------------------------------------------------
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
# --------------------------------------------------------------------
@@ -302,7 +302,7 @@ def blueprint_param(module):
blueprint = find_collection_item(aos.Blueprints,
item_name=margs['blueprint'],
item_id=margs['blueprint'])
except:
except Exception:
module.fail_json(msg="Unable to find the Blueprint based on name or ID, something went wrong")
if blueprint.exists is False:

View File

@@ -143,7 +143,7 @@ def blueprint_virtnet(module):
# --------------------------------------------------------------------
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
# --------------------------------------------------------------------
@@ -153,7 +153,7 @@ def blueprint_virtnet(module):
blueprint = find_collection_item(aos.Blueprints,
item_name=margs['blueprint'],
item_id=margs['blueprint'])
except:
except Exception:
module.fail_json(msg="Unable to find the Blueprint based on name or ID, something went wrong")
if blueprint.exists is False:
@@ -181,7 +181,7 @@ def blueprint_virtnet(module):
# --------------------------------------------------------------------
try:
virtnet = blueprint.VirtualNetworks[item_name]
except:
except Exception:
module.fail_json(msg="Something went wrong while trying to find Virtual Network %s in blueprint %s"
% (item_name, blueprint.name))

View File

@@ -150,7 +150,7 @@ def aos_device(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False

View File

@@ -188,7 +188,7 @@ def ext_router_absent(module, aos, my_ext_router):
# Add Sleep before delete to workaround a bug in AOS
time.sleep(2)
my_ext_router.delete()
except:
except Exception:
module.fail_json(msg="An error occurred, while trying to delete the External Router")
module.exit_json(changed=True,
@@ -219,7 +219,7 @@ def ext_router_present(module, aos, my_ext_router):
margs['loopback'],
margs['asn'])
my_ext_router = my_new_ext_router
except:
except Exception:
module.fail_json(msg="An error occurred while trying to create a new External Router")
module.exit_json(changed=True,
@@ -271,7 +271,7 @@ def ext_router(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False
@@ -299,7 +299,7 @@ def ext_router(module):
my_ext_router = find_collection_item(aos.ExternalRouters,
item_name=item_name,
item_id=item_id)
except:
except Exception:
module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")
# ----------------------------------------------------

View File

@@ -218,7 +218,7 @@ def ip_pool_absent(module, aos, my_pool):
if not module.check_mode:
try:
my_pool.delete()
except:
except Exception:
module.fail_json(msg="An error occurred, while trying to delete the IP Pool")
module.exit_json(changed=True,
@@ -240,7 +240,7 @@ def ip_pool_present(module, aos, my_pool):
else:
module.fail_json(msg="Unable to find display_name in 'content', Mandatory")
except:
except Exception:
module.fail_json(msg="Unable to load resource from content, something went wrong")
# if ip_pool doesn't exist already, create a new one
@@ -254,7 +254,7 @@ def ip_pool_present(module, aos, my_pool):
try:
my_new_pool = create_new_ip_pool(my_pool, margs['name'], margs['subnets'])
my_pool = my_new_pool
except:
except Exception:
module.fail_json(msg="An error occurred while trying to create a new IP Pool ")
module.exit_json(changed=True,
@@ -283,7 +283,7 @@ def ip_pool(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False
@@ -311,7 +311,7 @@ def ip_pool(module):
my_pool = find_collection_item(aos.IpPools,
item_name=item_name,
item_id=item_id)
except:
except Exception:
module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")
# ----------------------------------------------------

View File

@@ -158,7 +158,7 @@ def logical_device_absent(module, aos, my_logical_dev):
# Need to way 1sec before a delete to workaround a current limitation in AOS
time.sleep(1)
my_logical_dev.delete()
except:
except Exception:
module.fail_json(msg="An error occurred, while trying to delete the Logical Device")
module.exit_json(changed=True,
@@ -198,7 +198,7 @@ def logical_device(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False

View File

@@ -175,7 +175,7 @@ def logical_device_map_absent(module, aos, my_log_dev_map):
# limitation in AOS
time.sleep(1)
my_log_dev_map.delete()
except:
except Exception:
module.fail_json(msg="An error occurred, while trying to delete the Logical Device Map")
module.exit_json(changed=True,
@@ -217,7 +217,7 @@ def logical_device_map(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False
@@ -245,7 +245,7 @@ def logical_device_map(module):
my_log_dev_map = find_collection_item(aos.LogicalDeviceMaps,
item_name=item_name,
item_id=item_id)
except:
except Exception:
module.fail_json(msg="Unable to find the Logical Device Map based on name or ID, something went wrong")
# ----------------------------------------------------

View File

@@ -155,7 +155,7 @@ def rack_type_absent(module, aos, my_rack_type):
if not module.check_mode:
try:
my_rack_type.delete()
except:
except Exception:
module.fail_json(msg="An error occurred, while trying to delete the Rack Type")
module.exit_json(changed=True,
@@ -195,7 +195,7 @@ def rack_type(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False

View File

@@ -167,7 +167,7 @@ def template_absent(module, aos, my_template):
# need to way 1sec before delete to workaround a current limitation in AOS
time.sleep(1)
my_template.delete()
except:
except Exception:
module.fail_json(msg="An error occurred, while trying to delete the Template")
module.exit_json(changed=True,
@@ -209,7 +209,7 @@ def aos_template(module):
try:
aos = get_aos_session(module, margs['session'])
except:
except Exception:
module.fail_json(msg="Unable to login to the AOS server")
item_name = False
@@ -237,7 +237,7 @@ def aos_template(module):
my_template = find_collection_item(aos.DesignTemplates,
item_name=item_name,
item_id=item_id)
except:
except Exception:
module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")
# ----------------------------------------------------

View File

@@ -115,7 +115,7 @@ def main():
token=api_creds.token, port=api_creds.port)
password_changed = True
return ansible_return(module, None, False, req=data)
except:
except Exception:
pass
if not password_changed:

View File

@@ -285,7 +285,7 @@ class FileCopy(object):
scp = SCPClient(ssh.get_transport())
try:
scp.put(self.local_file, full_remote_path)
except:
except Exception:
time.sleep(10)
file_exists, temp_size = self.remote_file_exists(
dest, self.file_system)

View File

@@ -165,7 +165,7 @@ import os
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -323,7 +323,7 @@ import re
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -109,7 +109,7 @@ import os
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -123,7 +123,7 @@ import os
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -75,7 +75,7 @@ import re
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -130,7 +130,7 @@ import os
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -385,7 +385,7 @@ import re
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -72,7 +72,7 @@ import re
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -166,7 +166,7 @@ import os
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -75,7 +75,7 @@ import re
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -75,7 +75,7 @@ import re
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -95,7 +95,7 @@ import os
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict

View File

@@ -223,7 +223,7 @@ import re
try:
from ansible.module_utils.network.cnos import cnos
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule

View File

@@ -351,14 +351,14 @@ class Interfaces(FactsBase):
try:
intf = self.intf_facts[name]
intf['mediatype'] = mediatype
except:
except Exception:
# fanout
for subport in range(1, 5):
name = "ethernet" + sname + ":" + str(subport)
try:
intf = self.intf_facts[name]
intf['mediatype'] = mediatype
except:
except Exception:
# valid case to handle 2x50G
pass

View File

@@ -195,7 +195,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -204,7 +204,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:

View File

@@ -192,7 +192,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -201,7 +201,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:

View File

@@ -277,7 +277,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -286,7 +286,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:

View File

@@ -476,7 +476,7 @@ def fmgr_fwobj_ipv4(fmg, paramgram):
try:
for member in group_members.split(","):
members.append(member)
except:
except Exception:
pass
datagram["member"] = members
@@ -579,7 +579,7 @@ def fmgr_fwobj_ipv6(fmg, paramgram):
try:
for member in group_members.split(","):
members.append(member)
except:
except Exception:
pass
datagram["member"] = members
@@ -703,7 +703,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -712,7 +712,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:
@@ -791,7 +791,7 @@ def main():
response = fmg.login()
if response[1]['status']['code'] != 0:
module.fail_json(msg="Connection to FortiManager Failed")
except:
except Exception:
module.fail_json(msg="Connection to FortiManager Failed")
else:
# START SESSION LOGIC

View File

@@ -1849,7 +1849,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -1858,7 +1858,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:
@@ -2552,13 +2552,13 @@ def main():
override_data = list()
try:
override_data = module.params[list_variable]
except:
except Exception:
pass
try:
if override_data:
del paramgram[list_variable]
paramgram[list_variable] = override_data
except:
except Exception:
pass
# CHECK IF THE HOST/USERNAME/PW EXISTS, AND IF IT DOES, LOGIN.

View File

@@ -1057,7 +1057,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -1066,7 +1066,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:
@@ -1443,13 +1443,13 @@ def main():
override_data = list()
try:
override_data = module.params[list_variable]
except:
except Exception:
pass
try:
if override_data:
del paramgram[list_variable]
paramgram[list_variable] = override_data
except:
except Exception:
pass
# CHECK IF THE HOST/USERNAME/PW EXISTS, AND IF IT DOES, LOGIN.
@@ -1479,7 +1479,7 @@ def main():
if response[1][0]["policyid"]:
policy_id = response[1][0]["policyid"]
paramgram["policyid"] = policy_id
except:
except Exception:
fmgr_logout(fmg, module, results=response, msg="Couldn't get Policy ID from name, delete failed")
results = fmgr_firewall_policy_addsetdelete(fmg, paramgram)

View File

@@ -230,7 +230,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -239,7 +239,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:
@@ -374,7 +374,7 @@ def main():
if sn_compare == paramgram["fmgr_ha_peer_sn"]:
paramgram["peer_id"] = peer_loopcount
paramgram["next_peer_id"] = paramgram["peer_id"]
except:
except Exception:
pass
# ADVANCE THE LOOP AND REPEAT UNTIL DONE
peer_loopcount += 1

View File

@@ -282,7 +282,7 @@ def fmgr_get_cluster_nodes(fmg, paramgram):
try:
returned_nodes = response[1][0]["ha_slave"]
num_of_nodes = len(returned_nodes)
except:
except Exception:
error_msg = {"cluster_status": "MISSING"}
return error_msg

View File

@@ -770,7 +770,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -779,7 +779,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:
@@ -1056,13 +1056,13 @@ def main():
override_data = list()
try:
override_data = module.params[list_variable]
except:
except Exception:
pass
try:
if override_data:
del paramgram[list_variable]
paramgram[list_variable] = override_data
except:
except Exception:
pass
# CHECK IF THE HOST/USERNAME/PW EXISTS, AND IF IT DOES, LOGIN.

View File

@@ -855,7 +855,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg != "NULL" and len(results) == 0:
try:
fmg.logout()
except:
except Exception:
pass
module.fail_json(msg=msg)
@@ -864,7 +864,7 @@ def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_
if msg == "NULL":
try:
msg = results[1]['status']['message']
except:
except Exception:
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
if results[0] not in good_codes:
@@ -1194,13 +1194,13 @@ def main():
override_data = list()
try:
override_data = module.params[list_variable]
except:
except Exception:
pass
try:
if override_data:
del paramgram[list_variable]
paramgram[list_variable] = override_data
except:
except Exception:
pass
# CHECK IF THE HOST/USERNAME/PW EXISTS, AND IF IT DOES, LOGIN.

View File

@@ -116,7 +116,7 @@ from ansible.module_utils.basic import AnsibleModule
try:
from netaddr import IPNetwork
HAS_NETADDR = True
except:
except Exception:
HAS_NETADDR = False
@@ -169,7 +169,7 @@ def get_formated_ipaddr(input_ip):
else:
ip = IPNetwork(input_ip)
return "%s %s" % (str(ip.ip), str(ip.netmask))
except:
except Exception:
return False
return False

View File

@@ -82,7 +82,7 @@ try:
from pyFG.fortios import logger
from pyFG.exceptions import CommandExecutionException, FailedCommit, ForcedCommit
HAS_PYFG = True
except:
except Exception:
HAS_PYFG = False
@@ -124,7 +124,7 @@ def main():
# connect
try:
f.open()
except:
except Exception:
module.fail_json(msg='Error connecting device')
# get config
@@ -132,7 +132,7 @@ def main():
f.load_config(path=module.params['filter'])
result['running_config'] = f.running_config.to_text()
except:
except Exception:
module.fail_json(msg='Error reading running config')
# backup config
@@ -145,7 +145,7 @@ def main():
try:
conf_str = module.params['src']
f.load_config(in_candidate=True, config_text=conf_str)
except:
except Exception:
module.fail_json(msg="Can't open configuration file, or configuration invalid")
# get updates lines

View File

@@ -400,7 +400,7 @@ def main():
json_resp = jxmlease.parse(resp)
transformed.append(json_resp)
output.append(json_resp)
except:
except Exception:
raise ValueError(resp)
else:
transformed.append(resp)

View File

@@ -242,7 +242,7 @@ def main():
elif display == 'json':
try:
output = jxmlease.parse(xml_resp)
except:
except Exception:
raise ValueError(xml_resp)
elif display == 'pretty':
output = tostring(response, pretty_print=True)

View File

@@ -182,7 +182,7 @@ def get_xml_request(module, request, xmlns, content):
try:
# trying if content contains dict
content = ast.literal_eval(content)
except:
except Exception:
module.fail_json(msg='unsupported content value `%s`' % content)
if isinstance(content, dict):
@@ -246,7 +246,7 @@ def main():
elif display == 'json':
try:
output = jxmlease.parse(xml_resp)
except:
except Exception:
raise ValueError(xml_resp)
elif display == 'pretty':
output = tostring(response, pretty_print=True)

View File

@@ -268,7 +268,7 @@ def transfer_file_to_device(module, dest):
scp = SCPClient(ssh.get_transport())
try:
scp.put(module.params['local_file'], full_remote_path)
except:
except Exception:
time.sleep(10)
temp_size = verify_remote_file_exists(
module, dest, file_system=module.params['file_system'])

View File

@@ -298,7 +298,7 @@ def write_on_file(content, filename, module):
report = open(filepath, 'w')
report.write(content)
report.close()
except:
except Exception:
module.fail_json(msg="Error while writing on file.")
return filepath

View File

@@ -112,7 +112,7 @@ class FactsBase(object):
def run(self, cmd):
try:
return self.module.cli(cmd)[0]
except:
except Exception:
self.failed_commands.append(cmd)

View File

@@ -123,7 +123,7 @@ def main():
while True:
try:
xapi.op(cmd="show jobs all", cmd_xml=True)
except:
except Exception:
pass
else:
jobs = xapi.element_root.findall('.//job')