]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
RPC API: Add a ResourceNotAvailable 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: I7f535b7823288b74cbe27f43b645a8d0f3180905
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/resource.py
heat/engine/service.py
heat/engine/timestamp.py
heat/tests/test_api_openstack_v1.py

index 5ccfa2396263f6d245b759b5e5c0f725d52b323b..117e468eebce0862b8398dafaaabc384fbd0eaf0 100644 (file)
@@ -249,6 +249,7 @@ def map_remote_error(ex):
             'InvalidTenant',
             'StackNotFound',
             'ResourceNotFound',
+            'ResourceNotAvailable',
             'StackExists',
         )
 
index 1cd4b7ada7d2c9c3485135b726455e8d3e6c6d8c..a7e7ae0c709fc30d0ef75fa84267062f999a8426 100644 (file)
@@ -93,6 +93,7 @@ def remote_error(ex, force_exists=False):
         'ValueError': client_error,
         'StackNotFound': exc.HTTPNotFound,
         'ResourceNotFound': exc.HTTPNotFound,
+        'ResourceNotAvailable': exc.HTTPNotFound,
         'InvalidTenant': exc.HTTPForbidden,
         'StackExists': exc.HTTPConflict,
     }
index 9136e529405f21f9f953bcbec879bb4227045125..dd3cb0d3fc2d147158fdfeca7f04847aae6da9fc 100644 (file)
@@ -220,3 +220,7 @@ class StackExists(OpenstackException):
 class ResourceNotFound(OpenstackException):
     message = _("The Resource (%(resource_name)s) could not be found "
                 "in Stack %(stack_name)s.")
+
+
+class ResourceNotAvailable(OpenstackException):
+    message = _("The Resource (%(resource_name)s) is not available.")
index 8ca3f30b43a6c0f0ab8eb4b575f6f0e1cc6658af..aee065f43643a02b4193d115ed20e04eb6be76dc 100644 (file)
@@ -70,7 +70,7 @@ class Metadata(object):
     def __set__(self, resource, metadata):
         '''Update the metadata for the owning resource.'''
         if resource.id is None:
-            raise AttributeError("Resource has not yet been created")
+            raise exception.ResourceNotAvailable(resource_name=resource.name)
         rs = db_api.resource_get(resource.stack.context, resource.id)
         rs.update_and_save({'rsrc_metadata': metadata})
 
index 6ed9371eb3f755e23ca7e5c668b78366224cf9ed..34fb17422c31bfcc44a24bc5d38c5d525ed16f06 100644 (file)
@@ -381,7 +381,7 @@ class EngineService(service.Service):
 
         resource = stack[resource_name]
         if resource.id is None:
-            raise AttributeError('Resource not created')
+            raise exception.ResourceNotAvailable(resource_name=resource_name)
 
         return api.format_stack_resource(stack[resource_name])
 
index c271c5c10dc323be58a3e4032f3791fe665a36f5..c318cbefffc16628d22ff43c8101524705100e3e 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from heat.common import exception
+
 
 class Timestamp(object):
     '''
@@ -42,6 +44,6 @@ class Timestamp(object):
     def __set__(self, obj, timestamp):
         '''Update the timestamp for the given object.'''
         if obj.id is None:
-            raise AttributeError("%s has not yet been created" % str(obj))
+            raise exception.ResourceNotAvailable(resource_name=obj.name)
         o = self.db_fetch(obj.context, obj.id)
         o.update_and_save({self.attribute: timestamp})
index eae72227c4c820b0dff891751b235daf88509b39..436abd04c3e1c9542b5efcbd248bbca916810117 100644 (file)
@@ -1073,6 +1073,32 @@ class ResourceControllerTest(ControllerTest, unittest.TestCase):
                           resource_name=res_name)
         self.m.VerifyAll()
 
+    def test_show_uncreated_resource(self):
+        res_name = 'WikiDatabase'
+        stack_identity = identifier.HeatIdentifier(self.tenant,
+                                                   'wordpress', '1')
+        res_identity = identifier.ResourceIdentifier(resource_name=res_name,
+                                                     **stack_identity)
+
+        req = self._get(res_identity._tenant_path())
+
+        self.m.StubOutWithMock(rpc, 'call')
+        rpc.call(req.context, self.topic,
+                 {'method': 'describe_stack_resource',
+                  'args': {'stack_identity': stack_identity,
+                           'resource_name': res_name},
+                  'version': self.api_version},
+                 None).AndRaise(rpc_common.RemoteError("ResourceNotAvailable"))
+        self.m.ReplayAll()
+
+        self.assertRaises(webob.exc.HTTPNotFound,
+                          self.controller.show,
+                          req, tenant_id=self.tenant,
+                          stack_name=stack_identity.stack_name,
+                          stack_id=stack_identity.stack_id,
+                          resource_name=res_name)
+        self.m.VerifyAll()
+
     def test_metadata_show(self):
         res_name = 'WikiDatabase'
         stack_identity = identifier.HeatIdentifier(self.tenant,