Get deletion policy from ResourceDefinition

Change-Id: I5e402e3ed02b9e09d3f78ef3c910c4c3d2f90fc0
This commit is contained in:
Zane Bitter 2014-06-16 11:05:17 -04:00
parent b1af2e5695
commit 5097031f36
4 changed files with 17 additions and 18 deletions

View File

@ -544,7 +544,7 @@ class ResourceFacade(function.Function):
up = self.stack.parent_resource.t.get('UpdatePolicy', {})
return function.resolve(up)
elif attr == self.DELETION_POLICY:
dp = self.stack.parent_resource.t.get('DeletionPolicy', 'Delete')
dp = self.stack.parent_resource.t.deletion_policy()
return function.resolve(dp)

View File

@ -35,8 +35,6 @@ from heat.openstack.common import log as logging
LOG = logging.getLogger(__name__)
DELETION_POLICY = (DELETE, RETAIN, SNAPSHOT) = ('Delete', 'Retain', 'Snapshot')
def get_types(support_status):
'''Return a list of valid resource types.'''
@ -626,18 +624,18 @@ class Resource(object):
LOG.info(_('Validating %s') % str(self))
function.validate(self.t)
self.validate_deletion_policy(self.t)
self.validate_deletion_policy(self.t.deletion_policy())
return self.properties.validate()
@classmethod
def validate_deletion_policy(cls, template):
deletion_policy = template.get('DeletionPolicy', DELETE)
if deletion_policy not in DELETION_POLICY:
msg = _('Invalid DeletionPolicy %s') % deletion_policy
def validate_deletion_policy(cls, policy):
if policy not in rsrc_defn.ResourceDefinition.DELETION_POLICIES:
msg = _('Invalid deletion policy "%s"') % policy
raise exception.StackValidationFailed(message=msg)
elif deletion_policy == SNAPSHOT:
if policy == rsrc_defn.ResourceDefinition.SNAPSHOT:
if not callable(getattr(cls, 'handle_snapshot_delete', None)):
msg = _('Snapshot DeletionPolicy not supported')
msg = _('"%s" deletion policy not supported') % policy
raise exception.StackValidationFailed(message=msg)
def delete(self):
@ -661,20 +659,20 @@ class Resource(object):
self.state_set(action, self.IN_PROGRESS)
if self.abandon_in_progress:
deletion_policy = RETAIN
deletion_policy = self.t.RETAIN
else:
deletion_policy = self.t.get('DeletionPolicy', DELETE)
deletion_policy = self.t.deletion_policy()
handle_data = None
if deletion_policy == DELETE:
if deletion_policy == self.t.DELETE:
if callable(getattr(self, 'handle_delete', None)):
handle_data = self.handle_delete()
yield
elif deletion_policy == SNAPSHOT:
elif deletion_policy == self.t.SNAPSHOT:
if callable(getattr(self, 'handle_snapshot_delete', None)):
handle_data = self.handle_snapshot_delete(initial_state)
yield
if (deletion_policy != RETAIN and
if (deletion_policy != self.t.RETAIN and
callable(getattr(self, 'check_delete_complete', None))):
while not self.check_delete_complete(handle_data):
yield

View File

@ -654,8 +654,9 @@ class EngineService(service.Service):
props = properties.Properties(ResourceClass.properties_schema,
res.get('Properties', {}),
context=cnxt)
deletion_policy = res.get('DeletionPolicy', 'Delete')
try:
ResourceClass.validate_deletion_policy(res)
ResourceClass.validate_deletion_policy(deletion_policy)
props.validate(with_value=False)
except Exception as ex:
return {'Error': six.text_type(ex)}

View File

@ -1020,14 +1020,14 @@ class validateTest(HeatTestCase):
t = template_format.parse(test_template_invalid_deletion_policy)
engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, t, {}))
self.assertEqual({'Error': 'Invalid DeletionPolicy Destroy'}, res)
self.assertEqual({'Error': 'Invalid deletion policy "Destroy"'}, res)
def test_snapshot_deletion_policy(self):
t = template_format.parse(test_template_snapshot_deletion_policy)
engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, t, {}))
self.assertEqual(
{'Error': 'Snapshot DeletionPolicy not supported'}, res)
{'Error': '"Snapshot" deletion policy not supported'}, res)
@skipIf(try_import('cinderclient.v1.volume_backups') is None,
'unable to import volume_backups')