Merge "Fix exceptions to catch for ignore_missing"

This commit is contained in:
Jenkins 2015-12-15 05:50:03 +00:00 committed by Gerrit Code Review
commit ab5773663d
3 changed files with 16 additions and 13 deletions

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from keystoneauth1 import exceptions as ksa_exc
from openstack import exceptions
from openstack import resource
@ -123,14 +124,14 @@ class BaseProxy(object):
try:
rv = res.delete(self.session)
except exceptions.NotFoundException as exc:
except ksa_exc.NotFound as exc:
if ignore_missing:
return None
else:
# Reraise with a more specific type and message
raise exceptions.ResourceNotFound(
"No %s found for %s" % (resource_type.__name__, value),
details=exc.details, status_code=exc.status_code)
details=exc.details, status_code=exc.http_status)
return rv
@ -193,10 +194,10 @@ class BaseProxy(object):
try:
return res.get(self.session)
except exceptions.NotFoundException as exc:
except ksa_exc.NotFound as exc:
raise exceptions.ResourceNotFound(
"No %s found for %s" % (resource_type.__name__, value),
details=exc.details, status_code=exc.status_code)
details=exc.details, status_code=exc.http_status)
def _list(self, resource_type, value=None, paginated=False,
path_args=None, **query):

View File

@ -35,7 +35,7 @@ import copy
import itertools
import time
from keystoneauth1 import exceptions as ksa_exceptions
from keystoneauth1 import exceptions as ksa_exc
import six
from openstack import exceptions
@ -927,7 +927,7 @@ class Resource(collections.MutableMapping):
try:
if cls.allow_retrieve:
return cls.get_by_id(session, name_or_id, path_args=path_args)
except ksa_exceptions.http.NotFound:
except ksa_exc.NotFound:
pass
data = cls.list(session, path_args=path_args)
@ -1003,7 +1003,7 @@ def wait_for_delete(session, resource, interval, wait):
while total_sleep < wait:
try:
resource.get(session)
except ksa_exceptions.http.NotFound:
except ksa_exc.NotFound:
return resource
time.sleep(interval)
total_sleep += interval

View File

@ -13,6 +13,8 @@
import mock
import testtools
from keystoneauth1 import exceptions as ksa_exc
from openstack import exceptions
from openstack import proxy
from openstack import resource
@ -117,15 +119,15 @@ class TestProxyDelete(testtools.TestCase):
self.assertEqual(rv, self.fake_id)
def test_delete_ignore_missing(self):
self.res.delete.side_effect = exceptions.NotFoundException(
message="test", status_code=404)
self.res.delete.side_effect = ksa_exc.NotFound(message="test",
http_status=404)
rv = self.sot._delete(DeleteableResource, self.fake_id)
self.assertIsNone(rv)
def test_delete_ResourceNotFound(self):
self.res.delete.side_effect = exceptions.NotFoundException(
message="test", status_code=404)
self.res.delete.side_effect = ksa_exc.NotFound(message="test",
http_status=404)
self.assertRaisesRegexp(
exceptions.ResourceNotFound,
@ -230,8 +232,8 @@ class TestProxyGet(testtools.TestCase):
self.assertEqual(rv, self.fake_result)
def test_get_not_found(self):
self.res.get.side_effect = exceptions.NotFoundException(
message="test", status_code=404)
self.res.get.side_effect = ksa_exc.NotFound(message="test",
http_status=404)
self.assertRaisesRegexp(
exceptions.ResourceNotFound,