From 736944453492767b30f8bab0df5d954ea5bcad33 Mon Sep 17 00:00:00 2001 From: Tetiana Lashchova Date: Mon, 13 Jul 2015 17:40:43 +0300 Subject: [PATCH] Add show_resource function to Mistral resources (4) AWS resources will not be changed due to they do not support additional attributes. So 'show' attribute will be presented in their schemas, but will return always None. This patch adds show_resource method for heat (mistral) resources: - workflow - cron trigger Change-Id: I10599a0eb45c99acb44414147d04734e740afcf0 --- heat/engine/resources/openstack/mistral/cron_trigger.py | 9 +++++++++ heat/engine/resources/openstack/mistral/workflow.py | 9 +++++++++ heat/tests/mistral/test_mistral_cron_trigger.py | 2 ++ heat/tests/mistral/test_mistral_workflow.py | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/heat/engine/resources/openstack/mistral/cron_trigger.py b/heat/engine/resources/openstack/mistral/cron_trigger.py index 7f50365e50..7bdc6e1e53 100644 --- a/heat/engine/resources/openstack/mistral/cron_trigger.py +++ b/heat/engine/resources/openstack/mistral/cron_trigger.py @@ -89,6 +89,8 @@ class CronTrigger(resource.Resource): default_client_name = 'mistral' + entity = 'cron_triggers' + def _cron_trigger_name(self): return self.properties.get(self.NAME) or self.physical_resource_name() @@ -126,6 +128,13 @@ class CronTrigger(resource.Resource): elif name == self.REMAINING_EXECUTIONS: return trigger.remaining_executions + # TODO(tlashchova): remove this method when mistralclient>1.0.0 is used. + def _show_resource(self): + cron_trigger = self.client().cron_triggers.get(self.resource_id) + if hasattr(cron_trigger, 'to_dict'): + super(CronTrigger, self)._show_resource() + return cron_trigger._data + def resource_mapping(): return { diff --git a/heat/engine/resources/openstack/mistral/workflow.py b/heat/engine/resources/openstack/mistral/workflow.py index 2005cbbadc..55251debbd 100644 --- a/heat/engine/resources/openstack/mistral/workflow.py +++ b/heat/engine/resources/openstack/mistral/workflow.py @@ -32,6 +32,8 @@ class Workflow(signal_responder.SignalResponder, default_client_name = 'mistral' + entity = 'workflows' + PROPERTIES = ( NAME, TYPE, DESCRIPTION, INPUT, OUTPUT, TASKS, PARAMS ) = ( @@ -406,6 +408,13 @@ class Workflow(signal_responder.SignalResponder, elif name == self.ALARM_URL: return six.text_type(self._get_ec2_signed_url()) + # TODO(tlashchova): remove this method when mistralclient>1.0.0 is used. + def _show_resource(self): + workflow = self.client().workflows.get(self.resource_id) + if hasattr(workflow, 'to_dict'): + super(Workflow, self)._show_resource() + return workflow._data + def resource_mapping(): return { diff --git a/heat/tests/mistral/test_mistral_cron_trigger.py b/heat/tests/mistral/test_mistral_cron_trigger.py index 7d68f7f07c..f675a79625 100644 --- a/heat/tests/mistral/test_mistral_cron_trigger.py +++ b/heat/tests/mistral/test_mistral_cron_trigger.py @@ -41,6 +41,7 @@ class FakeCronTrigger(object): self.name = name self.next_execution_time = '2015-03-01 00:00:00' self.remaining_executions = 3 + self._data = {'trigger': 'info'} class MistralCronTriggerTestResource(cron_trigger.CronTrigger): @@ -98,6 +99,7 @@ class MistralCronTriggerTest(common.HeatTestCase): self.assertEqual('2015-03-01 00:00:00', ct.FnGetAtt('next_execution_time')) self.assertEqual(3, ct.FnGetAtt('remaining_executions')) + self.assertEqual({'trigger': 'info'}, ct.FnGetAtt('show')) def test_delete(self): ct = self._create_resource('trigger', self.rsrc_defn, self.stack) diff --git a/heat/tests/mistral/test_mistral_workflow.py b/heat/tests/mistral/test_mistral_workflow.py index 2d4f1b344b..869de921dd 100644 --- a/heat/tests/mistral/test_mistral_workflow.py +++ b/heat/tests/mistral/test_mistral_workflow.py @@ -173,6 +173,7 @@ resources: class FakeWorkflow(object): def __init__(self, name): self.name = name + self._data = {'workflow': 'info'} class MistralWorkFlowTestResource(workflow.Workflow): @@ -247,9 +248,12 @@ class TestMistralWorkflow(common.HeatTestCase): def test_attributes(self): wf = self._create_resource('workflow', self.rsrc_defn, self.stack) + self.mistral.workflows.get.return_value = \ + FakeWorkflow('test_stack-workflow-b5fiekfci3yc') self.assertEqual({'name': 'test_stack-workflow-b5fiekfci3yc', 'input': None}, wf.FnGetAtt('data')) self.assertEqual([], wf.FnGetAtt('executions')) + self.assertEqual({'workflow': 'info'}, wf.FnGetAtt('show')) def test_direct_workflow_validation_error(self): error_msg = ("Mistral resource validation error: "