Commit 7afc1208 authored by Bozhidar Zhelev's avatar Bozhidar Zhelev

final fixes + some more logging verbosity

parent e8f62257
......@@ -74,6 +74,8 @@ class TargetGroup():
asgs_by_status = self.group_asgs_by_status(asgs, self.new_asg)
active_asg = asgs_by_status['active_asg']
inactive_asg = asgs_by_status['inactive_asg']
inactive_asg_name = inactive_asg[0]['AutoScalingGroupName']
active_asg_name = active_asg[0]['AutoScalingGroupName']
logging.debug("switch_asg(): asgs_by_status: {}, active_asg: {}, inactive_asg: {}".format(asgs_by_status, active_asg, inactive_asg))
......@@ -90,6 +92,7 @@ class TargetGroup():
inactive_asg_instances.append(dict(Id=instance['InstanceId']))
# Add the ASG to the target group ARNs
logging.info(f"Attaching the {inactive_asg_name} ASG to the target group...")
try:
for asg in inactive_asg:
asg_client.attach_load_balancer_target_groups(
......@@ -97,23 +100,29 @@ class TargetGroup():
TargetGroupARNs=target_group_arns
)
except Exception as e:
logging.error("Couldn't attach the new ASG {} to the target group {}".format(inactive_asg, target_group_arns))
logging.error(f"Couldn't attach the new {inactive_asg_name} ASG to the {target_group_arns} target group!")
logging.error(e)
# FIXME: Raise an exception.AkinakaCriticalException above instead of catching this
exit(1)
else:
logging.info("Done!")
# Check if the newly attached instances are reported healthy in the target group before detaching the old ASG
try:
elb_waiter.wait(TargetGroupArn=target_group_arns, Targets=inactive_asg_instances)
except Exception as e:
logging.error("One or more instances from the new ASG {} are not InService to the target group {}".format(inactive_asg, target_group_arns))
logging.error(e)
# FIXME: Raise an exception.AkinakaCriticalException above instead of catching this
exit(1)
else:
logging.info("The instances from the {} ASG became InService in the target group.".format(inactive_asg))
logging.info(f"Waiting for the instances from the {inactive_asg_name} ASG to become Healthy targets...")
for tg in target_group_arns:
try:
elb_waiter.wait(TargetGroupArn=tg, Targets=inactive_asg_instances)
except Exception as e:
logging.error("Some of them did not register as Healthy... Check/Detach them manually !!!")
logging.error("Quitting...")
logging.error(e)
# FIXME: Raise an exception.AkinakaCriticalException above instead of catching this
exit(1)
else:
logging.info("Done!")
# Remove the asg from the target group
logging.info(f"Detaching the {active_asg_name} ASG from the target group...")
try:
for asg in active_asg:
asg_client.detach_load_balancer_target_groups(
......@@ -121,9 +130,11 @@ class TargetGroup():
TargetGroupARNs=target_group_arns
)
except Exception as e:
logging.error("Couldn't attach the new ASG {} to the target group {}".format(inactive_asg, target_group_arns))
logging.error(f"Could not detach the old {inactive_asg} ASG from the {target_group_arns} target group!")
logging.error(e)
# FIXME: Raise an exception.AkinakaCriticalException above instead of catching this
exit(1)
else:
logging.info("Done!")
return
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment