Avoid unnecessary passing of child_params in asg
This patch removes the unnecessary passing of child_params when processing instance groups or auto-scaling groups. No test case is added since this patch only introduces two lines of new code that have been covered well by existing test cases. Change-Id: I75720dbdf96b9722605b4db3bc2df6c8abf36e04
This commit is contained in:
parent
12a717f926
commit
b5b4ce4d9b
|
@ -200,8 +200,7 @@ class AutoScalingGroup(instgrp.InstanceGroup, cooldown.CooldownMixin):
|
|||
|
||||
def handle_create(self):
|
||||
self.validate_launchconfig()
|
||||
return self.create_with_template(self.child_template(),
|
||||
self._environment())
|
||||
return self.create_with_template(self.child_template())
|
||||
|
||||
def _get_conf_properties(self):
|
||||
conf, props = super(AutoScalingGroup, self)._get_conf_properties()
|
||||
|
|
|
@ -166,21 +166,12 @@ class InstanceGroup(stack_resource.StackResource):
|
|||
lc=self.LAUNCH_CONFIGURATION_NAME,
|
||||
ref=conf_refid))
|
||||
|
||||
def _environment(self):
|
||||
"""Return the environment for the nested stack."""
|
||||
return {
|
||||
environment_format.PARAMETERS: {},
|
||||
environment_format.RESOURCE_REGISTRY: {
|
||||
SCALED_RESOURCE_TYPE: 'AWS::EC2::Instance',
|
||||
},
|
||||
}
|
||||
|
||||
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, self._environment())
|
||||
return self.create_with_template(initial_template)
|
||||
|
||||
def check_create_complete(self, task):
|
||||
"""
|
||||
|
@ -317,8 +308,7 @@ class InstanceGroup(stack_resource.StackResource):
|
|||
efft_capacity = capacity
|
||||
template = self._create_template(efft_capacity, efft_bat_sz)
|
||||
self._lb_reload(exclude=changing_instances(template))
|
||||
updater = self.update_with_template(template,
|
||||
self._environment())
|
||||
updater = self.update_with_template(template)
|
||||
updater.run_to_completion()
|
||||
self.check_update_complete(updater)
|
||||
remainder -= efft_bat_sz
|
||||
|
@ -338,8 +328,7 @@ class InstanceGroup(stack_resource.StackResource):
|
|||
"""
|
||||
new_template = self._create_template(new_capacity)
|
||||
try:
|
||||
updater = self.update_with_template(new_template,
|
||||
self._environment())
|
||||
updater = self.update_with_template(new_template)
|
||||
updater.run_to_completion()
|
||||
self.check_update_complete(updater)
|
||||
finally:
|
||||
|
@ -397,7 +386,13 @@ class InstanceGroup(stack_resource.StackResource):
|
|||
return self._create_template(num_instances)
|
||||
|
||||
def child_params(self):
|
||||
return self._environment()
|
||||
"""Return the environment for the nested stack."""
|
||||
return {
|
||||
environment_format.PARAMETERS: {},
|
||||
environment_format.RESOURCE_REGISTRY: {
|
||||
SCALED_RESOURCE_TYPE: 'AWS::EC2::Instance',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
|
|
|
@ -151,8 +151,9 @@ class StackResource(resource.Resource):
|
|||
return template.Template(parsed_child_template,
|
||||
files=self.stack.t.files)
|
||||
|
||||
def _parse_nested_stack(self, stack_name, child_template, child_params,
|
||||
timeout_mins=None, adopt_data=None):
|
||||
def _parse_nested_stack(self, stack_name, child_template,
|
||||
child_params=None, timeout_mins=None,
|
||||
adopt_data=None):
|
||||
if self.stack.nested_depth >= cfg.CONF.max_nested_stack_depth:
|
||||
msg = _("Recursion depth exceeds %d.") % \
|
||||
cfg.CONF.max_nested_stack_depth
|
||||
|
@ -173,10 +174,13 @@ class StackResource(resource.Resource):
|
|||
stack_user_project_id = self.stack.stack_user_project_id
|
||||
new_nested_depth = self.stack.nested_depth + 1
|
||||
|
||||
# Note we disable rollback for nested stacks, since they
|
||||
# should be rolled back by the parent stack on failure
|
||||
if child_params is None:
|
||||
child_params = self.child_params()
|
||||
child_env = environment.get_child_environment(
|
||||
self.stack.env, child_params)
|
||||
|
||||
# Note we disable rollback for nested stacks, since they
|
||||
# should be rolled back by the parent stack on failure
|
||||
nested = parser.Stack(self.context,
|
||||
stack_name,
|
||||
parsed_template,
|
||||
|
@ -203,7 +207,7 @@ class StackResource(resource.Resource):
|
|||
message = exception.StackResourceLimitExceeded.msg_fmt
|
||||
raise exception.RequestLimitExceeded(message=message)
|
||||
|
||||
def create_with_template(self, child_template, user_params,
|
||||
def create_with_template(self, child_template, user_params=None,
|
||||
timeout_mins=None, adopt_data=None):
|
||||
"""Create the nested stack with the given template."""
|
||||
name = self.physical_resource_name()
|
||||
|
@ -237,7 +241,7 @@ class StackResource(resource.Resource):
|
|||
|
||||
return done
|
||||
|
||||
def update_with_template(self, child_template, user_params,
|
||||
def update_with_template(self, child_template, user_params=None,
|
||||
timeout_mins=None):
|
||||
"""Update the nested stack with the new template."""
|
||||
nested_stack = self.nested()
|
||||
|
|
|
@ -213,12 +213,8 @@ class TestGroupCrud(common.HeatTestCase):
|
|||
|
||||
self.group.handle_create()
|
||||
|
||||
expect_env = {'parameters': {},
|
||||
'resource_registry': {
|
||||
'OS::Heat::ScaledResource': 'AWS::EC2::Instance'}}
|
||||
self.group.child_template.assert_called_once_with()
|
||||
self.group.create_with_template.assert_called_once_with(
|
||||
'{}', expect_env)
|
||||
self.group.create_with_template.assert_called_once_with('{}')
|
||||
|
||||
def test_handle_update_desired_cap(self):
|
||||
self.group._try_rolling_update = mock.Mock(return_value=None)
|
||||
|
|
|
@ -306,12 +306,8 @@ class TestGroupCrud(common.HeatTestCase):
|
|||
|
||||
self.group.handle_create()
|
||||
|
||||
expect_env = {'parameters': {},
|
||||
'resource_registry': {
|
||||
'OS::Heat::ScaledResource': 'AWS::EC2::Instance'}}
|
||||
self.group.child_template.assert_called_once_with()
|
||||
self.group.create_with_template.assert_called_once_with(
|
||||
'{}', expect_env)
|
||||
self.group.create_with_template.assert_called_once_with('{}')
|
||||
|
||||
def test_handle_update_desired_cap(self):
|
||||
self.group._try_rolling_update = mock.Mock(return_value=None)
|
||||
|
|
|
@ -248,7 +248,7 @@ class RollingUpdatesTest(common.HeatTestCase):
|
|||
key=lambda name: rsrc.nested().resources[name].created_time)
|
||||
batches = []
|
||||
|
||||
def update_with_template(tmpl, env):
|
||||
def update_with_template(tmpl):
|
||||
# keep track of the new updates to resources _in creation order_.
|
||||
definitions = tmpl.resource_definitions(stack)
|
||||
templates = [definitions[name] for name in created_order]
|
||||
|
|
|
@ -50,7 +50,6 @@ class TestInstanceGroup(common.HeatTestCase):
|
|||
'resource_registry': {
|
||||
'OS::Heat::ScaledResource': 'AWS::EC2::Instance'}}
|
||||
self.assertEqual(expected, self.instance_group.child_params())
|
||||
self.assertEqual(expected, self.instance_group._environment())
|
||||
|
||||
def test_tags_default(self):
|
||||
expected = [{'Value': u'asg',
|
||||
|
@ -96,13 +95,9 @@ class TestInstanceGroup(common.HeatTestCase):
|
|||
|
||||
self.instance_group.handle_create()
|
||||
|
||||
expect_env = {'parameters': {},
|
||||
'resource_registry': {
|
||||
'OS::Heat::ScaledResource': 'AWS::EC2::Instance'}}
|
||||
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(
|
||||
'{}', expect_env)
|
||||
self.instance_group.create_with_template.assert_called_once_with('{}')
|
||||
|
||||
def test_update_in_failed(self):
|
||||
self.instance_group.state_set('CREATE', 'FAILED')
|
||||
|
|
Loading…
Reference in New Issue