diff options
author | Rabi Mishra <ramishra@redhat.com> | 2019-05-29 09:15:24 +0530 |
---|---|---|
committer | Rabi Mishra <ramishra@redhat.com> | 2019-05-31 12:06:30 +0000 |
commit | 03d6348f40073b80e671e885ae1b8aef6c23906a (patch) | |
tree | 50fc15a94958a63f5cb225765e1d6d3668651f70 | |
parent | fdb32e8652150774b9c0e57593cdc35830b9fb78 (diff) | |
download | heat-03d6348f40073b80e671e885ae1b8aef6c23906a.tar.gz |
Return None for attributes of sd with no actions
If the 'actions' property of a deployment is [], we don't
create a software deployment in heat and resource_id of the
software deployment is None. However, there is a possibility
that we access the attributes of the sd in the template and
that results in TypeError as we try to make an rpc call to
show the software deployment for None.
Change-Id: Iefd3cdd20bb51c63e7267ae0628e0f15544c0427
Task: 33516
(cherry picked from commit ee061103477ed7c9b4692a8b90817a127064fbcd)
-rw-r--r-- | heat/engine/resources/openstack/heat/software_deployment.py | 13 | ||||
-rw-r--r-- | heat/tests/openstack/heat/test_software_deployment.py | 3 |
2 files changed, 9 insertions, 7 deletions
diff --git a/heat/engine/resources/openstack/heat/software_deployment.py b/heat/engine/resources/openstack/heat/software_deployment.py index 2767c611d..bc47d093a 100644 --- a/heat/engine/resources/openstack/heat/software_deployment.py +++ b/heat/engine/resources/openstack/heat/software_deployment.py @@ -545,12 +545,13 @@ class SoftwareDeployment(signal_responder.SignalResponder): def get_attribute(self, key, *path): """Resource attributes map to deployment outputs values.""" - sd = self.rpc_client().show_software_deployment( - self.context, self.resource_id) - ov = sd[rpc_api.SOFTWARE_DEPLOYMENT_OUTPUT_VALUES] or {} - if key in ov: - attribute = ov.get(key) - return attributes.select_from_attribute(attribute, path) + if self.resource_id is not None: + sd = self.rpc_client().show_software_deployment( + self.context, self.resource_id) + ov = sd[rpc_api.SOFTWARE_DEPLOYMENT_OUTPUT_VALUES] or {} + if key in ov: + attribute = ov.get(key) + return attributes.select_from_attribute(attribute, path) # Since there is no value for this key yet, check the output schemas # to find out if the key is valid diff --git a/heat/tests/openstack/heat/test_software_deployment.py b/heat/tests/openstack/heat/test_software_deployment.py index 13b6d83d4..ef9075cff 100644 --- a/heat/tests/openstack/heat/test_software_deployment.py +++ b/heat/tests/openstack/heat/test_software_deployment.py @@ -201,7 +201,6 @@ class SoftwareDeploymentTest(common.HeatTestCase): get_ec2_signed_url.return_value = 'http://192.0.2.2/signed_url' self.deployment = self.stack['deployment_mysql'] - self.rpc_client = mock.MagicMock() self.deployment._rpc_client = self.rpc_client @@ -1097,6 +1096,7 @@ class SoftwareDeploymentTest(common.HeatTestCase): def test_fn_get_att(self): self._create_stack(self.template) + self.deployment.resource_id = 'c8a19429-7fde-47ea-a42f-40045488226c' mock_sd = { 'outputs': [ {'name': 'failed', 'error_output': True}, @@ -1132,6 +1132,7 @@ class SoftwareDeploymentTest(common.HeatTestCase): def test_fn_get_att_error(self): self._create_stack(self.template) + self.deployment.resource_id = 'c8a19429-7fde-47ea-a42f-40045488226c' mock_sd = { 'outputs': [], |