Merge "Move launchconfig reference validation to validate()"
This commit is contained in:
commit
e199dea7bf
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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('{}')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user