From 2edded25b216e0c160b6c2b60e1c95d0ddc29b08 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Mon, 3 Nov 2014 15:27:44 +0800 Subject: [PATCH] Correct validation for timeout when rolling update Using effective capacity not the current capacity to calculate whether the update action will in result timeout. Change-Id: I718e19c197efa5ca3add270a7470ed26e0f705db Closes-Bug: #1388695 --- heat/engine/resources/autoscaling.py | 12 ++++++------ heat/tests/test_autoscaling_update_policy.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 3d080ff45..b04f7e705 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -368,14 +368,13 @@ class InstanceGroup(stack_resource.StackResource): efft_bat_sz = min(batch_size, capacity) efft_min_sz = min(min_in_service, capacity) - batch_cnt = (capacity + efft_bat_sz - 1) // efft_bat_sz - if pause_sec * (batch_cnt - 1) >= self.stack.timeout_secs(): - raise ValueError('The current UpdatePolicy will result ' - 'in stack update timeout.') - # effective capacity includes temporary capacity added to accommodate # the minimum number of instances in service during update efft_capacity = max(capacity - efft_bat_sz, efft_min_sz) + efft_bat_sz + batch_cnt = (efft_capacity + efft_bat_sz - 1) // efft_bat_sz + if pause_sec * (batch_cnt - 1) >= self.stack.timeout_secs(): + raise ValueError('The current UpdatePolicy will result ' + 'in stack update timeout.') try: remainder = capacity @@ -389,7 +388,8 @@ class InstanceGroup(stack_resource.StackResource): updater.run_to_completion() self.check_update_complete(updater) remainder -= efft_bat_sz - if remainder > 0 and pause_sec > 0: + if ((remainder > 0 or efft_capacity > capacity) and + pause_sec > 0): self._lb_reload() waiter = scheduler.TaskRunner(pause_between_batch) waiter(timeout=pause_sec) diff --git a/heat/tests/test_autoscaling_update_policy.py b/heat/tests/test_autoscaling_update_policy.py index 29e93b294..24bdfe6ee 100644 --- a/heat/tests/test_autoscaling_update_policy.py +++ b/heat/tests/test_autoscaling_update_policy.py @@ -804,18 +804,23 @@ class AutoScalingGroupTest(common.HeatTestCase): self.m.UnsetStubs() # modify the pause time and test for error - new_pause_time = 'PT30M' + # the following test, effective_capacity is 12 + # batch_count = (effective_capacity + batch_size -1)//batch_size + # = (12 + 2 - 1)//2 = 6 + # if (batch_count - 1)* pause_time > stack.time_out, to raise error + # (6 - 1)*14*60 > 3600, so to raise error + new_pause_time = 'PT14M' + min_in_service = 10 updt_template = json.loads(copy.deepcopy(asg_tmpl_with_updt_policy)) group = updt_template['Resources']['WebServerGroup'] policy = group['UpdatePolicy']['AutoScalingRollingUpdate'] policy['PauseTime'] = new_pause_time + policy['MinInstancesInService'] = min_in_service config = updt_template['Resources']['LaunchConfig'] config['Properties']['ImageId'] = 'F17-x86_64-cfntools' updated_tmpl = template_format.parse(json.dumps(updt_template)) updated_stack = utils.parse_stack(updated_tmpl) - self._stub_grp_replace(num_creates_expected_on_updt=0, - num_deletes_expected_on_updt=0, - num_reloads_expected_on_updt=1) + self.stub_KeypairConstraint_validate() self.stub_ImageConstraint_validate() self.m.ReplayAll()