From 5737782c718e84446d8f7f207b3b488ca4473862 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Tue, 10 Jul 2012 17:53:58 -0400 Subject: [PATCH] Raise the correct error when a stack is not found Change-Id: Ia96d7b96f61e48d20ab080395365e770cf5bb1a8 Signed-off-by: Zane Bitter --- heat/engine/parser.py | 3 +++ heat/tests/test_parser.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/heat/engine/parser.py b/heat/engine/parser.py index b0f8d5c6..e3c02e16 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -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) diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index 7b809092..8ad8ac3f 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -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__': -- 2.45.2