diff --git a/doc/source/template_guide/hot_spec.rst b/doc/source/template_guide/hot_spec.rst index 3ebd70fdd..b645ef855 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 9079d4082..63c4dd9e7 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -514,6 +514,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."""