From 654a0ed26de7f7dc3e255826dc477dffb1393550 Mon Sep 17 00:00:00 2001 From: Tetiana Lashchova Date: Fri, 24 Apr 2015 18:17:13 +0300 Subject: [PATCH] Add remaining_executions attribute to OS::Mistral::CronTrigger remaining_executions defines the number of occurrences after which the trigger should be deleted. Change-Id: Icf54e6def1d985217e7db46850dbd777f1ad8760 --- .../heat_mistral/resources/cron_trigger.py | 17 +++++++++++++---- .../heat_mistral/tests/test_cron_trigger.py | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/contrib/heat_mistral/heat_mistral/resources/cron_trigger.py b/contrib/heat_mistral/heat_mistral/resources/cron_trigger.py index 7890f2f952..5a69877326 100644 --- a/contrib/heat_mistral/heat_mistral/resources/cron_trigger.py +++ b/contrib/heat_mistral/heat_mistral/resources/cron_trigger.py @@ -34,9 +34,9 @@ class CronTrigger(resource.Resource): ) ATTRIBUTES = ( - NEXT_EXECUTION_TIME, + NEXT_EXECUTION_TIME, REMAINING_EXECUTIONS ) = ( - 'next_execution_time', + 'next_execution_time', 'remaining_executions' ) properties_schema = { @@ -75,8 +75,11 @@ class CronTrigger(resource.Resource): attributes_schema = { NEXT_EXECUTION_TIME: attributes.Schema( - _('Time of the next execution in format "YYYY-MM-DD HH:MM".') + _('Time of the next execution in format "YYYY-MM-DD HH:MM:SS".') ), + REMAINING_EXECUTIONS: attributes.Schema( + _('Number of remaining executions.') + ) } default_client_name = 'mistral' @@ -108,9 +111,15 @@ class CronTrigger(resource.Resource): self.client_plugin().ignore_not_found(ex) def _resolve_attribute(self, name): - if name == self.NEXT_EXECUTION_TIME: + try: trigger = self.client().cron_triggers.get(self.resource_id) + except Exception as ex: + self.client_plugin().ignore_not_found(ex) + return '' + if name == self.NEXT_EXECUTION_TIME: return trigger.next_execution_time + elif name == self.REMAINING_EXECUTIONS: + return trigger.remaining_executions def resource_mapping(): diff --git a/contrib/heat_mistral/heat_mistral/tests/test_cron_trigger.py b/contrib/heat_mistral/heat_mistral/tests/test_cron_trigger.py index 62c94dd308..e9f09c1b3e 100644 --- a/contrib/heat_mistral/heat_mistral/tests/test_cron_trigger.py +++ b/contrib/heat_mistral/heat_mistral/tests/test_cron_trigger.py @@ -40,6 +40,7 @@ class FakeCronTrigger(object): def __init__(self, name): self.name = name self.next_execution_time = '2015-03-01 00:00:00' + self.remaining_executions = 3 class CronTriggerTest(common.HeatTestCase): @@ -89,6 +90,7 @@ class CronTriggerTest(common.HeatTestCase): ct = self._create_resource('trigger', self.rsrc_defn, self.stack) self.assertEqual('2015-03-01 00:00:00', ct.FnGetAtt('next_execution_time')) + self.assertEqual(3, ct.FnGetAtt('remaining_executions')) def test_delete(self): ct = self._create_resource('trigger', self.rsrc_defn, self.stack)