Don't raise or catch StandardError in amazon modules

reviewable/pr18780/r1
Toshio Kuratomi 9 years ago
parent 60dd37d15f
commit 3c4f954f0f

@ -268,8 +268,7 @@ def main():
try: try:
connection = connect_to_aws(boto.dynamodb2, region, **aws_connect_params) connection = connect_to_aws(boto.dynamodb2, region, **aws_connect_params)
except (NoAuthHandlerFound, AnsibleAWSError), e:
except (NoAuthHandlerFound, StandardError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
state = module.params.get('state') state = module.params.get('state')

@ -184,7 +184,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.ec2.elb, region, **aws_connect_params) connection = connect_to_aws(boto.ec2.elb, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")
@ -194,4 +194,5 @@ def main():
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import * from ansible.module_utils.ec2 import *
if __name__ == '__main__':
main() main()

@ -195,9 +195,6 @@ def create_eni(connection, module):
instance_id = module.params.get("instance_id") instance_id = module.params.get("instance_id")
if instance_id == 'None': if instance_id == 'None':
instance_id = None instance_id = None
do_detach = True
else:
do_detach = False
device_index = module.params.get("device_index") device_index = module.params.get("device_index")
subnet_id = module.params.get('subnet_id') subnet_id = module.params.get('subnet_id')
private_ip_address = module.params.get('private_ip_address') private_ip_address = module.params.get('private_ip_address')
@ -212,7 +209,7 @@ def create_eni(connection, module):
if instance_id is not None: if instance_id is not None:
try: try:
eni.attach(instance_id, device_index) eni.attach(instance_id, device_index)
except BotoServerError as ex: except BotoServerError:
eni.delete() eni.delete()
raise raise
# Wait to allow creation / attachment to finish # Wait to allow creation / attachment to finish
@ -236,8 +233,6 @@ def modify_eni(connection, module):
else: else:
do_detach = False do_detach = False
device_index = module.params.get("device_index") device_index = module.params.get("device_index")
subnet_id = module.params.get('subnet_id')
private_ip_address = module.params.get('private_ip_address')
description = module.params.get('description') description = module.params.get('description')
security_groups = module.params.get('security_groups') security_groups = module.params.get('security_groups')
force_detach = module.params.get("force_detach") force_detach = module.params.get("force_detach")
@ -245,7 +240,6 @@ def modify_eni(connection, module):
delete_on_termination = module.params.get("delete_on_termination") delete_on_termination = module.params.get("delete_on_termination")
changed = False changed = False
try: try:
# Get the eni with the eni_id specified # Get the eni with the eni_id specified
eni_result_set = connection.get_all_network_interfaces(eni_id) eni_result_set = connection.get_all_network_interfaces(eni_id)
@ -376,7 +370,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.ec2, region, **aws_connect_params) connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")
@ -403,4 +397,5 @@ from ansible.module_utils.ec2 import *
# this is magic, see lib/ansible/module_common.py # this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>> #<<INCLUDE_ANSIBLE_MODULE_COMMON>>
if __name__ == '__main__':
main() main()

@ -113,7 +113,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.ec2, region, **aws_connect_params) connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")

@ -154,7 +154,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.ec2, region, **aws_connect_params) connection = connect_to_aws(boto.ec2, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")
@ -167,4 +167,3 @@ from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

@ -134,7 +134,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.vpc, region, **aws_connect_params) connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")

@ -571,7 +571,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.vpc, region, **aws_connect_params) connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")
@ -598,4 +598,3 @@ from ansible.module_utils.ec2 import * # noqa
if __name__ == '__main__': if __name__ == '__main__':
main() main()

@ -111,7 +111,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.vpc, region, **aws_connect_params) connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")

@ -242,7 +242,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.vpc, region, **aws_connect_params) connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")
@ -270,4 +270,3 @@ from ansible.module_utils.ec2 import * # noqa
if __name__ == '__main__': if __name__ == '__main__':
main() main()

@ -111,7 +111,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.vpc, region, **aws_connect_params) connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")

@ -25,7 +25,7 @@ description:
- Creates or terminates ecs clusters. - Creates or terminates ecs clusters.
version_added: "2.0" version_added: "2.0"
author: Mark Chance(@Java1Guy) author: Mark Chance(@Java1Guy)
requirements: [ json, time, boto, boto3 ] requirements: [ boto, boto3 ]
options: options:
state: state:
description: description:
@ -100,8 +100,9 @@ status:
returned: ACTIVE returned: ACTIVE
type: string type: string
''' '''
import time
try: try:
import json, time
import boto import boto
HAS_BOTO = True HAS_BOTO = True
except ImportError: except ImportError:
@ -147,7 +148,7 @@ class EcsClusterManager:
c = self.find_in_array(response['clusters'], cluster_name) c = self.find_in_array(response['clusters'], cluster_name)
if c: if c:
return c return c
raise StandardError("Unknown problem describing cluster %s." % cluster_name) raise Exception("Unknown problem describing cluster %s." % cluster_name)
def create_cluster(self, clusterName = 'default'): def create_cluster(self, clusterName = 'default'):
response = self.ecs.create_cluster(clusterName=clusterName) response = self.ecs.create_cluster(clusterName=clusterName)
@ -175,8 +176,6 @@ def main():
if not HAS_BOTO3: if not HAS_BOTO3:
module.fail_json(msg='boto3 is required.') module.fail_json(msg='boto3 is required.')
cluster_name = module.params['name']
cluster_mgr = EcsClusterManager(module) cluster_mgr = EcsClusterManager(module)
try: try:
existing = cluster_mgr.describe_cluster(module.params['name']) existing = cluster_mgr.describe_cluster(module.params['name'])

@ -324,7 +324,6 @@ def destroy_lifecycle_rule(connection, module):
else: else:
lifecycle_obj.append(existing_rule) lifecycle_obj.append(existing_rule)
# Write lifecycle to bucket or, if there no rules left, delete lifecycle configuration # Write lifecycle to bucket or, if there no rules left, delete lifecycle configuration
try: try:
if lifecycle_obj: if lifecycle_obj:
@ -385,7 +384,7 @@ def main():
# use this as fallback because connect_to_region seems to fail in boto + non 'classic' aws accounts in some cases # use this as fallback because connect_to_region seems to fail in boto + non 'classic' aws accounts in some cases
if connection is None: if connection is None:
connection = boto.connect_s3(**aws_connect_params) connection = boto.connect_s3(**aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
expiration_date = module.params.get("expiration_date") expiration_date = module.params.get("expiration_date")

@ -162,10 +162,9 @@ def main():
# use this as fallback because connect_to_region seems to fail in boto + non 'classic' aws accounts in some cases # use this as fallback because connect_to_region seems to fail in boto + non 'classic' aws accounts in some cases
if connection is None: if connection is None:
connection = boto.connect_s3(**aws_connect_params) connection = boto.connect_s3(**aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
state = module.params.get("state") state = module.params.get("state")
if state == 'present': if state == 'present':

@ -216,7 +216,7 @@ def main():
try: try:
connection = connect_to_aws(boto.sqs, region, **aws_connect_params) connection = connect_to_aws(boto.sqs, region, **aws_connect_params)
except (NoAuthHandlerFound, StandardError), e: except (NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
state = module.params.get('state') state = module.params.get('state')
@ -230,4 +230,5 @@ def main():
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import * from ansible.module_utils.ec2 import *
if __name__ == '__main__':
main() main()

@ -84,9 +84,6 @@ ec2_tag:
''' '''
import sys
import time
try: try:
import boto.sts import boto.sts
from boto.exception import BotoServerError from boto.exception import BotoServerError
@ -138,7 +135,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.sts, region, **aws_connect_params) connection = connect_to_aws(boto.sts, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")
@ -153,4 +150,5 @@ def main():
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import * from ansible.module_utils.ec2 import *
if __name__ == '__main__':
main() main()

Loading…
Cancel
Save