Skip to content

Commit

Permalink
route53_info: fix "key error" for health_check operations (ansible-co…
Browse files Browse the repository at this point in the history
…llections#1419)

route53_info: fix "key error" for health_check operations

SUMMARY

Fixes ansible-collections#1396
This pull request

Add new return key health_check_observations for health check operations, returned when I(query=health_check) and I(health_check_method=status) or I(health_check_method=failure_reason)
Fixes "Key Error" when getting status or failure_reason of a health check.


ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

route53_info
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell
Reviewed-by: Mandar Kulkarni <[email protected]>
Reviewed-by: Alina Buzachis
  • Loading branch information
mandar242 authored Mar 17, 2023
1 parent dd31c47 commit a27dfd1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- route53_info - Fixed "Key Error" when getting status or failure_reason of a health check (https://github.com/ansible-collections/amazon.aws/pull/1419).
- route53_info - Add new return key `health_check_observations` for health check operations (https://github.com/ansible-collections/amazon.aws/pull/1419).
60 changes: 49 additions & 11 deletions plugins/modules/route53_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
version_added: 4.1.0
version_added_collection: community.aws
health_check:
description: A dict of Route53 health check details returned by get_health_check_status in boto3.
description: A dict of Route53 health check details returned by get_health_check in boto3.
type: dict
returned: when I(query=health_check) and I(health_check_method=details)
contains:
Expand Down Expand Up @@ -448,6 +448,33 @@
sample: HTTPS
version_added: 4.1.0
version_added_collection: community.aws
health_check_observations:
description: A dict of Route53 health check details returned by get_health_check_status and get_health_check_last_failure_reason in boto3.
type: list
elements: dict
returned: when I(query=health_check) and I(health_check_method=status) or I(health_check_method=failure_reason)
contains:
ip_address:
description: The IP address of the Amazon Route 53 health checker that provided the failure reason in StatusReport.
type: str
sample: '12.345.67.89'
region:
description: The region of the Amazon Route 53 health checker that provided the status in StatusReport.
type: str
sample: 'us-west-1'
status_report:
description: A complex type that contains the last failure reason and the time of the failed health check.
type: dict
contains:
checked_time:
description: The date and time that the health checker performed the health check in ISO 8601 format and Coordinated Universal Time (UTC).
type: str
sample: '2023-03-08T23:10:08.452000+00:00'
status:
description: A description of the status of the health check endpoint as reported by one of the Amazon Route 53 health checkers.
type: str
sample: 'Failure: Resolved IP: 12.345.67.89. The connection was closed by the endpoint.'
version_added: 5.4.0
ResourceRecordSets:
description: A deprecated CamelCased list of resource record sets returned by list_resource_record_sets in boto3. \
This list contains same elements/parameters as it's snake_cased version mentioned above. \
Expand Down Expand Up @@ -484,7 +511,7 @@
elements: dict
returned: when I(query=reusable_delegation_set)
HealthCheck:
description: A deprecated CamelCased dict of Route53 health check details returned by get_health_check_status in boto3. \
description: A deprecated CamelCased dict of Route53 health check details returned by get_health_check in boto3. \
This dict contains same elements/parameters as it's snake_cased version mentioned above. \
This field is deprecated and will be removed in 6.0.0 version release.
type: dict
Expand Down Expand Up @@ -624,6 +651,7 @@ def get_count():

def get_health_check():
params = dict()
results = dict()

if not module.params.get('health_check_id'):
module.fail_json(msg="health_check_id is required")
Expand All @@ -632,16 +660,26 @@ def get_health_check():

if module.params.get('health_check_method') == 'details':
results = client.get_health_check(**params)
results["health_check"] = camel_dict_to_snake_dict(results["HealthCheck"])
module.deprecate(
"The 'CamelCase' return values with key 'HealthCheck' is deprecated \
and will be replaced by 'snake_case' return values with key 'health_check'. \
Both case values are returned for now.",
date="2025-01-01",
collection_name="amazon.aws",
)

elif module.params.get('health_check_method') == 'failure_reason':
results = client.get_health_check_last_failure_reason(**params)
elif module.params.get('health_check_method') == 'status':
results = client.get_health_check_status(**params)
response = client.get_health_check_last_failure_reason(**params)
results["health_check_observations"] = [
camel_dict_to_snake_dict(health_check) for health_check in response["HealthCheckObservations"]
]

results['health_check'] = camel_dict_to_snake_dict(results['HealthCheck'])
module.deprecate("The 'CamelCase' return values with key 'HealthCheck' is deprecated and \
will be replaced by 'snake_case' return values with key 'health_check'. \
Both case values are returned for now.",
date='2025-01-01', collection_name='amazon.aws')
elif module.params.get('health_check_method') == 'status':
response = client.get_health_check_status(**params)
results["health_check_observations"] = [
camel_dict_to_snake_dict(health_check) for health_check in response["HealthCheckObservations"]
]

return results

Expand Down Expand Up @@ -824,7 +862,7 @@ def main():
try:
results = invocations[module.params.get('query')]()
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json(msg=to_native(e))
module.fail_json_aws(e, msg="Query failed")

module.exit_json(**results)

Expand Down
30 changes: 30 additions & 0 deletions tests/integration/targets/route53_health_check/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,36 @@
- create_check is changed
- health_check_info.health_check.health_check_config.measure_latency == true

- pause:
seconds: 20

# test route53_info for health_check_method=status
- name: Get health check status
amazon.aws.route53_info:
query: health_check
health_check_id: "{{ create_check.health_check.id }}"
health_check_method: status
register: health_check_status_info

- assert:
that:
- health_check_status_info is not failed
- '"health_check_observations" in health_check_status_info'

# test route53_info for health_check_method=failure_reason
- name: Get health check failure_reason
amazon.aws.route53_info:
query: health_check
health_check_id: "{{ create_check.health_check.id }}"
health_check_method: failure_reason
register: health_check_failure_reason_info

- assert:
that:
- health_check_failure_reason_info is not failed
- '"health_check_observations" in health_check_failure_reason_info'


- name: 'Update above health check to disable latency graphs - immutable, no change'
route53_health_check:
state: present
Expand Down

0 comments on commit a27dfd1

Please sign in to comment.