Merge "Adding own child_template for AutoScalingGroup"
This commit is contained in:
commit
a6e3d4b3ee
@ -568,12 +568,7 @@ class AutoScalingGroup(InstanceGroup, CooldownMixin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def handle_create(self):
|
def handle_create(self):
|
||||||
if self.properties[self.DESIRED_CAPACITY]:
|
return self.create_with_template(self.child_template(),
|
||||||
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,
|
|
||||||
self._environment())
|
self._environment())
|
||||||
|
|
||||||
def check_create_complete(self, task):
|
def check_create_complete(self, task):
|
||||||
@ -748,6 +743,13 @@ class AutoScalingGroup(InstanceGroup, CooldownMixin):
|
|||||||
raise exception.NotSupported(feature=_("Anything other than one "
|
raise exception.NotSupported(feature=_("Anything other than one "
|
||||||
"VPCZoneIdentifier"))
|
"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):
|
class LaunchConfiguration(resource.Resource):
|
||||||
|
|
||||||
|
@ -1682,6 +1682,33 @@ class AutoScalingTest(HeatTestCase):
|
|||||||
expected_msg = "DesiredCapacity must be between MinSize and MaxSize"
|
expected_msg = "DesiredCapacity must be between MinSize and MaxSize"
|
||||||
self.assertEqual(expected_msg, str(e))
|
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):
|
class TestInstanceGroup(HeatTestCase):
|
||||||
params = {'KeyName': 'test', 'ImageId': 'foo'}
|
params = {'KeyName': 'test', 'ImageId': 'foo'}
|
||||||
|
Loading…
Reference in New Issue
Block a user