From d6fc9f1dfcaf0aedb26dbb4c10197ab0d6793bc7 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 5 May 2014 12:48:45 -0500 Subject: [PATCH] Fixing two bugs in the ec2_elb_lb module * the current state of the ELB was not reflected properly when checking the status after a change was made. * invalid zones caused a traceback when enabling/disabling zones --- library/cloud/ec2_elb_lb | 47 +++++++++++++------ .../roles/test_ec2_elb_lb/tasks/main.yml | 4 +- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/library/cloud/ec2_elb_lb b/library/cloud/ec2_elb_lb index 5de76cb5df..3f2ba40951 100644 --- a/library/cloud/ec2_elb_lb +++ b/library/cloud/ec2_elb_lb @@ -204,32 +204,37 @@ class ElbManager(object): self._delete_elb() def get_info(self): - if not self.elb: + try: + check_elb = self.elb_conn.get_all_load_balancers(self.name)[0] + except: + check_elb = None + + if not check_elb: info = { 'name': self.name, 'status': self.status } else: info = { - 'name': self.elb.name, - 'dns_name': self.elb.dns_name, - 'zones': self.elb.availability_zones, - 'security_group_ids': self.elb.security_groups, + 'name': check_elb.name, + 'dns_name': check_elb.dns_name, + 'zones': check_elb.availability_zones, + 'security_group_ids': check_elb.security_groups, 'status': self.status } - if self.elb.health_check: + if check_elb.health_check: info['health_check'] = { - 'target': self.elb.health_check.target, - 'interval': self.elb.health_check.interval, - 'timeout': self.elb.health_check.timeout, - 'healthy_threshold': self.elb.health_check.healthy_threshold, - 'unhealthy_threshold': self.elb.health_check.unhealthy_threshold, + 'target': check_elb.health_check.target, + 'interval': check_elb.health_check.interval, + 'timeout': check_elb.health_check.timeout, + 'healthy_threshold': check_elb.health_check.healthy_threshold, + 'unhealthy_threshold': check_elb.health_check.unhealthy_threshold, } - if self.elb.listeners: + if check_elb.listeners: info['listeners'] = [l.get_complex_tuple() - for l in self.elb.listeners] + for l in check_elb.listeners] elif self.status == 'created': # When creating a new ELB, listeners don't show in the # immediately returned result, so just include the @@ -366,11 +371,23 @@ class ElbManager(object): return tuple(listener_list) def _enable_zones(self, zones): - self.elb_conn.enable_availability_zones(self.name, zones) + try: + self.elb.enable_zones(zones) + except boto.exception.BotoServerError, e: + if "Invalid Availability Zone" in e.error_message: + 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 def _disable_zones(self, zones): - self.elb_conn.disable_availability_zones(self.name, zones) + try: + self.elb.disable_zones(zones) + except boto.exception.BotoServerError, e: + if "Invalid Availability Zone" in e.error_message: + 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 def _set_zones(self): diff --git a/test/integration/roles/test_ec2_elb_lb/tasks/main.yml b/test/integration/roles/test_ec2_elb_lb/tasks/main.yml index 297bd84196..ba3968a9c2 100644 --- a/test/integration/roles/test_ec2_elb_lb/tasks/main.yml +++ b/test/integration/roles/test_ec2_elb_lb/tasks/main.yml @@ -59,8 +59,8 @@ - 'info.changed' - '"failed" not in info' - 'info.elb.status == "created"' - - 'info.elb.zones[0] == "us-east-1c"' - - 'info.elb.zones[1] == "us-east-1d"' + - '"us-east-1c" in info.elb.zones' + - '"us-east-1d" in info.elb.zones' - 'info.elb.health_check.healthy_threshold == 10' - 'info.elb.health_check.interval == 30' - 'info.elb.health_check.target == "HTTP:80/index.html"'