From d6f1bc2ece427c99c42d9b49c91394cba1389ed5 Mon Sep 17 00:00:00 2001 From: carlos roman Date: Wed, 4 Jul 2018 21:16:47 -0500 Subject: [PATCH] Suspend AWS autoscaling process We need to do this to avoid racing conditions --- License2Deploy/rolling_deploy.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/License2Deploy/rolling_deploy.py b/License2Deploy/rolling_deploy.py index fd1314d..321807f 100644 --- a/License2Deploy/rolling_deploy.py +++ b/License2Deploy/rolling_deploy.py @@ -52,6 +52,7 @@ def __init__(self, self.only_new_wait = only_new_wait self.existing_instance_ids = [] self.new_desired_capacity = None + self.sc_proc = ['ReplaceUnhealthy', 'AZRebalance', 'AlarmNotification', 'ScheduledActions'] def get_ami_id_state(self, ami_id): try: @@ -337,6 +338,18 @@ def enable_project_cloudwatch_alarms(self): logging.error("Unable to enable the cloud-watch alarm, please investigate: {0}".format(e)) exit(self.exit_error_code) + def suspend_process(self, group_name): + self.conn_auto.suspend_processes( + AutoScalingGroupName=group_name, + ScalingProcesses=self.sc_proc + ) + + def resume_processes(self, group_name): + self.conn_auto.resume_processes( + AutoScalingGroupName=group_name, + ScalingProcesses=self.sc_proc + ) + def is_redeploy(self): current_reservations = self.get_reservations(self.existing_instance_ids) current_build_numbers = [instance.tags['BUILD'] @@ -361,6 +374,7 @@ def deploy(self): # pragma: no cover self.log_instances_ips(self.existing_instance_ids, group_name) if not self.force_redeploy and self.is_redeploy(): self.stop_deploy('You are attempting to redeploy the same build. Please pass the force_redeploy flag if a redeploy is desired') + self.suspend_process(group_name) self.disable_project_cloudwatch_alarms() self.new_desired_capacity = self.calculate_autoscale_desired_instance_count(group_name, 'increase') self.set_autoscale_instance_desired_count(self.new_desired_capacity, group_name) @@ -369,6 +383,7 @@ def deploy(self): # pragma: no cover self.confirm_lb_has_only_new_instances() self.tag_ami(self.ami_id, self.env) self.enable_project_cloudwatch_alarms() + self.resume_processes(group_name) logging.info("Deployment Complete!") def revert_deployment(self): #pragma: no cover