Use specific exceptions instead of the general MetadefRecordNotFound
Currently, when metadef namespaces, objects or properties are not found by ID, a general MetadefRecordNotFound exception is raised. Instead, just use the specific MetadefNamespaceNotFound, MetadefObjectNotFound or MetadefPropertyNotFound exceptions. Change-Id: Icb6bf543015305174720f2fd950f5e4984f39798 Closes-Bug: 1367650
This commit is contained in:
parent
aee984ffd7
commit
86657d9a15
|
@ -406,8 +406,3 @@ class MetadefResourceTypeAssociationNotFound(NotFound):
|
|||
" resource-type=%(resource_type_name)s to"
|
||||
" namespace=%(namespace_name)s,"
|
||||
" was not found.")
|
||||
|
||||
|
||||
class MetadefRecordNotFound(NotFound):
|
||||
message = _("Metadata definition %(record_type)s record not found"
|
||||
" for id %(id)s.")
|
||||
|
|
|
@ -1101,10 +1101,10 @@ def metadef_namespace_get_by_id(context, namespace_id):
|
|||
namespace = next(namespace for namespace in DATA['metadef_namespaces']
|
||||
if namespace['id'] == namespace_id)
|
||||
except StopIteration:
|
||||
msg = "No namespace found with id %s" % namespace_id
|
||||
LOG.debug(msg)
|
||||
raise exception.MetadefRecordNotFound(
|
||||
record_type='namespace', id=namespace_id)
|
||||
msg = (_("Metadata definition namespace not found for id=%s")
|
||||
% namespace_id)
|
||||
LOG.warn(msg)
|
||||
raise exception.MetadefNamespaceNotFound(msg)
|
||||
|
||||
if not _is_namespace_visible(context, namespace):
|
||||
msg = ("Forbidding request, metadata definition namespace=%s"
|
||||
|
@ -1235,11 +1235,10 @@ def metadef_object_get_by_id(context, namespace_name, object_id):
|
|||
object['id'] == object_id):
|
||||
return object
|
||||
else:
|
||||
msg = ("No metadata definition object found with id %s"
|
||||
msg = (_("Metadata definition object not found for id=%s")
|
||||
% object_id)
|
||||
LOG.debug(msg)
|
||||
raise exception.MetadefRecordNotFound(record_type='object',
|
||||
id=object_id)
|
||||
LOG.warn(msg)
|
||||
raise exception.MetadefObjectNotFound(msg)
|
||||
|
||||
|
||||
@log_call
|
||||
|
@ -1485,11 +1484,10 @@ def metadef_property_get_by_id(context, namespace_name, property_id):
|
|||
property['id'] == property_id):
|
||||
return property
|
||||
else:
|
||||
msg = ("No metadata definition property found with id=%s"
|
||||
msg = (_("Metadata definition property not found for id=%s")
|
||||
% property_id)
|
||||
LOG.debug(msg)
|
||||
raise exception.MetadefRecordNotFound(record_type='property',
|
||||
id=property_id)
|
||||
LOG.warn(msg)
|
||||
raise exception.MetadefPropertyNotFound(msg)
|
||||
|
||||
|
||||
@log_call
|
||||
|
|
|
@ -86,10 +86,10 @@ def _get(context, namespace_id, session):
|
|||
.filter_by(id=namespace_id)
|
||||
namespace_rec = query.one()
|
||||
except sa_orm.exc.NoResultFound:
|
||||
msg = _LW("Metadata definition namespace not found for id=%s")
|
||||
LOG.warn(msg % namespace_id)
|
||||
raise exc.MetadefRecordNotFound(record_type='namespace',
|
||||
id=namespace_id)
|
||||
msg = (_("Metadata definition namespace not found for id=%s")
|
||||
% namespace_id)
|
||||
LOG.warn(msg)
|
||||
raise exc.MetadefNamespaceNotFound(msg)
|
||||
|
||||
# Make sure they are allowed to view it.
|
||||
if not _is_namespace_visible(context, namespace_rec.as_dict()):
|
||||
|
|
|
@ -34,9 +34,10 @@ def _get(context, object_id, session):
|
|||
.filter_by(id=object_id)
|
||||
metadef_object = query.one()
|
||||
except sa_orm.exc.NoResultFound:
|
||||
msg = _LW("Metadata definition object not found for id %s")
|
||||
LOG.warn(msg % object_id)
|
||||
raise exc.MetadefRecordNotFound(record_type='object', id=object_id)
|
||||
msg = (_("Metadata definition object not found for id %s")
|
||||
% object_id)
|
||||
LOG.warn(msg)
|
||||
raise exc.MetadefObjectNotFound(msg)
|
||||
|
||||
return metadef_object
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ def _get(context, property_id, session):
|
|||
property_rec = query.one()
|
||||
|
||||
except sa_orm.exc.NoResultFound:
|
||||
msg = _LW("Metadata definition property not found for id=%s")
|
||||
LOG.warn(msg % property_id)
|
||||
raise exc.MetadefRecordNotFound(
|
||||
record_type='property', id=property_id)
|
||||
msg = (_("Metadata definition property not found for id=%s")
|
||||
% property_id)
|
||||
LOG.warn(msg)
|
||||
raise exc.MetadefPropertyNotFound(msg)
|
||||
|
||||
return property_rec
|
||||
|
||||
|
|
Loading…
Reference in New Issue