Skip to content

Commit

Permalink
Fixed integration test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
GomathiselviS committed Oct 17, 2022
1 parent 7b182f7 commit 7e595ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
33 changes: 12 additions & 21 deletions plugins/modules/cloudwatch_metric_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
you to create an alarm based on the result of a metric math expression.
type: list
required: false
version_added: "5.1.0"
elements: dict
suboptions:
id:
Expand Down Expand Up @@ -144,6 +145,7 @@
description: The percentile statistic for the metric specified in the metric name.
type: str
required: false
version_added: "5.1.0"
comparison:
description:
- Determines how the threshold value is compared
Expand Down Expand Up @@ -310,11 +312,12 @@
except ImportError:
pass # protected by AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import snake_dict_to_camel_dict
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict


def create_metric_alarm(connection, module, params):
alarms = connection.describe_alarms(AlarmNames=[params['AlarmName']])

if params.get('Dimensions'):
if not isinstance(params['Dimensions'], list):
fixed_dimensions = []
Expand Down Expand Up @@ -360,6 +363,11 @@ def create_metric_alarm(connection, module, params):

result = {}
if alarms['MetricAlarms']:
if alarms['MetricAlarms'][0].get('Metrics'):
metric_list = []
for metric_element in alarms['MetricAlarms'][0]['Metrics']:
metric_list.append(camel_dict_to_snake_dict(metric_element))
alarms['MetricAlarms'][0]['Metrics'] = metric_list
result = alarms['MetricAlarms'][0]

module.exit_json(changed=changed,
Expand Down Expand Up @@ -399,19 +407,6 @@ def delete_metric_alarm(connection, module, params):
module.fail_json_aws(e)
else:
module.exit_json(changed=False)

def delete_none_values(params):
"""Delete None values recursively from params"""
if isinstance(params, dict):
for key, value in list(params.items()):
if isinstance(value, (list, dict, tuple, set)):
params[key] = delete_none_values(value)
elif value is None or key is None:
del params[key]
elif isinstance(params, list):
params = [(delete_none_values(item) for item in params if item is not None)]

return params


def main():
Expand Down Expand Up @@ -451,7 +446,7 @@ def main():
['unit', 'metrics'],
['statistic', 'extended_statistic'],
]
#mutually_exclusive = []

module = AnsibleAWSModule(
argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
Expand Down Expand Up @@ -483,14 +478,10 @@ def main():
params['Metrics'].append(snake_dict_to_camel_dict(element, capitalize_first=True))
if module.params.get('extended_statistic'):
params['ExtendedStatistic'] = module.params.get('extended_statistic')

# Remove None value from params
#delete_none_values(params)

for key, value in list(params.items()):
if value is None:
del params[key]



connection = module.client('cloudwatch')

Expand Down
12 changes: 6 additions & 6 deletions tests/integration/targets/cloudwatch_metric_alarm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@
- ec2_instance_metric_alarm_metrics.changed
- ec2_instance_metric_alarm_metrics.alarm_arn
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.stat == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.stat'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.metric.namespace == alarm_info_metrics.metric_alarms[0].nmetrics[0].metric_stat.metric.namespace'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.metric.metric_name == alarm_info_metrics.metric_alarms[0].nmetrics[0].metric_stat.metric.metric_name'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.metric.dimensions[0].name == alarm_info_metrics.metric_alarms[0].nmetrics[0].metric_stat.metric.dimensions[0].name'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.metric.dimensions[0].value == alarm_info_metrics.metric_alarms[0].nmetrics[0].metric_stat.metric.dimensions[0].value'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.id == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.id'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.metric.namespace == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.metric.namespace'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.metric.metric_name == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.metric.metric_name'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.metric.dimensions[0].name == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.metric.dimensions[0].name'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.metric.dimensions[0].value == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.metric.dimensions[0].value'
- 'ec2_instance_metric_alarm_metrics.metrics[0].id == alarm_info_metrics.metric_alarms[0].metrics[0].id'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.period == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.period'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.unit == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.unit'
- 'ec2_instance_metric_alarm_metrics.metrics[0].metric_stat.return_data == alarm_info_metrics.metric_alarms[0].metrics[0].metric_stat.return_data'
- 'ec2_instance_metric_alarm_metrics.metrics[0].return_data == alarm_info_metrics.metric_alarms[0].metrics[0].return_data'


- name: try to remove the alarm
Expand Down

0 comments on commit 7e595ce

Please sign in to comment.