aws: Handle exceptions while describing metric alarm (#57304)
Handle exceptions raised while describing the metric alarms rather than printing tracebacks. Fixes: #55786 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
78b003858d
commit
0f10c4e8d2
1 changed files with 12 additions and 3 deletions
|
@ -162,6 +162,7 @@ try:
|
|||
except ImportError:
|
||||
pass # Taken care of by ec2.HAS_BOTO
|
||||
|
||||
import traceback
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import (AnsibleAWSError, HAS_BOTO, connect_to_aws, ec2_argument_spec,
|
||||
get_aws_connection_info)
|
||||
|
@ -184,7 +185,11 @@ def create_metric_alarm(connection, module):
|
|||
insufficient_data_actions = module.params.get('insufficient_data_actions')
|
||||
ok_actions = module.params.get('ok_actions')
|
||||
|
||||
alarms = connection.describe_alarms(alarm_names=[name])
|
||||
alarms = None
|
||||
try:
|
||||
alarms = connection.describe_alarms(alarm_names=[name])
|
||||
except BotoServerError as e:
|
||||
module.fail_json(msg="Failed to describe alarm %s: %s" % (name, str(e)), exception=traceback.format_exc())
|
||||
|
||||
if not alarms:
|
||||
|
||||
|
@ -209,7 +214,7 @@ def create_metric_alarm(connection, module):
|
|||
changed = True
|
||||
alarms = connection.describe_alarms(alarm_names=[name])
|
||||
except BotoServerError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
module.fail_json(msg="Failed to create alarm %s: %s" % (name, str(e)), exception=traceback.format_exc())
|
||||
|
||||
else:
|
||||
alarm = alarms[0]
|
||||
|
@ -272,7 +277,11 @@ def create_metric_alarm(connection, module):
|
|||
def delete_metric_alarm(connection, module):
|
||||
name = module.params.get('name')
|
||||
|
||||
alarms = connection.describe_alarms(alarm_names=[name])
|
||||
alarms = None
|
||||
try:
|
||||
alarms = connection.describe_alarms(alarm_names=[name])
|
||||
except BotoServerError as e:
|
||||
module.fail_json(msg="Failed to describe alarm %s: %s" % (name, str(e)), exception=traceback.format_exc())
|
||||
|
||||
if alarms:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue