Make Heat ASG always do rolling_updates

This patch closes a bug related to the 'rolling_updates' property of a
Heat AutoScalingResourceGroup resource.  Currently the 'rolling_updates'
property is a map will all keys having default values assigned.  This
means the 'rolling_updates' property as a whole has a default value
ready to be used.

Closes-Bug: 1343873
Change-Id: Icb8dcf44ab16c0547fd1b8edcce650a6892900f2
This commit is contained in:
tengqm 2014-11-30 19:23:22 +08:00
parent 45be90bb22
commit 571b4dd7ba
2 changed files with 14 additions and 7 deletions

View File

@ -102,6 +102,12 @@ class AutoScalingResourceGroup(aws_asg.AutoScalingGroup):
constraints=[constraints.Range(min=0)],
default=0),
},
# A default policy has all fields with their own default values.
default={
MIN_IN_SERVICE: 0,
MAX_BATCH_SIZE: 1,
PAUSE_TIME: 0,
},
),
}
@ -126,8 +132,7 @@ class AutoScalingResourceGroup(aws_asg.AutoScalingGroup):
metadata=rsrc.get('metadata'))
def _try_rolling_update(self, prop_diff):
if (self.properties[self.ROLLING_UPDATES] and
self.RESOURCE in prop_diff):
if self.RESOURCE in prop_diff:
policy = self.properties[self.ROLLING_UPDATES]
self._replace(policy[self.MIN_IN_SERVICE],
policy[self.MAX_BATCH_SIZE],

View File

@ -360,8 +360,6 @@ def asg_tmpl_with_bad_updt_policy():
def asg_tmpl_with_default_updt_policy():
t = template_format.parse(inline_templates.as_heat_template)
agp = t['resources']['my-group']['properties']
agp['rolling_updates'] = {}
return json.dumps(t)
@ -392,7 +390,12 @@ class RollingUpdatePolicyTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
stack.validate()
grp = stack['my-group']
self.assertFalse(grp.properties['rolling_updates'])
default_policy = {
'min_in_service': 0,
'pause_time': 0,
'max_batch_size': 1
}
self.assertEqual(default_policy, grp.properties['rolling_updates'])
def test_parse_with_update_policy(self):
tmpl = template_format.parse(asg_tmpl_with_updt_policy())
@ -429,8 +432,7 @@ class RollingUpdatePolicyTest(common.HeatTestCase):
def test_parse_with_bad_pausetime_in_update_policy(self):
tmpl = template_format.parse(asg_tmpl_with_default_updt_policy())
group = tmpl['resources']['my-group']
policy = group['properties']['rolling_updates']
policy['pause_time'] = 'a-string'
group['properties']['rolling_updates'] = {'pause_time': 'a-string'}
stack = utils.parse_stack(tmpl)
error = self.assertRaises(
exception.StackValidationFailed, stack.validate)