From 0679458a59a3f1ea212bbcc05fdf7cf970c454fd Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 30 Jun 2015 11:17:33 -0700 Subject: [PATCH] Prepare SignalResponder class for more signal types This change makes some minor refactorings in the SignalResponder class to disambiguate the existing signal support and allow for the addition of other signal types currently supported elsewhere in the codebase. Implements: partial blueprint uniform-resource-signals Change-Id: I353558431a8851e4e43c8a787f03190ed508bb5d --- .../resources/aws/autoscaling/scaling_policy.py | 2 +- .../resources/aws/cfn/wait_condition_handle.py | 2 +- .../resources/openstack/heat/ha_restarter.py | 2 +- .../resources/openstack/heat/scaling_policy.py | 4 ++-- .../openstack/heat/software_deployment.py | 4 ++-- .../resources/openstack/mistral/workflow.py | 2 +- heat/engine/resources/signal_responder.py | 16 ++++++++++------ heat/tests/generic_resource.py | 2 +- heat/tests/test_software_deployment.py | 8 ++++---- 9 files changed, 23 insertions(+), 19 deletions(-) diff --git a/heat/engine/resources/aws/autoscaling/scaling_policy.py b/heat/engine/resources/aws/autoscaling/scaling_policy.py index d5a6340857..0af313cb1e 100644 --- a/heat/engine/resources/aws/autoscaling/scaling_policy.py +++ b/heat/engine/resources/aws/autoscaling/scaling_policy.py @@ -97,7 +97,7 @@ class AWSScalingPolicy(heat_sp.AutoScalingPolicy): def FnGetRefId(self): if self.resource_id is not None: - return six.text_type(self._get_signed_url()) + return six.text_type(self._get_ec2_signed_url()) else: return six.text_type(self.name) diff --git a/heat/engine/resources/aws/cfn/wait_condition_handle.py b/heat/engine/resources/aws/cfn/wait_condition_handle.py index 0811a068cb..9982c74311 100644 --- a/heat/engine/resources/aws/cfn/wait_condition_handle.py +++ b/heat/engine/resources/aws/cfn/wait_condition_handle.py @@ -45,7 +45,7 @@ class WaitConditionHandle(wc_base.BaseWaitConditionHandle): ''' if self.resource_id: wc = signal_responder.WAITCONDITION - return six.text_type(self._get_signed_url(signal_type=wc)) + return six.text_type(self._get_ec2_signed_url(signal_type=wc)) else: return six.text_type(self.name) diff --git a/heat/engine/resources/openstack/heat/ha_restarter.py b/heat/engine/resources/openstack/heat/ha_restarter.py index 74db80af73..4dbfa20cf5 100644 --- a/heat/engine/resources/openstack/heat/ha_restarter.py +++ b/heat/engine/resources/openstack/heat/ha_restarter.py @@ -103,7 +103,7 @@ class Restarter(signal_responder.SignalResponder): when there is an alarm. ''' if name == self.ALARM_URL and self.resource_id is not None: - return six.text_type(self._get_signed_url()) + return six.text_type(self._get_ec2_signed_url()) def resource_mapping(): diff --git a/heat/engine/resources/openstack/heat/scaling_policy.py b/heat/engine/resources/openstack/heat/scaling_policy.py index 957f5ed5df..8074089083 100644 --- a/heat/engine/resources/openstack/heat/scaling_policy.py +++ b/heat/engine/resources/openstack/heat/scaling_policy.py @@ -190,9 +190,9 @@ class AutoScalingPolicy(signal_responder.SignalResponder, def _resolve_attribute(self, name): if name == self.ALARM_URL: - return six.text_type(self._get_signed_url()) + return six.text_type(self._get_ec2_signed_url()) elif name == self.SIGNAL_URL: - return six.text_type(self._get_signal_url()) + return six.text_type(self._get_heat_signal_url()) def FnGetRefId(self): return resource.Resource.FnGetRefId(self) diff --git a/heat/engine/resources/openstack/heat/software_deployment.py b/heat/engine/resources/openstack/heat/software_deployment.py index 79d7258998..0b87aea57a 100644 --- a/heat/engine/resources/openstack/heat/software_deployment.py +++ b/heat/engine/resources/openstack/heat/software_deployment.py @@ -425,7 +425,7 @@ class SoftwareDeployment(signal_responder.SignalResponder): scl.DESCRIPTION: _('ID of signal to use for signaling ' 'output values'), scl.TYPE: 'String', - 'value': self._get_signed_url() + 'value': self._get_ec2_signed_url() }) inputs.append({ scl.NAME: self.DEPLOY_SIGNAL_VERB, @@ -537,7 +537,7 @@ class SoftwareDeployment(signal_responder.SignalResponder): def _delete_resource(self): if self._signal_transport_cfn(): - self._delete_signed_url() + self._delete_ec2_signed_url() self._delete_user() elif self._signal_transport_heat(): self._delete_user() diff --git a/heat/engine/resources/openstack/mistral/workflow.py b/heat/engine/resources/openstack/mistral/workflow.py index 47befc64d7..0b58d521a1 100644 --- a/heat/engine/resources/openstack/mistral/workflow.py +++ b/heat/engine/resources/openstack/mistral/workflow.py @@ -408,7 +408,7 @@ class Workflow(signal_responder.SignalResponder, self.INPUT: self.properties.get(self.INPUT)} elif name == self.ALARM_URL: - return six.text_type(self._get_signed_url()) + return six.text_type(self._get_ec2_signed_url()) def resource_mapping(): diff --git a/heat/engine/resources/signal_responder.py b/heat/engine/resources/signal_responder.py index 87472fb3d2..5693bf5968 100644 --- a/heat/engine/resources/signal_responder.py +++ b/heat/engine/resources/signal_responder.py @@ -42,12 +42,13 @@ class SignalResponder(stack_user.StackUser): def handle_delete(self): super(SignalResponder, self).handle_delete() - self._delete_signed_url() + self._delete_ec2_signed_url() + self._delete_heat_signal_url() - def _delete_signed_url(self): + def _delete_ec2_signed_url(self): self.data_delete('ec2_signed_url') - def _get_signed_url(self, signal_type=SIGNAL): + def _get_ec2_signed_url(self, signal_type=SIGNAL): """Create properly formatted and pre-signed URL. This uses the created user for the credentials. @@ -105,8 +106,11 @@ class SignalResponder(stack_user.StackUser): self.data_set('ec2_signed_url', url) return url - def _get_signal_url(self): - stored = self.data().get('signal_url') + def _delete_heat_signal_url(self): + self.data_delete('heat_signal_url') + + def _get_heat_signal_url(self): + stored = self.data().get('heat_signal_url') if stored is not None: return stored @@ -117,5 +121,5 @@ class SignalResponder(stack_user.StackUser): url = urlparse.urlunsplit( (host_url.scheme, host_url.netloc, 'v1/%s/signal' % path, '', '')) - self.data_set('signal_url', url) + self.data_set('heat_signal_url', url) return url diff --git a/heat/tests/generic_resource.py b/heat/tests/generic_resource.py index c1fc6969b1..5466b109c2 100644 --- a/heat/tests/generic_resource.py +++ b/heat/tests/generic_resource.py @@ -145,7 +145,7 @@ class SignalResource(signal_responder.SignalResponder): def _resolve_attribute(self, name): if name == 'AlarmUrl' and self.resource_id is not None: - return six.text_type(self._get_signed_url()) + return six.text_type(self._get_ec2_signed_url()) class StackUserResource(stack_user.StackUser): diff --git a/heat/tests/test_software_deployment.py b/heat/tests/test_software_deployment.py index 92a1159af5..85167e2c80 100644 --- a/heat/tests/test_software_deployment.py +++ b/heat/tests/test_software_deployment.py @@ -163,10 +163,10 @@ class SoftwareDeploymentTest(common.HeatTestCase): self.patchobject(sd.SoftwareDeployment, '_create_user') self.patchobject(sd.SoftwareDeployment, '_create_keypair') self.patchobject(sd.SoftwareDeployment, '_delete_user') - self.patchobject(sd.SoftwareDeployment, '_delete_signed_url') - get_signed_url = self.patchobject( - sd.SoftwareDeployment, '_get_signed_url') - get_signed_url.return_value = 'http://192.0.2.2/signed_url' + self.patchobject(sd.SoftwareDeployment, '_delete_ec2_signed_url') + get_ec2_signed_url = self.patchobject( + sd.SoftwareDeployment, '_get_ec2_signed_url') + get_ec2_signed_url.return_value = 'http://192.0.2.2/signed_url' self.deployment = self.stack['deployment_mysql']