StackResource add show_deleted option to nested() accessor method

Adds the option to return a stack object even if the stack has been
deleted, which is slightly more convenient when polling for DELETE
COMPLETE state, as you no longer have to handle NotFound when the
delete happens.

Change-Id: I9074bfcec84836cc789cf9f5ecd0a904f020ccb9
blueprint: decouple-nested
This commit is contained in:
Steven Hardy 2014-08-22 16:03:57 +01:00
parent 2a5ec237e3
commit ae4ab1e1ff
2 changed files with 17 additions and 2 deletions

View File

@ -53,11 +53,12 @@ class StackResource(resource.Resource):
self.attributes_schema,
self._resolve_attribute)
def nested(self, force_reload=False):
def nested(self, force_reload=False, show_deleted=False):
'''
Return a Stack object representing the nested (child) stack.
:param force_reload: Forces reloading from the DB instead of returning
the locally cached Stack object
:param show_deleted: Returns the stack even if it's been deleted
'''
if force_reload:
self._nested = None
@ -66,7 +67,7 @@ class StackResource(resource.Resource):
self._nested = parser.Stack.load(self.context,
self.resource_id,
parent_resource=self,
show_deleted=False,
show_deleted=show_deleted,
force_reload=force_reload)
if self._nested is None:

View File

@ -502,6 +502,20 @@ class StackResourceTest(common.HeatTestCase):
self.assertEqual(expected_state,
self.parent_resource.nested(force_reload=True).state)
def test_load_nested_deleted(self):
create_creator = self.parent_resource.create_with_template(
self.templ, {"KeyName": "key"})
create_creator.run_to_completion()
expected_state = (parser.Stack.CREATE, parser.Stack.COMPLETE)
self.assertEqual(expected_state, self.parent_resource.nested().state)
delete_deletor = self.parent_resource.delete_nested()
delete_deletor.run_to_completion()
expected_state = (parser.Stack.DELETE, parser.Stack.COMPLETE)
self.assertEqual(expected_state,
self.parent_resource.nested(force_reload=True,
show_deleted=True).state)
def test_load_nested_non_exist(self):
self.parent_resource.create_with_template(self.templ,
{"KeyName": "key"})