Raise the correct error when a stack is not found

Change-Id: Ia96d7b96f61e48d20ab080395365e770cf5bb1a8
Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter
2012-07-10 17:53:58 -04:00
parent 57a71eb07d
commit 5737782c71
2 changed files with 6 additions and 0 deletions

View File

@@ -273,6 +273,9 @@ class Stack(object):
def load(cls, context, stack_id):
'''Retrieve a Stack from the database'''
s = db_api.stack_get(context, stack_id)
if s is None:
message = 'No stack exists with id "%s"' % str(stack_id)
raise exception.NotFound(message)
template = Template.load(context, s.raw_template_id)
params = Parameters(s.name, template, s.parameters)

View File

@@ -337,6 +337,9 @@ class StackTest(unittest.TestCase):
stack.state_set('blarg', 'wibble')
self.assertEqual(stack.state_description, 'wibble')
def test_load_nonexistant_id(self):
self.assertRaises(exception.NotFound, parser.Stack.load,
None, -1)
# allows testing of the test directly, shown below
if __name__ == '__main__':