]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Raise the correct error when a stack is not found
authorZane Bitter <zbitter@redhat.com>
Tue, 10 Jul 2012 21:53:58 +0000 (17:53 -0400)
committerZane Bitter <zbitter@redhat.com>
Wed, 11 Jul 2012 15:52:46 +0000 (11:52 -0400)
Change-Id: Ia96d7b96f61e48d20ab080395365e770cf5bb1a8
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/parser.py
heat/tests/test_parser.py

index b0f8d5c65de8d85c31075514a0248d65563aa2f6..e3c02e16cbac8573b3e77d180ac6a01771cf039e 100644 (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)
index 7b809092a92d5fd65ef9e659cca490caa1ce3c01..8ad8ac3fe751ce7f19c46eb360ab72ab48e69fe2 100644 (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__':