Merge "Adding own child_template for AutoScalingGroup"

This commit is contained in:
Jenkins 2014-07-17 19:22:52 +00:00 committed by Gerrit Code Review
commit a6e3d4b3ee
2 changed files with 35 additions and 6 deletions

View File

@ -568,12 +568,7 @@ class AutoScalingGroup(InstanceGroup, CooldownMixin):
}
def handle_create(self):
if self.properties[self.DESIRED_CAPACITY]:
num_to_create = self.properties[self.DESIRED_CAPACITY]
else:
num_to_create = self.properties[self.MIN_SIZE]
initial_template = self._create_template(num_to_create)
return self.create_with_template(initial_template,
return self.create_with_template(self.child_template(),
self._environment())
def check_create_complete(self, task):
@ -748,6 +743,13 @@ class AutoScalingGroup(InstanceGroup, CooldownMixin):
raise exception.NotSupported(feature=_("Anything other than one "
"VPCZoneIdentifier"))
def child_template(self):
if self.properties[self.DESIRED_CAPACITY]:
num_instances = self.properties[self.DESIRED_CAPACITY]
else:
num_instances = self.properties[self.MIN_SIZE]
return self._create_template(num_instances)
class LaunchConfiguration(resource.Resource):

View File

@ -1682,6 +1682,33 @@ class AutoScalingTest(HeatTestCase):
expected_msg = "DesiredCapacity must be between MinSize and MaxSize"
self.assertEqual(expected_msg, str(e))
def test_child_template_uses_min_size(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
defn = rsrc_defn.ResourceDefinition(
'asg', 'AWS::AutoScaling::AutoScalingGroup',
{'MinSize': 2, 'MaxSize': 5, 'LaunchConfigurationName': 'foo'})
rsrc = asc.AutoScalingGroup('asg', defn, stack)
rsrc._create_template = mock.Mock(return_value='tpl')
self.assertEqual('tpl', rsrc.child_template())
rsrc._create_template.assert_called_once_with(2)
def test_child_template_uses_desired_capacity(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
defn = rsrc_defn.ResourceDefinition(
'asg', 'AWS::AutoScaling::AutoScalingGroup',
{'MinSize': 2, 'MaxSize': 5, 'DesiredCapacity': 3,
'LaunchConfigurationName': 'foo'})
rsrc = asc.AutoScalingGroup('asg', defn, stack)
rsrc._create_template = mock.Mock(return_value='tpl')
self.assertEqual('tpl', rsrc.child_template())
rsrc._create_template.assert_called_once_with(3)
class TestInstanceGroup(HeatTestCase):
params = {'KeyName': 'test', 'ImageId': 'foo'}