From 1a224a3f5a5b049ec5c9edfac2f9880859a18566 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 2 Jun 2016 11:52:56 -0400 Subject: [PATCH] Allow deletion_policy to be lowercase in HOT This is more consistent with the rest of the HOT language. Change-Id: I445e986b067a1311efc23a5d350bd81976253a3f --- doc/source/template_guide/hot_spec.rst | 7 ++-- heat/engine/hot/template.py | 11 ++++++ heat/tests/test_hot.py | 48 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/doc/source/template_guide/hot_spec.rst b/doc/source/template_guide/hot_spec.rst index 4c7a4f096..3ce85bb16 100644 --- a/doc/source/template_guide/hot_spec.rst +++ b/doc/source/template_guide/hot_spec.rst @@ -645,8 +645,11 @@ update_policy deletion_policy Deletion policy for the resource. The allowed deletion policies are - ``Delete``, ``Retain``, and ``Snapshot``. - This attribute is optional; the default policy is ``Delete``. + ``Delete``, ``Retain``, and ``Snapshot``. Beginning with + ``heat_template_version`` ``2016-10-14``, the lowercase equivalents + ``delete``, ``retain``, and ``snapshot`` are also allowed. + This attribute is optional; the default policy is to delete the physical + resource when deleting a resource from the stack. Depending on the type of resource, the resource block might include more resource specific data. diff --git a/heat/engine/hot/template.py b/heat/engine/hot/template.py index 3fce927d4..da9166500 100644 --- a/heat/engine/hot/template.py +++ b/heat/engine/hot/template.py @@ -404,6 +404,17 @@ class HOTemplate20160408(HOTemplate20151015): class HOTemplate20161014(HOTemplate20160408): + deletion_policies = { + 'Delete': rsrc_defn.ResourceDefinition.DELETE, + 'Retain': rsrc_defn.ResourceDefinition.RETAIN, + 'Snapshot': rsrc_defn.ResourceDefinition.SNAPSHOT, + + # aliases added in 2016-10-14 + 'delete': rsrc_defn.ResourceDefinition.DELETE, + 'retain': rsrc_defn.ResourceDefinition.RETAIN, + 'snapshot': rsrc_defn.ResourceDefinition.SNAPSHOT, + } + functions = { 'get_attr': hot_funcs.GetAttAllAttributes, 'get_file': hot_funcs.GetFile, diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index 6362c8537..28954b156 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -513,6 +513,54 @@ class HOTemplateTest(common.HeatTestCase): {'get_attr': ['rg', 'name']}]} self.assertEqual('', self.resolve(snippet, tmpl, stack)) + def test_deletion_policy_titlecase(self): + hot_tpl = template_format.parse(''' + heat_template_version: 2016-10-14 + resources: + del: + type: OS::Heat::None + deletion_policy: Delete + ret: + type: OS::Heat::None + deletion_policy: Retain + snap: + type: OS::Heat::None + deletion_policy: Snapshot + ''') + + rsrc_defns = template.Template(hot_tpl).resource_definitions(None) + + self.assertEqual(rsrc_defn.ResourceDefinition.DELETE, + rsrc_defns['del'].deletion_policy()) + self.assertEqual(rsrc_defn.ResourceDefinition.RETAIN, + rsrc_defns['ret'].deletion_policy()) + self.assertEqual(rsrc_defn.ResourceDefinition.SNAPSHOT, + rsrc_defns['snap'].deletion_policy()) + + def test_deletion_policy(self): + hot_tpl = template_format.parse(''' + heat_template_version: 2016-10-14 + resources: + del: + type: OS::Heat::None + deletion_policy: delete + ret: + type: OS::Heat::None + deletion_policy: retain + snap: + type: OS::Heat::None + deletion_policy: snapshot + ''') + + rsrc_defns = template.Template(hot_tpl).resource_definitions(None) + + self.assertEqual(rsrc_defn.ResourceDefinition.DELETE, + rsrc_defns['del'].deletion_policy()) + self.assertEqual(rsrc_defn.ResourceDefinition.RETAIN, + rsrc_defns['ret'].deletion_policy()) + self.assertEqual(rsrc_defn.ResourceDefinition.SNAPSHOT, + rsrc_defns['snap'].deletion_policy()) + def test_str_replace(self): """Test str_replace function."""