Merge "Fix exceptions to catch for ignore_missing"
This commit is contained in:
commit
ab5773663d
|
@ -10,6 +10,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from keystoneauth1 import exceptions as ksa_exc
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
from openstack import resource
|
from openstack import resource
|
||||||
|
|
||||||
|
@ -123,14 +124,14 @@ class BaseProxy(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rv = res.delete(self.session)
|
rv = res.delete(self.session)
|
||||||
except exceptions.NotFoundException as exc:
|
except ksa_exc.NotFound as exc:
|
||||||
if ignore_missing:
|
if ignore_missing:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
# Reraise with a more specific type and message
|
# Reraise with a more specific type and message
|
||||||
raise exceptions.ResourceNotFound(
|
raise exceptions.ResourceNotFound(
|
||||||
"No %s found for %s" % (resource_type.__name__, value),
|
"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
|
return rv
|
||||||
|
|
||||||
|
@ -193,10 +194,10 @@ class BaseProxy(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return res.get(self.session)
|
return res.get(self.session)
|
||||||
except exceptions.NotFoundException as exc:
|
except ksa_exc.NotFound as exc:
|
||||||
raise exceptions.ResourceNotFound(
|
raise exceptions.ResourceNotFound(
|
||||||
"No %s found for %s" % (resource_type.__name__, value),
|
"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,
|
def _list(self, resource_type, value=None, paginated=False,
|
||||||
path_args=None, **query):
|
path_args=None, **query):
|
||||||
|
|
|
@ -35,7 +35,7 @@ import copy
|
||||||
import itertools
|
import itertools
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from keystoneauth1 import exceptions as ksa_exceptions
|
from keystoneauth1 import exceptions as ksa_exc
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
|
@ -927,7 +927,7 @@ class Resource(collections.MutableMapping):
|
||||||
try:
|
try:
|
||||||
if cls.allow_retrieve:
|
if cls.allow_retrieve:
|
||||||
return cls.get_by_id(session, name_or_id, path_args=path_args)
|
return cls.get_by_id(session, name_or_id, path_args=path_args)
|
||||||
except ksa_exceptions.http.NotFound:
|
except ksa_exc.NotFound:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
data = cls.list(session, path_args=path_args)
|
data = cls.list(session, path_args=path_args)
|
||||||
|
@ -1003,7 +1003,7 @@ def wait_for_delete(session, resource, interval, wait):
|
||||||
while total_sleep < wait:
|
while total_sleep < wait:
|
||||||
try:
|
try:
|
||||||
resource.get(session)
|
resource.get(session)
|
||||||
except ksa_exceptions.http.NotFound:
|
except ksa_exc.NotFound:
|
||||||
return resource
|
return resource
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
total_sleep += interval
|
total_sleep += interval
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
import mock
|
import mock
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
from keystoneauth1 import exceptions as ksa_exc
|
||||||
|
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
from openstack import proxy
|
from openstack import proxy
|
||||||
from openstack import resource
|
from openstack import resource
|
||||||
|
@ -117,15 +119,15 @@ class TestProxyDelete(testtools.TestCase):
|
||||||
self.assertEqual(rv, self.fake_id)
|
self.assertEqual(rv, self.fake_id)
|
||||||
|
|
||||||
def test_delete_ignore_missing(self):
|
def test_delete_ignore_missing(self):
|
||||||
self.res.delete.side_effect = exceptions.NotFoundException(
|
self.res.delete.side_effect = ksa_exc.NotFound(message="test",
|
||||||
message="test", status_code=404)
|
http_status=404)
|
||||||
|
|
||||||
rv = self.sot._delete(DeleteableResource, self.fake_id)
|
rv = self.sot._delete(DeleteableResource, self.fake_id)
|
||||||
self.assertIsNone(rv)
|
self.assertIsNone(rv)
|
||||||
|
|
||||||
def test_delete_ResourceNotFound(self):
|
def test_delete_ResourceNotFound(self):
|
||||||
self.res.delete.side_effect = exceptions.NotFoundException(
|
self.res.delete.side_effect = ksa_exc.NotFound(message="test",
|
||||||
message="test", status_code=404)
|
http_status=404)
|
||||||
|
|
||||||
self.assertRaisesRegexp(
|
self.assertRaisesRegexp(
|
||||||
exceptions.ResourceNotFound,
|
exceptions.ResourceNotFound,
|
||||||
|
@ -230,8 +232,8 @@ class TestProxyGet(testtools.TestCase):
|
||||||
self.assertEqual(rv, self.fake_result)
|
self.assertEqual(rv, self.fake_result)
|
||||||
|
|
||||||
def test_get_not_found(self):
|
def test_get_not_found(self):
|
||||||
self.res.get.side_effect = exceptions.NotFoundException(
|
self.res.get.side_effect = ksa_exc.NotFound(message="test",
|
||||||
message="test", status_code=404)
|
http_status=404)
|
||||||
|
|
||||||
self.assertRaisesRegexp(
|
self.assertRaisesRegexp(
|
||||||
exceptions.ResourceNotFound,
|
exceptions.ResourceNotFound,
|
||||||
|
|
Loading…
Reference in New Issue