mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix ec2_elb_lb error handling. (#24183)
- Use `fail_json` for `get_all_load_balancers` unhandled exception. - Do not mask error message on failure of `enable_zones`. - Do not mask error message on failure of `disable_zones`. Also added/removed blank lines to improve PEP 8 compliance.
This commit is contained in:
parent
fbb924ff24
commit
425d35ef0f
1 changed files with 11 additions and 11 deletions
|
@ -403,12 +403,14 @@ except ImportError:
|
||||||
HAS_BOTO = False
|
HAS_BOTO = False
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.ec2 import ec2_argument_spec, connect_to_aws, AnsibleAWSError
|
from ansible.module_utils.ec2 import ec2_argument_spec, connect_to_aws, AnsibleAWSError
|
||||||
from ansible.module_utils.ec2 import get_aws_connection_info
|
from ansible.module_utils.ec2 import get_aws_connection_info
|
||||||
|
|
||||||
|
|
||||||
def _throttleable_operation(max_retries):
|
def _throttleable_operation(max_retries):
|
||||||
def _operation_wrapper(op):
|
def _operation_wrapper(op):
|
||||||
def _do_op(*args, **kwargs):
|
def _do_op(*args, **kwargs):
|
||||||
|
@ -477,7 +479,12 @@ class ElbManager(object):
|
||||||
self.changed = False
|
self.changed = False
|
||||||
self.status = 'gone'
|
self.status = 'gone'
|
||||||
self.elb_conn = self._get_elb_connection()
|
self.elb_conn = self._get_elb_connection()
|
||||||
self.elb = self._get_elb()
|
|
||||||
|
try:
|
||||||
|
self.elb = self._get_elb()
|
||||||
|
except boto.exception.BotoServerError as e:
|
||||||
|
module.fail_json(msg='unable to get all load balancers: %s' % e.message, exception=traceback.format_exc())
|
||||||
|
|
||||||
self.ec2_conn = self._get_ec2_connection()
|
self.ec2_conn = self._get_ec2_connection()
|
||||||
|
|
||||||
@_throttleable_operation(_THROTTLING_RETRIES)
|
@_throttleable_operation(_THROTTLING_RETRIES)
|
||||||
|
@ -832,20 +839,15 @@ class ElbManager(object):
|
||||||
try:
|
try:
|
||||||
self.elb.enable_zones(zones)
|
self.elb.enable_zones(zones)
|
||||||
except boto.exception.BotoServerError as e:
|
except boto.exception.BotoServerError as e:
|
||||||
if "Invalid Availability Zone" in e.error_message:
|
self.module.fail_json(msg='unable to enable zones: %s' % e.message, exception=traceback.format_exc())
|
||||||
self.module.fail_json(msg=e.error_message)
|
|
||||||
else:
|
|
||||||
self.module.fail_json(msg="an unknown server error occurred, please try again later")
|
|
||||||
self.changed = True
|
self.changed = True
|
||||||
|
|
||||||
def _disable_zones(self, zones):
|
def _disable_zones(self, zones):
|
||||||
try:
|
try:
|
||||||
self.elb.disable_zones(zones)
|
self.elb.disable_zones(zones)
|
||||||
except boto.exception.BotoServerError as e:
|
except boto.exception.BotoServerError as e:
|
||||||
if "Invalid Availability Zone" in e.error_message:
|
self.module.fail_json(msg='unable to disable zones: %s' % e.message, exception=traceback.format_exc())
|
||||||
self.module.fail_json(msg=e.error_message)
|
|
||||||
else:
|
|
||||||
self.module.fail_json(msg="an unknown server error occurred, please try again later")
|
|
||||||
self.changed = True
|
self.changed = True
|
||||||
|
|
||||||
def _attach_subnets(self, subnets):
|
def _attach_subnets(self, subnets):
|
||||||
|
@ -1321,7 +1323,6 @@ def main():
|
||||||
except boto.exception.NoAuthHandlerFound as e:
|
except boto.exception.NoAuthHandlerFound as e:
|
||||||
module.fail_json(msg = str(e))
|
module.fail_json(msg = str(e))
|
||||||
|
|
||||||
|
|
||||||
elb_man = ElbManager(module, name, listeners, purge_listeners, zones,
|
elb_man = ElbManager(module, name, listeners, purge_listeners, zones,
|
||||||
purge_zones, security_group_ids, health_check,
|
purge_zones, security_group_ids, health_check,
|
||||||
subnets, purge_subnets, scheme,
|
subnets, purge_subnets, scheme,
|
||||||
|
@ -1331,7 +1332,6 @@ def main():
|
||||||
region=region, instance_ids=instance_ids, purge_instance_ids=purge_instance_ids,
|
region=region, instance_ids=instance_ids, purge_instance_ids=purge_instance_ids,
|
||||||
**aws_connect_params)
|
**aws_connect_params)
|
||||||
|
|
||||||
|
|
||||||
# check for unsupported attributes for this version of boto
|
# check for unsupported attributes for this version of boto
|
||||||
if cross_az_load_balancing and not elb_man._check_attribute_support('cross_zone_load_balancing'):
|
if cross_az_load_balancing and not elb_man._check_attribute_support('cross_zone_load_balancing'):
|
||||||
module.fail_json(msg="You must install boto >= 2.18.0 to use the cross_az_load_balancing attribute")
|
module.fail_json(msg="You must install boto >= 2.18.0 to use the cross_az_load_balancing attribute")
|
||||||
|
|
Loading…
Reference in a new issue