Use ResourceNotFound replace RP and Image NotFound

This is a series of optimization for exception.

In fact, we only need to use the ResourceNotFound exception
to fit NotFound Exception.

This patch also adds dependency package cursive which is used
in [1].

[1]. 6740c3c0c5/cyborg/image/glance.py (L30)

Change-Id: I9e80dcfed54147c942f90c696e483fa6db842dde
Story: 2007045
Task: 37968
This commit is contained in:
chenke 2020-01-07 15:22:26 +08:00 committed by chenker
parent a39f816b55
commit 4bf582a849
6 changed files with 33 additions and 9 deletions

View File

@ -297,10 +297,6 @@ class ResourceProviderUpdateFailed(CyborgException):
"%(error)s")
class ResourceProviderNotFound(NotFound):
msg_fmt = _("No such resource provider %(name_or_uuid)s.")
class ResourceProviderSyncFailed(CyborgException):
msg_fmt = _("Failed to synchronize the placement service with resource "
"provider information supplied by the compute host.")
@ -389,10 +385,6 @@ class ImageNotAuthorized(CyborgException):
msg_fmt = _("Not authorized for image %(image_id)s.")
class ImageNotFound(NotFound):
msg_fmt = _("Image %(image_id)s could not be found.")
class ImageBadRequest(Invalid):
msg_fmt = _("Request of image %(image_id)s got BadRequest response: "
"%(response)s")

View File

@ -643,7 +643,9 @@ def _translate_image_exception(image_id, exc_value):
glanceclient.exc.Unauthorized)):
return exception.ImageNotAuthorized(image_id=image_id)
if isinstance(exc_value, glanceclient.exc.NotFound):
return exception.ImageNotFound(image_id=image_id)
return exception.ResourceNotFound(
resource='Image',
msg='with uuid=%s' % image_id)
if isinstance(exc_value, glanceclient.exc.BadRequest):
return exception.ImageBadRequest(image_id=image_id,
response=six.text_type(exc_value))

View File

View File

@ -0,0 +1,28 @@
# Copyright 2020 ZTE Corporation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import glanceclient
from cyborg.common import exception
from cyborg.image import glance
from cyborg.tests.unit.db import base
class TestExceptionTranslations(base.DbTestCase):
def test_client_notfound_converts_to_imagenotfound(self):
in_exc = glanceclient.exc.NotFound('123')
out_exc = glance._translate_image_exception('123', in_exc)
self.assertIsInstance(out_exc, exception.ResourceNotFound)

View File

@ -29,3 +29,4 @@ psutil>=3.2.2 # BSD
mock>=2.0.0 # BSD
python-glanceclient>=2.3.0 # Apache-2.0
oslo.privsep>=1.32.0 # Apache-2.0
cursive>=0.2.1 # Apache-2.0

View File

@ -19,3 +19,4 @@ doc8>=0.6.0 # Apache-2.0
pycodestyle>=2.0.0 # MIT License
Pygments>=2.2.0 # BSD license
os-resource-classes>=0.5.0 # Apache-2.0
cursive>=0.2.1 # Apache-2.0