Move launchconfig reference validation to validate()

Now we do launchconfig reference check for
AWS::AutoScaling::AutoScalingGroup and OS::Heat::InstanceGroup
resources only in handle_create(), this patch moves the
check to validate(), then the validation will work when
resource update.

Change-Id: I727c7155ce708a11184aad6fea36a365f1022c92
Closes-Bug: #1554311
This commit is contained in:
huangtianhua 2016-03-08 17:16:23 +08:00
parent b6a0e752cf
commit ee086961a6
3 changed files with 18 additions and 18 deletions

View File

@ -189,7 +189,6 @@ class AutoScalingGroup(instgrp.InstanceGroup, cooldown.CooldownMixin):
}
def handle_create(self):
self.validate_launchconfig()
return self.create_with_template(self.child_template())
def _make_launch_config_resource(self, name, props):

View File

@ -132,6 +132,7 @@ class InstanceGroup(stack_resource.StackResource):
def validate(self):
"""Add validation for update_policy."""
self.validate_launchconfig()
super(InstanceGroup, self).validate()
if self.update_policy is not None:
@ -167,7 +168,6 @@ class InstanceGroup(stack_resource.StackResource):
def handle_create(self):
"""Create a nested stack and add the initial resources to it."""
self.validate_launchconfig()
num_instances = self.properties[self.SIZE]
initial_template = self._create_template(num_instances)
return self.create_with_template(initial_template)

View File

@ -79,32 +79,33 @@ class TestInstanceGroup(common.HeatTestCase):
expected = [{'Key': 'metering.fee', 'Value': 'foo'}]
self.assertEqual(expected, self.instance_group._tags())
def test_validate_launch_conf(self):
props = self.instance_group.properties.data
props['LaunchConfigurationName'] = 'urg_i_cant_spell'
creator = scheduler.TaskRunner(self.instance_group.create)
error = self.assertRaises(exception.ResourceFailure, creator)
self.assertIn('(urg_i_cant_spell) reference can not be found.',
six.text_type(error))
def test_validate_launch_conf_no_ref(self):
def test_validate_launch_conf_ref(self):
# test the launch conf ref can't be found
props = self.instance_group.properties.data
props['LaunchConfigurationName'] = 'JobServerConfig'
creator = scheduler.TaskRunner(self.instance_group.create)
error = self.assertRaises(exception.ResourceFailure, creator)
self.assertIn('(JobServerConfig) reference can not be',
error = self.assertRaises(ValueError, self.instance_group.validate)
self.assertIn('(JobServerConfig) reference can not be found',
six.text_type(error))
# test resource name of instance group not WebServerGroup, so no ref
props = self.instance_group.properties.data
props['LaunchConfigurationName'] = 'LaunchConfig'
error = self.assertRaises(ValueError, self.instance_group.validate)
self.assertIn('LaunchConfigurationName (LaunchConfig) requires a '
'reference to the configuration not just the '
'name of the resource.',
six.text_type(error))
# test validate ok
props = self.instance_group.properties.data
props['LaunchConfigurationName'] = 'LaunchConfig'
self.instance_group.name = 'WebServerGroup'
self.instance_group.validate()
def test_handle_create(self):
self.instance_group.create_with_template = mock.Mock(return_value=None)
self.instance_group.validate_launchconfig = mock.Mock(
return_value=None)
self.instance_group._create_template = mock.Mock(return_value='{}')
self.instance_group.handle_create()
self.instance_group.validate_launchconfig.assert_called_once_with()
self.instance_group._create_template.assert_called_once_with(2)
self.instance_group.create_with_template.assert_called_once_with('{}')