mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-03 15:10:21 -07:00
Fix ec2_asg exception handling (#25121)
`e.message` is a string, and `camel_dict_to_snake_dict` fails when given a string. The intended code is to run `camel_dict_to_snake_dict` on `e.response`, the result of which includes a `message` key. Make exception handling lines more consistent and wrap for slightly shorter lines.
This commit is contained in:
parent
d958440bcb
commit
5c1a914002
1 changed files with 15 additions and 10 deletions
|
@ -381,9 +381,11 @@ def elb_healthy(asg_connection, elb_connection, module, group_name):
|
||||||
if e.response['Error']['Code'] == 'InvalidInstance':
|
if e.response['Error']['Code'] == 'InvalidInstance':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
module.fail_json(msg="Failed to get load balancer.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
module.fail_json(msg="Failed to get load balancer.",
|
||||||
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
except botocore.exceptions.BotoCoreError as e:
|
except botocore.exceptions.BotoCoreError as e:
|
||||||
module.fail_json(msg="Failed to get load balancer.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.message))
|
module.fail_json(msg="Failed to get load balancer.",
|
||||||
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
|
|
||||||
for i in lb_instances.get('InstanceStates'):
|
for i in lb_instances.get('InstanceStates'):
|
||||||
if i['State'] == "InService":
|
if i['State'] == "InService":
|
||||||
|
@ -413,9 +415,11 @@ def tg_healthy(asg_connection, elbv2_connection, module, group_name):
|
||||||
if e.response['Error']['Code'] == 'InvalidInstance':
|
if e.response['Error']['Code'] == 'InvalidInstance':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
module.fail_json(msg="Failed to get target group.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
module.fail_json(msg="Failed to get target group.",
|
||||||
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
except botocore.exceptions.BotoCoreError as e:
|
except botocore.exceptions.BotoCoreError as e:
|
||||||
module.fail_json(msg="Failed to get target group.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.message))
|
module.fail_json(msg="Failed to get target group.",
|
||||||
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
|
|
||||||
for i in tg_instances.get('TargetHealthDescriptions'):
|
for i in tg_instances.get('TargetHealthDescriptions'):
|
||||||
if i['TargetHealth']['State'] == "healthy":
|
if i['TargetHealth']['State'] == "healthy":
|
||||||
|
@ -605,7 +609,8 @@ def create_autoscaling_group(connection, module):
|
||||||
changed = True
|
changed = True
|
||||||
return changed, asg_properties
|
return changed, asg_properties
|
||||||
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
||||||
module.fail_json(msg="Failed to create Autoscaling Group.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.message))
|
module.fail_json(msg="Failed to create Autoscaling Group.",
|
||||||
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
else:
|
else:
|
||||||
as_group = as_groups['AutoScalingGroups'][0]
|
as_group = as_groups['AutoScalingGroups'][0]
|
||||||
initial_asg_properties = get_properties(as_group)
|
initial_asg_properties = get_properties(as_group)
|
||||||
|
@ -646,7 +651,7 @@ def create_autoscaling_group(connection, module):
|
||||||
)
|
)
|
||||||
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
||||||
module.fail_json(msg="Failed to update Autoscaling Group.",
|
module.fail_json(msg="Failed to update Autoscaling Group.",
|
||||||
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.message))
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
|
|
||||||
# Update load balancers if they are specified and one or more already exists
|
# Update load balancers if they are specified and one or more already exists
|
||||||
elif as_group['LoadBalancerNames']:
|
elif as_group['LoadBalancerNames']:
|
||||||
|
@ -687,7 +692,7 @@ def create_autoscaling_group(connection, module):
|
||||||
)
|
)
|
||||||
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
||||||
module.fail_json(msg="Failed to update Autoscaling Group.",
|
module.fail_json(msg="Failed to update Autoscaling Group.",
|
||||||
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.message))
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
# Update target groups if they are specified and one or more already exists
|
# Update target groups if they are specified and one or more already exists
|
||||||
elif target_group_arns and as_group['TargetGroupARNs']:
|
elif target_group_arns and as_group['TargetGroupARNs']:
|
||||||
# Get differences
|
# Get differences
|
||||||
|
@ -749,7 +754,7 @@ def create_autoscaling_group(connection, module):
|
||||||
)
|
)
|
||||||
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
||||||
module.fail_json(msg="Failed to update Autoscaling Group notifications.",
|
module.fail_json(msg="Failed to update Autoscaling Group notifications.",
|
||||||
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.message))
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
if wait_for_instances:
|
if wait_for_instances:
|
||||||
wait_for_new_inst(module, connection, group_name, wait_timeout, desired_capacity, 'viable_instances')
|
wait_for_new_inst(module, connection, group_name, wait_timeout, desired_capacity, 'viable_instances')
|
||||||
# Wait for ELB health if ELB(s)defined
|
# Wait for ELB health if ELB(s)defined
|
||||||
|
@ -770,7 +775,7 @@ def create_autoscaling_group(connection, module):
|
||||||
changed = True
|
changed = True
|
||||||
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
|
||||||
module.fail_json(msg="Failed to read existing Autoscaling Groups.",
|
module.fail_json(msg="Failed to read existing Autoscaling Groups.",
|
||||||
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.message))
|
exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
return changed, asg_properties
|
return changed, asg_properties
|
||||||
|
|
||||||
|
|
||||||
|
@ -1126,7 +1131,7 @@ def main():
|
||||||
**aws_connect_params)
|
**aws_connect_params)
|
||||||
except (botocore.exceptions.NoCredentialsError, botocore.exceptions.ProfileNotFound) as e:
|
except (botocore.exceptions.NoCredentialsError, botocore.exceptions.ProfileNotFound) as e:
|
||||||
module.fail_json(msg="Can't authorize connection. Check your credentials and profile.",
|
module.fail_json(msg="Can't authorize connection. Check your credentials and profile.",
|
||||||
exceptions=traceback.format_exc(), **camel_dict_to_snake_dict(e.message))
|
exceptions=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
changed = create_changed = replace_changed = False
|
changed = create_changed = replace_changed = False
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue