Refactor catching exception at services controller level
Change-Id: I17ba7b9f1142b9bc52e3facc0813cf962ecf87c0
This commit is contained in:
parent
6b91d346a4
commit
aa15e29fb3
@ -49,9 +49,8 @@ class RegionRoleController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(
|
||||
request.transaction_id,
|
||||
status_code=409,
|
||||
message='Duplicate Entry-Group Region Roles already assigned.',
|
||||
error_details=exception.message)
|
||||
status_code=409.2,
|
||||
message=exception.message)
|
||||
|
||||
except ErrorStatus as exception:
|
||||
LOG.log_exception(
|
||||
@ -64,6 +63,6 @@ class RegionRoleController(rest.RestController):
|
||||
"Exception - Failed in assign roles for region.", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
return result
|
||||
|
@ -6,7 +6,7 @@ from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils import utils
|
||||
from orm.services.customer_manager.cms_rest.logger import get_logger
|
||||
from orm.common.orm_common.utils.error_base import \
|
||||
ErrorStatus, NotFoundError
|
||||
ErrorStatus, NotFoundError, ConflictError
|
||||
from orm.services.customer_manager.cms_rest.logic.group_logic import GroupLogic
|
||||
from orm.services.customer_manager.cms_rest.model.GroupModels import \
|
||||
RegionUser, RegionUserResultWrapper
|
||||
@ -44,17 +44,15 @@ class RegionUserController(rest.RestController):
|
||||
group_id,
|
||||
event_details=event_details)
|
||||
|
||||
except DBDuplicateEntry as exception:
|
||||
except (ConflictError, DBDuplicateEntry) as exception:
|
||||
LOG.log_exception(
|
||||
"DBDuplicateEntry - Group users already assigned.", exception)
|
||||
print(exception.message)
|
||||
"Duplicate Entry - Group users already assigned.", exception)
|
||||
raise err_utils.get_error(
|
||||
request.transaction_id,
|
||||
status_code=409,
|
||||
message='Duplicate Entry - Group users already assigned.',
|
||||
error_details=exception.message)
|
||||
status_code=409.2,
|
||||
message=exception.message)
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception(
|
||||
"ErrorStatus - Failed to add users", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -65,7 +63,7 @@ class RegionUserController(rest.RestController):
|
||||
"Exception - Failed in add region users", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
return result
|
||||
|
||||
@ -115,4 +113,4 @@ class RegionUserController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
@ -3,7 +3,7 @@ from pecan import request, rest
|
||||
from wsmeext.pecan import wsexpose
|
||||
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus, NotFoundError
|
||||
from orm.common.orm_common.utils import utils
|
||||
from orm.services.customer_manager.cms_rest.controllers.v1.orm.group.\
|
||||
region_roles import RegionRoleController
|
||||
@ -52,11 +52,10 @@ class RegionController(rest.RestController):
|
||||
LOG.log_exception(
|
||||
"RegionController - Group Region already exists", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=409,
|
||||
message='Region already exists',
|
||||
error_details=str(exception))
|
||||
status_code=409.2,
|
||||
message=str(exception))
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception(
|
||||
"RegionController - Failed to add regions", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -67,7 +66,7 @@ class RegionController(rest.RestController):
|
||||
"RegionController - Failed in add regions", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
return result
|
||||
|
||||
@ -100,7 +99,7 @@ class RegionController(rest.RestController):
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=str(exception),
|
||||
status_code=404)
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("RegionController - Failed to delete region",
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -111,4 +110,4 @@ class RegionController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
@ -3,7 +3,8 @@ from pecan import request, rest
|
||||
from wsmeext.pecan import wsexpose
|
||||
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus
|
||||
from orm.common.orm_common.utils.error_base import \
|
||||
ErrorStatus, InputValueError, NotFoundError, NotAllowedError
|
||||
from orm.common.orm_common.utils import utils
|
||||
from orm.services.customer_manager.cms_rest.logger import get_logger
|
||||
from orm.services.customer_manager.cms_rest.logic.group_logic import GroupLogic
|
||||
@ -45,9 +46,8 @@ class RoleController(rest.RestController):
|
||||
"DBDuplicateEntry - Group Roles already assigned.", exception)
|
||||
raise err_utils.get_error(
|
||||
request.transaction_id,
|
||||
status_code=409,
|
||||
message='Duplicate Entry - Group Roles already assigned.',
|
||||
error_details=exception.message)
|
||||
status_code=409.2,
|
||||
message=exception.message)
|
||||
|
||||
except ErrorStatus as exception:
|
||||
LOG.log_exception(
|
||||
@ -60,7 +60,7 @@ class RoleController(rest.RestController):
|
||||
"Exception - Failed in assign roles", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
return result
|
||||
|
||||
@ -92,11 +92,11 @@ class RoleController(rest.RestController):
|
||||
group_id,
|
||||
event_details=event_details)
|
||||
|
||||
except ValueError as exception:
|
||||
except (InputValueError, ValueError) as exception:
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=str(exception),
|
||||
status_code=404)
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("ErrorStatus - Failed to unassign roles",
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -107,7 +107,7 @@ class RoleController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose([RoleResult], str, str, str, str, rest_content_types='json')
|
||||
def get_all(self, group_id, region=None, customer=None, domain=None):
|
||||
@ -121,7 +121,7 @@ class RoleController(rest.RestController):
|
||||
customer,
|
||||
domain)
|
||||
return result
|
||||
except ErrorStatus as exception:
|
||||
except (NotAllowedError, ErrorStatus) as exception:
|
||||
LOG.log_exception("RoleController - Failed to GetRolelist",
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -133,4 +133,4 @@ class RoleController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
@ -3,7 +3,8 @@ import oslo_db
|
||||
from wsmeext.pecan import wsexpose
|
||||
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus
|
||||
from orm.common.orm_common.utils.error_base \
|
||||
import ErrorStatus, NotFoundError, NotAllowedError
|
||||
from orm.common.orm_common.utils import utils
|
||||
from orm.services.customer_manager.cms_rest.controllers.v1.orm.group.regions \
|
||||
import RegionController
|
||||
@ -35,7 +36,7 @@ class GroupController(rest.RestController):
|
||||
LOG.info(
|
||||
"GroupController - GetGroupDetails finished: " + str(result))
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("GroupController - Failed to GetGroupDetails",
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -47,7 +48,7 @@ class GroupController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=exception.message)
|
||||
message=exception.message)
|
||||
return result
|
||||
|
||||
@wsexpose(GroupResultWrapper, body=Group, rest_content_types='json',
|
||||
@ -112,7 +113,7 @@ class GroupController(rest.RestController):
|
||||
request.headers, group_uuid,
|
||||
event_details=event_details)
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("Failed in UpdateGroup", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exception.message,
|
||||
@ -123,7 +124,7 @@ class GroupController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=exception.message)
|
||||
message=exception.message)
|
||||
|
||||
return result
|
||||
|
||||
@ -145,7 +146,7 @@ class GroupController(rest.RestController):
|
||||
start,
|
||||
limit)
|
||||
return result
|
||||
except ErrorStatus as exception:
|
||||
except (NotAllowedError, ErrorStatus) as exception:
|
||||
LOG.log_exception("GroupController - Failed to GetGrouplist",
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -156,7 +157,7 @@ class GroupController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=exception.message)
|
||||
message=exception.message)
|
||||
|
||||
@wsexpose(None, str, rest_content_types='json', status_code=204)
|
||||
def delete(self, group_uuid):
|
||||
@ -173,7 +174,7 @@ class GroupController(rest.RestController):
|
||||
request.headers, group_uuid,
|
||||
event_details=event_details)
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (ErrorStatus, NotAllowedError, NotFoundError) as exception:
|
||||
LOG.log_exception("GroupController - Failed to DeleteGroup",
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -185,4 +186,4 @@ class GroupController(rest.RestController):
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=exception.message)
|
||||
message=exception.message)
|
||||
|
@ -5,7 +5,8 @@ from wsmeext.pecan import wsexpose
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils import utils
|
||||
from orm.services.customer_manager.cms_rest.logger import get_logger
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus, NotFoundError
|
||||
from orm.common.orm_common.utils.error_base import \
|
||||
ErrorStatus, NotFoundError, ConflictError
|
||||
from orm.services.customer_manager.cms_rest.logic.group_logic import GroupLogic
|
||||
from orm.services.customer_manager.cms_rest.model.GroupModels import \
|
||||
User, UserResultWrapper
|
||||
@ -42,17 +43,15 @@ class UserController(rest.RestController):
|
||||
group_id,
|
||||
event_details=event_details)
|
||||
|
||||
except DBDuplicateEntry as exception:
|
||||
except (ConflictError, DBDuplicateEntry) as exception:
|
||||
LOG.log_exception(
|
||||
"DBDuplicateEntry - Group users already assigned.", exception)
|
||||
print(exception.message)
|
||||
raise err_utils.get_error(
|
||||
request.transaction_id,
|
||||
status_code=409,
|
||||
message='Duplicate Entry - Group users already assigned.',
|
||||
error_details=exception.message)
|
||||
status_code=409.2,
|
||||
message=exception.message)
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception(
|
||||
"ErrorStatus - Failed to add users", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
@ -63,7 +62,7 @@ class UserController(rest.RestController):
|
||||
"Exception - Failed in add default users", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
return result
|
||||
|
||||
@ -94,21 +93,17 @@ class UserController(rest.RestController):
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=str(exception),
|
||||
status_code=404)
|
||||
except ErrorStatus as exception:
|
||||
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("ErrorStatus - Failed to delete user from group",
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exception.message,
|
||||
status_code=exception.status_code)
|
||||
|
||||
except NotFoundError as e:
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=e.message,
|
||||
status_code=404)
|
||||
|
||||
except Exception as exception:
|
||||
LOG.log_exception("Exception - Failed in delete default user",
|
||||
exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
@ -421,8 +421,8 @@ class GroupLogic(object):
|
||||
try:
|
||||
group = datamanager.get_group_by_uuid_or_name(group_uuid)
|
||||
if group is None:
|
||||
raise NotFoundStatus("group {} does not exist".format(
|
||||
group_uuid))
|
||||
raise NotFoundError("group {} does not exist".format(
|
||||
group_uuid))
|
||||
user_record = datamanager.get_record('groups_user')
|
||||
result = user_record.remove_user_from_group(group_uuid, region_id,
|
||||
user_domain, user)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from orm.common.orm_common.injector import injector
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus, NotFoundError, ConflictError
|
||||
from orm.services.image_manager.ims.logger import get_logger
|
||||
from orm.services.image_manager.ims.persistency.wsme.models import CustomerWrapper, ImageWrapper
|
||||
from orm.services.image_manager.ims.utils import authentication as auth
|
||||
@ -35,7 +35,7 @@ class CustomerController(rest.RestController):
|
||||
event_details=event_details)
|
||||
return result
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus, ConflictError) as exception:
|
||||
LOG.log_exception("TenantController - Failed to add tenants", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exception.message,
|
||||
@ -44,7 +44,7 @@ class CustomerController(rest.RestController):
|
||||
LOG.log_exception("TenantController - Failed to add tenants", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(ImageWrapper, str, body=CustomerWrapper, rest_content_types='json', status_code=200)
|
||||
def put(self, image_id, cust_wrapper):
|
||||
@ -64,7 +64,7 @@ class CustomerController(rest.RestController):
|
||||
event_details=event_details)
|
||||
return result
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus, ConflictError) as exception:
|
||||
LOG.log_exception("TenantController - Failed to replace tenants", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exception.message,
|
||||
@ -73,7 +73,7 @@ class CustomerController(rest.RestController):
|
||||
LOG.log_exception("TenantController - Failed to replace tenants", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(None, str, str, rest_content_types='json', status_code=204)
|
||||
def delete(self, image_id, cust_id):
|
||||
@ -93,7 +93,7 @@ class CustomerController(rest.RestController):
|
||||
request.headers, image_id,
|
||||
event_details=event_details)
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("TenantController - Failed to delete tenant", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exception.message,
|
||||
@ -102,4 +102,4 @@ class CustomerController(rest.RestController):
|
||||
LOG.log_exception("TenantController - Failed to delete tenant", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from orm.common.orm_common.injector import injector
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus, NotFoundError
|
||||
from orm.services.image_manager.ims.logger import get_logger
|
||||
from orm.services.image_manager.ims.persistency.wsme.models import Enabled, ImageWrapper
|
||||
from orm.services.image_manager.ims.utils import authentication as auth
|
||||
@ -39,7 +39,7 @@ class EnabledController(rest.RestController):
|
||||
event_details=event_details)
|
||||
return result
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("Failed in EnableImage", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exception.message,
|
||||
@ -49,26 +49,14 @@ class EnabledController(rest.RestController):
|
||||
LOG.log_exception("Failed in EnableImage", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(None, str, body=Enabled, rest_content_types='json',
|
||||
status_code=200)
|
||||
@wsexpose(None, str, body=Enabled, rest_content_types='json')
|
||||
def post(self, image_id, enabled):
|
||||
image_logic, utils = di.resolver.unpack(EnabledController)
|
||||
auth.authorize(request, "image:enable")
|
||||
try:
|
||||
LOG.debug("method not allowed only put allowed")
|
||||
raise ErrorStatus("Method not allowed, only 'put' method allowed")
|
||||
return None
|
||||
|
||||
except ErrorStatus as exception:
|
||||
LOG.log_exception("Failed in EnableImage", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exception.message,
|
||||
status_code=exception.status_code)
|
||||
|
||||
except Exception as exception:
|
||||
LOG.log_exception("Failed in EnableImage", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message = "Post method not allowed to enable image"
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=message,
|
||||
status_code=405)
|
||||
|
@ -2,7 +2,7 @@ import oslo_db
|
||||
|
||||
from orm.common.orm_common.injector import injector
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ConflictError, ErrorStatus, NotFoundError
|
||||
from orm.common.orm_common.utils.error_base import ConflictError, ErrorStatus, NotFoundError, NotAllowedError
|
||||
from orm.services.image_manager.ims.controllers.v1.orm.images.customers import CustomerController
|
||||
from orm.services.image_manager.ims.controllers.v1.orm.images.enabled import EnabledController
|
||||
from orm.services.image_manager.ims.controllers.v1.orm.images.regions import RegionController
|
||||
@ -38,7 +38,7 @@ class ImageController(rest.RestController):
|
||||
if invalid_extra_param:
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message="URL has invalid extra param '{}' ".format(invalid_extra_param),
|
||||
status_code=405)
|
||||
status_code=400)
|
||||
try:
|
||||
LOG.info("ImageController - Create image: " + str(image_wrapper.image.name))
|
||||
image_wrapper.image.owner = request.headers.get('X-RANGER-Owner') or ''
|
||||
@ -77,7 +77,7 @@ class ImageController(rest.RestController):
|
||||
LOG.log_exception("ImageController - Failed to CreateImage", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(ImageWrapper, str, body=ImageWrapper, rest_content_types='json', status_code=200)
|
||||
def put(self, image_id, image_wrapper):
|
||||
@ -113,7 +113,7 @@ class ImageController(rest.RestController):
|
||||
LOG.log_exception("ImageController - Failed to UpdateImage", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(ImageWrapper, str, str, str, str, str, rest_content_types='json')
|
||||
def get(self, image_uuid):
|
||||
@ -135,7 +135,7 @@ class ImageController(rest.RestController):
|
||||
LOG.log_exception("ImageController - Failed to GetImageDetails", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(ImageSummaryResponse, str, str, str, rest_content_types='json')
|
||||
def get_all(self, visibility=None, region=None, customer=None):
|
||||
@ -158,7 +158,7 @@ class ImageController(rest.RestController):
|
||||
LOG.log_exception("ImageController - Failed to GetImagelist", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(None, str, rest_content_types='json', status_code=204)
|
||||
def delete(self, image_uuid):
|
||||
@ -175,7 +175,7 @@ class ImageController(rest.RestController):
|
||||
request.headers, image_uuid,
|
||||
event_details=event_details)
|
||||
|
||||
except (ErrorStatus, NotFoundError) as exp:
|
||||
except (ErrorStatus, NotFoundError, NotAllowedError) as exp:
|
||||
LOG.log_exception("ImageController - Failed to delete image", exp)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=str(exp),
|
||||
@ -185,7 +185,7 @@ class ImageController(rest.RestController):
|
||||
LOG.log_exception("ImageController - Failed to delete image", exp)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exp))
|
||||
message=str(exp))
|
||||
|
||||
'''
|
||||
@expose()
|
||||
|
@ -29,19 +29,14 @@ class MetadataController(rest.RestController):
|
||||
LOG.info("MetadataController - metadata added")
|
||||
return "OK"
|
||||
|
||||
except NotFoundError as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.error("MetadataController - failed to add metadata: ", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=str(exception),
|
||||
status_code=exception.status_code)
|
||||
|
||||
except ErrorStatus as exception:
|
||||
LOG.error("MetadataController - Failed to add metadata", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=str(exception),
|
||||
status_code=exception.status_code)
|
||||
except Exception as exception:
|
||||
LOG.error("MetadataController - Failed to add metadata", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
@ -46,7 +46,7 @@ class RegionController(rest.RestController):
|
||||
event_details=event_details)
|
||||
return result
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("RegionController - Failed to add region", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=str(exception),
|
||||
@ -55,7 +55,7 @@ class RegionController(rest.RestController):
|
||||
LOG.log_exception("RegionController - Failed to add region", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(RegionWrapper, str, body=RegionWrapper, rest_content_types='json', status_code=200)
|
||||
def put(self, image_id, region_wrapper): # add regions to image
|
||||
@ -77,7 +77,7 @@ class RegionController(rest.RestController):
|
||||
event_details=event_details)
|
||||
return result
|
||||
|
||||
except ErrorStatus as exception:
|
||||
except (NotFoundError, ErrorStatus) as exception:
|
||||
LOG.log_exception("RegionController - Failed to replace region", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=str(exception),
|
||||
@ -86,7 +86,7 @@ class RegionController(rest.RestController):
|
||||
LOG.log_exception("RegionController - Failed to replace region", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(None, str, str, str, rest_content_types='json', status_code=204)
|
||||
def delete(self, image_id, region_name, force_delete='False'):
|
||||
@ -117,4 +117,4 @@ class RegionController(rest.RestController):
|
||||
LOG.log_exception("RegionController - Failed to delete region", exception)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
@ -345,7 +345,7 @@ def add_customers(image_uuid, customers, transaction_id):
|
||||
except Exception as exp:
|
||||
if 'conflicts with persistent instance' in str(exp) or \
|
||||
'Duplicate entry' in str(exp):
|
||||
raise ErrorStatus("Duplicate Customer for Image")
|
||||
raise ConflictError("Duplicate Customer for Image")
|
||||
LOG.log_exception("ImageLogic - Failed to add Customers", exp)
|
||||
datamanager.rollback()
|
||||
raise
|
||||
@ -363,7 +363,7 @@ def replace_customers(image_uuid, customers, transaction_id):
|
||||
raise NotFoundError('image {0} not found'.format(image_uuid))
|
||||
|
||||
if sql_image.visibility != "shared":
|
||||
raise ValueError('Customer can only be replaced with shared Image')
|
||||
raise ErrorStatus('Customer can only be replaced with shared Image')
|
||||
|
||||
existing_region_names = sql_image.get_existing_region_names()
|
||||
sql_image.remove_all_customers()
|
||||
@ -384,8 +384,8 @@ def replace_customers(image_uuid, customers, transaction_id):
|
||||
except Exception as exp:
|
||||
if 'conflicts with persistent instance' in str(exp) or \
|
||||
'Duplicate entry' in str(exp):
|
||||
raise ConflictError("Duplicate Customer for Image")
|
||||
LOG.log_exception("ImageLogic - Failed to add Customers", exp)
|
||||
raise ConflictError("Duplicate customer for image")
|
||||
LOG.log_exception("ImageLogic - Failed to replace customers", exp)
|
||||
datamanager.rollback()
|
||||
raise
|
||||
|
||||
@ -402,7 +402,7 @@ def delete_customer(image_uuid, customer_id, transaction_id):
|
||||
raise NotFoundError('image {0} not found'.format(image_uuid))
|
||||
|
||||
if sql_image.visibility != "shared":
|
||||
raise ValueError(
|
||||
raise ErrorStatus(
|
||||
"Customer can only be deleted from shared image {}".format(
|
||||
image_uuid))
|
||||
|
||||
@ -579,11 +579,10 @@ def enable_image(image_uuid, int_enabled, transaction_id):
|
||||
image_uuid))
|
||||
|
||||
sql_image.enabled = int_enabled
|
||||
|
||||
existing_region_names = sql_image.get_existing_region_names()
|
||||
|
||||
datamanager.flush() # i want to get any exception created by this
|
||||
# insert method
|
||||
# Flush to see if there is any exception
|
||||
datamanager.flush()
|
||||
|
||||
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
||||
transaction_id)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus, NotFoundError
|
||||
from orm.services.region_manager.rms.model import url_parm
|
||||
from orm.services.region_manager.rms.services import services
|
||||
from orm.services.region_manager.rms.utils import authentication
|
||||
@ -36,7 +36,7 @@ class LcpController(rest.RestController):
|
||||
logger.error(str(exception))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(wtypes.text, str, rest_content_types='json')
|
||||
def get_one(self, lcp_id):
|
||||
@ -53,7 +53,7 @@ class LcpController(rest.RestController):
|
||||
logger.error(str(exception))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
for zone in zones:
|
||||
if zone["id"] == lcp_id:
|
||||
@ -88,7 +88,7 @@ def get_zones():
|
||||
logger.debug("Available regions: {}".format(', '.join(
|
||||
[region["zone_name"] for region in result])))
|
||||
|
||||
except ErrorStatus as e:
|
||||
except (NotFoundError, ErrorStatus) as e:
|
||||
logger.debug(e.message)
|
||||
finally:
|
||||
return result
|
||||
|
@ -59,7 +59,7 @@ class LogsController(rest.RestController):
|
||||
str(exception)))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@staticmethod
|
||||
def _change_log_level(log_level):
|
||||
|
@ -3,7 +3,8 @@ import logging
|
||||
import wsme
|
||||
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus, NotFoundError
|
||||
from orm.common.orm_common.utils.error_base import \
|
||||
ErrorStatus, NotFoundError, ConflictError, InputValueError
|
||||
from orm.common.orm_common.utils import utils
|
||||
from orm.services.region_manager.rms.model import model as PythonModel
|
||||
from orm.services.region_manager.rms.services import services as GroupService
|
||||
@ -135,7 +136,7 @@ class GroupsController(rest.RestController):
|
||||
logger.error(exception.message)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=exception.message)
|
||||
message=exception.message)
|
||||
|
||||
@wsexpose(GroupWrapper, status_code=200, rest_content_types='json')
|
||||
def get_all(self):
|
||||
@ -152,7 +153,7 @@ class GroupsController(rest.RestController):
|
||||
logger.exception(exp)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=exception.message)
|
||||
message=exception.message)
|
||||
|
||||
return groups_wrraper
|
||||
|
||||
@ -192,7 +193,7 @@ class GroupsController(rest.RestController):
|
||||
event_details=event_details)
|
||||
return Result(group)
|
||||
|
||||
except (NotFoundError, ErrorStatus) as e:
|
||||
except (NotFoundError, InputValueError, ErrorStatus, ConflictError) as e:
|
||||
logger.error("GroupsController :- {}".format(e.message))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=e.message,
|
||||
@ -201,7 +202,7 @@ class GroupsController(rest.RestController):
|
||||
logger.error(exception.message)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=exception.message)
|
||||
message=exception.message)
|
||||
|
||||
@wsexpose(None, str, status_code=204, rest_content_types='json')
|
||||
def delete(self, group_id):
|
||||
@ -231,7 +232,7 @@ class GroupsController(rest.RestController):
|
||||
logger.exception("Failed to delete group :- {}".format(exp))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=exp.message)
|
||||
message=exp.message)
|
||||
return
|
||||
|
||||
@wsexpose(Result, str, body=Groups, status_code=201,
|
||||
|
@ -2,7 +2,7 @@ import json
|
||||
import logging
|
||||
|
||||
from orm.common.orm_common.utils import api_error_utils as err_utils
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus
|
||||
from orm.common.orm_common.utils.error_base import ErrorStatus, NotFoundError
|
||||
from orm.common.orm_common.utils import utils
|
||||
from orm.services.region_manager.rms.services import services as RegionService
|
||||
from orm.services.region_manager.rms.utils import authentication
|
||||
@ -41,7 +41,7 @@ class RegionMetadataController(rest.RestController):
|
||||
logger.debug("Got region metadata: {}".format(region.metadata))
|
||||
return MetaData(region.metadata)
|
||||
|
||||
except ErrorStatus as exp:
|
||||
except (NotFoundError, ErrorStatus) as exp:
|
||||
logger.error("RegionsController - {}".format(exp.message))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exp.message,
|
||||
@ -50,7 +50,7 @@ class RegionMetadataController(rest.RestController):
|
||||
logger.exception(str(exp))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exp))
|
||||
message=str(exp))
|
||||
|
||||
@wsexpose(MetaData, str, body=MetaData, status_code=201,
|
||||
rest_content_types='json')
|
||||
@ -78,7 +78,7 @@ class RegionMetadataController(rest.RestController):
|
||||
event_details=event_details)
|
||||
return MetaData(result)
|
||||
|
||||
except ErrorStatus as e:
|
||||
except (NotFoundError, ErrorStatus) as e:
|
||||
logger.error(e.message)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=e.message,
|
||||
@ -87,7 +87,7 @@ class RegionMetadataController(rest.RestController):
|
||||
logger.error(str(exception))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(MetaData, str, body=MetaData, status_code=201,
|
||||
rest_content_types='json')
|
||||
@ -115,7 +115,7 @@ class RegionMetadataController(rest.RestController):
|
||||
event_details=event_details)
|
||||
return MetaData(result)
|
||||
|
||||
except ErrorStatus as e:
|
||||
except (NotFoundError, ErrorStatus) as e:
|
||||
logger.error(e.message)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=e.message,
|
||||
@ -124,7 +124,7 @@ class RegionMetadataController(rest.RestController):
|
||||
logger.error(str(exception))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
@wsexpose(None, str, str, status_code=204, rest_content_types='json')
|
||||
def delete(self, region_id, metadata_key):
|
||||
@ -158,7 +158,7 @@ class RegionMetadataController(rest.RestController):
|
||||
logger.error(str(exception))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(exception))
|
||||
message=str(exception))
|
||||
|
||||
def _validate_request_input(self):
|
||||
data_dict = json.loads(request.body)
|
||||
|
@ -238,7 +238,7 @@ class RegionsController(rest.RestController):
|
||||
|
||||
return result
|
||||
|
||||
except ErrorStatus as exp:
|
||||
except (NotFoundError, ErrorStatus) as exp:
|
||||
logger.error("RegionsController {}".format(exp.message))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
message=exp.message,
|
||||
|
@ -82,7 +82,7 @@ class RegionStatusController(rest.RestController):
|
||||
logger.error(str(e))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(e))
|
||||
message=str(e))
|
||||
|
||||
@wsexpose(str, str, rest_content_types='json')
|
||||
def get(self, region_id):
|
||||
|
@ -43,13 +43,13 @@ class UUIDController(rest.RestController):
|
||||
"Failed to get uuid : {}".format(str(ex)))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(ex))
|
||||
message=str(ex))
|
||||
|
||||
if resp.status_code != 200:
|
||||
message = "Failed to uuid {}: {}".format(uuid, resp.text)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=resp.status_code,
|
||||
error_details=message)
|
||||
message=message)
|
||||
|
||||
uuid_data = json.loads(resp.content)
|
||||
return UUIDData(id=str(uuid_data['id']),
|
||||
@ -79,11 +79,11 @@ class UUIDController(rest.RestController):
|
||||
"Failed to delete uuid : {}".format(str(ex)))
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=500,
|
||||
error_details=str(ex))
|
||||
message=str(ex))
|
||||
|
||||
if resp.status_code != 200:
|
||||
message = "Failed to delete uuid {}: {}".format(uuid, resp.text)
|
||||
raise err_utils.get_error(request.transaction_id,
|
||||
status_code=resp.status_code,
|
||||
error_details=message)
|
||||
message=message)
|
||||
return
|
||||
|
@ -107,7 +107,7 @@ def _notify(ord_url,
|
||||
if token_id:
|
||||
headers['X-Auth-Token'] = token_id
|
||||
else:
|
||||
logger.info('Failed get_token for region %s' % (region_id))
|
||||
logger.error('Failed get_token for region %s' % (region_id))
|
||||
raise NoTokenError
|
||||
|
||||
# Prepare the request body
|
||||
@ -161,7 +161,7 @@ def _notify(ord_url,
|
||||
cert=conf.ordupdate.cert_path)
|
||||
|
||||
except requests.exceptions.SSLError:
|
||||
logger.debug('Received an SSL error (is the certificate valid?)')
|
||||
logger.error('Received an SSL error (is the certificate valid?)')
|
||||
raise
|
||||
else:
|
||||
if is_ord_url_https:
|
||||
@ -173,10 +173,10 @@ def _notify(ord_url,
|
||||
files=files,
|
||||
headers=headers)
|
||||
|
||||
# Make sure the ORD sent an ACK
|
||||
# Verify if Ranger Agent sent the expected ACK
|
||||
if response.status_code != ACK_CODE:
|
||||
message = 'Did not receive an ACK from ORD %s, status code: %d' % (
|
||||
ord_url, response.status_code, )
|
||||
message = 'Received error response code (%d) from Ranger Agent %s' % (
|
||||
response.status_code, ord_url)
|
||||
encoded_message = message.replace('\n', '_').replace('\r', '_')
|
||||
if encoded_message != message:
|
||||
encoded_message = encoded_message + "(encoded)"
|
||||
@ -306,7 +306,6 @@ def notify_ord(transaction_id,
|
||||
resource_template_data
|
||||
)
|
||||
|
||||
# All OK
|
||||
event_details = '%s notified' % (region_id, )
|
||||
status = 'Success'
|
||||
except NoTokenError:
|
||||
@ -314,10 +313,16 @@ def notify_ord(transaction_id,
|
||||
status = 'GET Token Error'
|
||||
error_msg = 'Failed to get token for region %s' % (region_id,)
|
||||
raise
|
||||
except Exception:
|
||||
event_details = '%s notification failed' % (region_id, )
|
||||
except NotifyNotAcknowledgedError as exp:
|
||||
event_details = 'Ranger Agent %s respond with error code' % (region_id,)
|
||||
status = 'ORD_Error'
|
||||
error_msg = str(exp)
|
||||
raise
|
||||
except Exception as exp:
|
||||
event_details = 'Notification failed for region %s' % (region_id, )
|
||||
status = 'ORD_Error'
|
||||
error_msg = 'Notification to Ranger Agent failed'
|
||||
logger.error(str(exp))
|
||||
raise
|
||||
finally:
|
||||
# Update resource_status db with status
|
||||
|
@ -286,10 +286,7 @@ def main(jsondata, external_transaction_id, resource_type, operation):
|
||||
input_data.targets = utils.add_rms_status_to_regions(
|
||||
input_data.targets, input_data.resource_type)
|
||||
_generate_resource_data(input_data)
|
||||
except ConflictError:
|
||||
LOG.error(str(exp))
|
||||
raise
|
||||
except ErrorStatus as exp:
|
||||
except (ConflictError, ErrorStatus) as exp:
|
||||
LOG.error(str(exp))
|
||||
raise
|
||||
except Exception as e:
|
||||
|
@ -588,7 +588,7 @@ class TestAddCustomers(FunctionalTest):
|
||||
mock_get_image_by_uuid):
|
||||
rds_proxy, mock_data_manager = get_data_manager_mock()
|
||||
mock_di.resolver.unpack.return_value = mock_data_manager
|
||||
self.assertRaises(ErrorStatus, image_logic.add_customers,
|
||||
self.assertRaises(ConflictError, image_logic.add_customers,
|
||||
'uuid', mock.MagicMock(),
|
||||
'transaction')
|
||||
|
||||
@ -644,7 +644,7 @@ class TestReplaceCustomers(FunctionalTest):
|
||||
visibility = 'public'
|
||||
rds_proxy, mock_data_manager = get_data_manager_mock()
|
||||
mock_di.resolver.unpack.return_value = mock_data_manager
|
||||
self.assertRaises(ValueError,
|
||||
self.assertRaises(ErrorStatus,
|
||||
image_logic.replace_customers,
|
||||
'uuid', mock.MagicMock(),
|
||||
'transaction')
|
||||
|
Loading…
x
Reference in New Issue
Block a user