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
commit 3fba006207
320 changed files with 659 additions and 656 deletions

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")
# ----------------------------------------------------