Don't get derived config if resource ID unset

SoftwareDeployments that do not have CREATE as one of their actions will
not have a resource ID when they are updated. In this case,
handle_update should not attempt to retrieve the SoftwareDeployment's
derived config because it will fail.

Closes-Bug: #1629397
Change-Id: Ia49a549e11e2e6a1e9399a1370f990780c17bf0d
(cherry picked from commit 5fc3e013b5)
This commit is contained in:
Drago Rosson 2016-09-30 18:14:03 +00:00 committed by Zane Bitter
parent dd707bc997
commit ea0ba0ae45
2 changed files with 36 additions and 4 deletions

View File

@ -435,10 +435,14 @@ class SoftwareDeployment(signal_responder.SignalResponder):
return self._check_complete()
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
prev_derived_config = self._get_derived_config_id()
old_config = self._load_config(prev_derived_config)
old_inputs = {i.name(): i
for i in old_config[rpc_api.SOFTWARE_CONFIG_INPUTS]}
if self.resource_id is None:
prev_derived_config = None
old_inputs = {}
else:
prev_derived_config = self._get_derived_config_id()
old_config = self._load_config(prev_derived_config)
old_inputs = {i.name(): i
for i in old_config[rpc_api.SOFTWARE_CONFIG_INPUTS]}
self.properties = json_snippet.properties(self.properties_schema,
self.context)

View File

@ -136,6 +136,21 @@ class SoftwareDeploymentTest(common.HeatTestCase):
}
}
template_update_only = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'deployment_mysql': {
'Type': 'OS::Heat::SoftwareDeployment',
'Properties': {
'server': '9f1f0e00-05d2-4ca5-8602-95021f19c9d0',
'config': '48e8ade1-9196-42d5-89a2-f709fde42632',
'input_values': {'foo': 'bar'},
'actions': ['UPDATE'],
}
}
}
}
template_no_config = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
@ -881,6 +896,19 @@ class SoftwareDeploymentTest(common.HeatTestCase):
self.deployment.handle_update,
snippet, None, prop_diff)
def test_handle_update_with_update_only(self):
self._create_stack(self.template_update_only)
rsrc = self.stack['deployment_mysql']
prop_diff = {
'input_values': {'foo': 'different'}
}
props = copy.copy(rsrc.properties.data)
props.update(prop_diff)
snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
self.deployment.handle_update(
json_snippet=snippet, tmpl_diff=None, prop_diff=prop_diff)
self.rpc_client.show_software_deployment.assert_not_called()
def test_handle_suspend_resume(self):
self._create_stack(self.template_delete_suspend_resume)