RPC API: Add a ResourceNotAvailable exception

Change-Id: I7f535b7823288b74cbe27f43b645a8d0f3180905
Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2013-01-17 11:10:15 +01:00
parent 9c95aec814
commit d8be4d0c12
7 changed files with 37 additions and 3 deletions

View File

@ -249,6 +249,7 @@ def map_remote_error(ex):
'InvalidTenant',
'StackNotFound',
'ResourceNotFound',
'ResourceNotAvailable',
'StackExists',
)

View 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,
}

View 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.")

View 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})

View 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])

View 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})

View 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,