]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
RPC API: Add a PhysicalResourceNotFound exception
authorZane Bitter <zbitter@redhat.com>
Thu, 17 Jan 2013 10:10:15 +0000 (11:10 +0100)
committerZane Bitter <zbitter@redhat.com>
Thu, 17 Jan 2013 10:47:47 +0000 (11:47 +0100)
Change-Id: I409f8df9e93809f7267fb09656302082e42753da
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/api/aws/exception.py
heat/api/openstack/v1/util.py
heat/common/exception.py
heat/engine/service.py
heat/tests/test_api_cfn_v1.py
heat/tests/test_engine_service.py

index 117e468eebce0862b8398dafaaabc384fbd0eaf0..727e104e83a768ed280df2044f3c5f8df118e0a9 100644 (file)
@@ -250,6 +250,7 @@ def map_remote_error(ex):
             'StackNotFound',
             'ResourceNotFound',
             'ResourceNotAvailable',
+            'PhysicalResourceNotFound',
             'StackExists',
         )
 
index a7e7ae0c709fc30d0ef75fa84267062f999a8426..708a28291ab14bb4a2c0c27972b7befba65c5774 100644 (file)
@@ -94,6 +94,7 @@ def remote_error(ex, force_exists=False):
         'StackNotFound': exc.HTTPNotFound,
         'ResourceNotFound': exc.HTTPNotFound,
         'ResourceNotAvailable': exc.HTTPNotFound,
+        'PhysicalResourceNotFound': exc.HTTPNotFound,
         'InvalidTenant': exc.HTTPForbidden,
         'StackExists': exc.HTTPConflict,
     }
index dd3cb0d3fc2d147158fdfeca7f04847aae6da9fc..0b6e7b18b4fbec413d3cef273ef395fa55efdc9e 100644 (file)
@@ -224,3 +224,7 @@ class ResourceNotFound(OpenstackException):
 
 class ResourceNotAvailable(OpenstackException):
     message = _("The Resource (%(resource_name)s) is not available.")
+
+
+class PhysicalResourceNotFound(OpenstackException):
+    message = _("The Resource (%(resource_id)s) could not be found.")
index 34fb17422c31bfcc44a24bc5d38c5d525ed16f06..907808bf9c44345415c3498ade70b9f9426c0781 100644 (file)
@@ -396,8 +396,8 @@ class EngineService(service.Service):
         rs = db_api.resource_get_by_physical_resource_id(context,
                                                          physical_resource_id)
         if not rs:
-            msg = "The specified PhysicalResourceId doesn't exist"
-            raise AttributeError(msg)
+            raise exception.PhysicalResourceNotFound(
+                resource_id=physical_resource_id)
 
         stack = parser.Stack.load(context, stack=rs.stack)
         resource = stack[rs.name]
index 57576cbf90b08143477a43774120fc0af1998ce8..b576e17c4978a22854833d4cd0e8f0651e55c6a3 100644 (file)
@@ -1208,6 +1208,32 @@ class StackControllerTest(unittest.TestCase):
 
         self.assertEqual(response, expected)
 
+    def test_describe_stack_resources_physical_not_found(self):
+        # Format a dummy request
+        stack_name = "wordpress"
+        identity = dict(identifier.HeatIdentifier('t', stack_name, '6'))
+        params = {'Action': 'DescribeStackResources',
+                  'LogicalResourceId': "WikiDatabase",
+                  'PhysicalResourceId': 'aaaaaaaa-9f88-404d-cccc-ffffffffffff'}
+        dummy_req = self._dummy_GET_request(params)
+
+        # Stub out the RPC call to the engine with a pre-canned response
+        self.m.StubOutWithMock(rpc, 'call')
+        rpc.call(dummy_req.context, self.topic,
+                 {'method': 'find_physical_resource',
+                  'args': {'physical_resource_id':
+                           'aaaaaaaa-9f88-404d-cccc-ffffffffffff'},
+                  'version': self.api_version},
+                 None).AndRaise(
+                     rpc_common.RemoteError("PhysicalResourceNotFound"))
+
+        self.m.ReplayAll()
+
+        response = self.controller.describe_stack_resources(dummy_req)
+
+        self.assertEqual(type(response),
+                         exception.HeatInvalidParameterValueError)
+
     def test_describe_stack_resources_err_inval(self):
         # Format a dummy request containing both StackName and
         # PhysicalResourceId, which is invalid and should throw a
index ab4298f5ad68a9eeb1b2ddeede6a573a5d022f94..ac235d127fc89356b966284939c94400a0fafba4 100644 (file)
@@ -640,7 +640,7 @@ class stackServiceTest(unittest.TestCase):
         self.assertEqual(resource_identity.resource_name, 'WebServer')
 
     def test_find_physical_resource_nonexist(self):
-        self.assertRaises(AttributeError,
+        self.assertRaises(exception.PhysicalResourceNotFound,
                           self.man.find_physical_resource,
                           self.ctx, 'foo')