Merge "Allow deletion_policy to be lowercase in HOT"

This commit is contained in:
Jenkins 2016-06-09 21:13:10 +00:00 committed by Gerrit Code Review
commit 900e9a32c1
3 changed files with 64 additions and 2 deletions

View File

@ -645,8 +645,11 @@ update_policy
deletion_policy deletion_policy
Deletion policy for the resource. The allowed deletion policies are Deletion policy for the resource. The allowed deletion policies are
``Delete``, ``Retain``, and ``Snapshot``. ``Delete``, ``Retain``, and ``Snapshot``. Beginning with
This attribute is optional; the default policy is ``Delete``. ``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 Depending on the type of resource, the resource block might include more
resource specific data. resource specific data.

View File

@ -404,6 +404,17 @@ class HOTemplate20160408(HOTemplate20151015):
class HOTemplate20161014(HOTemplate20160408): 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 = { functions = {
'get_attr': hot_funcs.GetAttAllAttributes, 'get_attr': hot_funcs.GetAttAllAttributes,
'get_file': hot_funcs.GetFile, 'get_file': hot_funcs.GetFile,

View File

@ -514,6 +514,54 @@ class HOTemplateTest(common.HeatTestCase):
{'get_attr': ['rg', 'name']}]} {'get_attr': ['rg', 'name']}]}
self.assertEqual('', self.resolve(snippet, tmpl, stack)) 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): def test_str_replace(self):
"""Test str_replace function.""" """Test str_replace function."""