Use exceptions from Keystoneauth

As keystoneclient and other services rely more on keystoneauth we should
assume that keystoneauth is our base auth library, not keystoneclient
and start to default to the objects provided from there. This will make
it easier to remove these objects when the time comes.

For the session independant parts of keystoneclient we should use the
exception names as provided by keystoneauth instead of the aliases in
keystoneclient.

Change-Id: Ic513046f8398a76c244e145d6cc3117cdf6bb4cd
This commit is contained in:
Jamie Lennox
2016-08-24 18:33:54 +10:00
parent f557170404
commit 5b91fedd65
11 changed files with 39 additions and 33 deletions

View File

@@ -22,12 +22,13 @@ import copy
import functools
import warnings
from keystoneauth1 import exceptions as ksa_exceptions
from keystoneauth1 import plugin
from oslo_utils import strutils
import six
from six.moves import urllib
from keystoneclient import exceptions
from keystoneclient import exceptions as ksc_exceptions
from keystoneclient.i18n import _
@@ -226,8 +227,8 @@ class Manager(object):
resp, body = methods[method](url, body=body,
**kwargs)
except KeyError:
raise exceptions.ClientException(_("Invalid update method: %s")
% method)
raise ksc_exceptions.ClientException(_("Invalid update method: %s")
% method)
# PUT requests may not return a body
if body:
return self.resource_class(self, body[response_key])
@@ -253,9 +254,9 @@ class ManagerWithFind(Manager):
if num == 0:
msg = _("No %(name)s matching %(kwargs)s.") % {
'name': self.resource_class.__name__, 'kwargs': kwargs}
raise exceptions.NotFound(404, msg)
raise ksa_exceptions.NotFound(404, msg)
elif num > 1:
raise exceptions.NoUniqueMatch
raise ksc_exceptions.NoUniqueMatch
else:
return rl[0]
@@ -384,7 +385,7 @@ class CrudManager(Manager):
return self._list(
url_query,
self.collection_key)
except exceptions.EmptyCatalog:
except ksa_exceptions.EmptyCatalog:
if fallback_to_auth:
return self._list(
url_query,
@@ -431,9 +432,9 @@ class CrudManager(Manager):
if num == 0:
msg = _("No %(name)s matching %(kwargs)s.") % {
'name': self.resource_class.__name__, 'kwargs': kwargs}
raise exceptions.NotFound(404, msg)
raise ksa_exceptions.NotFound(404, msg)
elif num > 1:
raise exceptions.NoUniqueMatch
raise ksc_exceptions.NoUniqueMatch
else:
return rl[0]

View File

@@ -10,11 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from keystoneauth1 import exceptions as ksa_exceptions
import six
import testresources
from testtools import matchers
from keystoneclient import exceptions
from keystoneclient import exceptions as ksc_exceptions
from keystoneclient.tests.unit import client_fixtures
from keystoneclient.tests.unit import utils as test_utils
from keystoneclient import utils
@@ -39,16 +41,16 @@ class FakeManager(object):
try:
return self.resources[str(resource_id)]
except KeyError:
raise exceptions.NotFound(resource_id)
raise ksa_exceptions.NotFound(resource_id)
def find(self, name=None):
if name == '9999':
# NOTE(morganfainberg): special case that raises NoUniqueMatch.
raise exceptions.NoUniqueMatch()
raise ksc_exceptions.NoUniqueMatch()
for resource_id, resource in self.resources.items():
if resource['name'] == str(name):
return resource
raise exceptions.NotFound(name)
raise ksa_exceptions.NotFound(name)
class FindResourceTestCase(test_utils.TestCase):
@@ -58,7 +60,7 @@ class FindResourceTestCase(test_utils.TestCase):
self.manager = FakeManager()
def test_find_none(self):
self.assertRaises(exceptions.CommandError,
self.assertRaises(ksc_exceptions.CommandError,
utils.find_resource,
self.manager,
'asdf')
@@ -90,7 +92,7 @@ class FindResourceTestCase(test_utils.TestCase):
self.assertEqual(output, self.manager.resources['5678'])
def test_find_no_unique_match(self):
self.assertRaises(exceptions.CommandError,
self.assertRaises(ksc_exceptions.CommandError,
utils.find_resource,
self.manager,
9999)

View File

@@ -12,9 +12,9 @@
import uuid
from keystoneauth1 import exceptions
from keystoneauth1 import fixture
from keystoneclient import exceptions
from keystoneclient.tests.unit.v2_0 import utils
from keystoneclient.v2_0 import client
from keystoneclient.v2_0 import tenants

View File

@@ -12,10 +12,10 @@
import uuid
from keystoneauth1 import exceptions
from keystoneauth1 import fixture
from keystoneclient import access
from keystoneclient import exceptions
from keystoneclient.tests.unit.v2_0 import utils
from keystoneclient.v2_0 import client
from keystoneclient.v2_0 import tokens

View File

@@ -13,6 +13,7 @@
import copy
import uuid
from keystoneauth1 import exceptions
from keystoneauth1 import fixture
from keystoneauth1.identity import v3
from keystoneauth1 import session
@@ -21,7 +22,6 @@ import six
from testtools import matchers
from keystoneclient import access
from keystoneclient import exceptions
from keystoneclient.tests.unit.v3 import utils
from keystoneclient.v3 import client
from keystoneclient.v3.contrib.federation import base

View File

@@ -12,7 +12,9 @@
import uuid
from keystoneclient import exceptions
from keystoneauth1 import exceptions as ksa_exceptions
from keystoneclient import exceptions as ksc_exceptions
from keystoneclient.tests.unit.v3 import utils
from keystoneclient.v3 import projects
@@ -284,7 +286,7 @@ class ProjectTests(utils.ClientTestCase, utils.CrudTests):
def test_get_with_invalid_parameters_combination(self):
# subtree_as_list and subtree_as_ids can not be included at the
# same time in the call.
self.assertRaises(exceptions.ValidationError,
self.assertRaises(ksc_exceptions.ValidationError,
self.manager.get,
project=uuid.uuid4().hex,
subtree_as_list=True,
@@ -292,7 +294,7 @@ class ProjectTests(utils.ClientTestCase, utils.CrudTests):
# parents_as_list and parents_as_ids can not be included at the
# same time in the call.
self.assertRaises(exceptions.ValidationError,
self.assertRaises(ksc_exceptions.ValidationError,
self.manager.get,
project=uuid.uuid4().hex,
parents_as_list=True,
@@ -308,5 +310,5 @@ class ProjectTests(utils.ClientTestCase, utils.CrudTests):
# NOTE(rodrigods): this is the expected behaviour of the Identity
# server, a different implementation might not fail this request.
self.assertRaises(exceptions.Forbidden, self.manager.update,
self.assertRaises(ksa_exceptions.Forbidden, self.manager.update,
ref['id'], **utils.parameterize(req_ref))

View File

@@ -12,10 +12,10 @@
import uuid
from keystoneauth1 import exceptions
import testresources
from keystoneclient import access
from keystoneclient import exceptions
from keystoneclient.tests.unit import client_fixtures
from keystoneclient.tests.unit.v3 import utils

View File

@@ -15,13 +15,14 @@ import hashlib
import logging
import sys
from keystoneauth1 import exceptions as ksa_exceptions
from oslo_utils import timeutils
# NOTE(stevemar): do not remove positional. We need this to stay for a while
# since versions of auth_token require it here.
from positional import positional # noqa
import six
from keystoneclient import exceptions
from keystoneclient import exceptions as ksc_exceptions
logger = logging.getLogger(__name__)
@@ -32,8 +33,8 @@ def find_resource(manager, name_or_id):
# first try the entity as a string
try:
return manager.get(name_or_id)
except (exceptions.NotFound): # nosec(cjschaef): try to find 'name_or_id'
# as a six.binary_type instead
except (ksa_exceptions.NotFound): # nosec(cjschaef): try to find
# 'name_or_id' as a six.binary_type instead
pass
# finally try to find entity by name
@@ -41,15 +42,15 @@ def find_resource(manager, name_or_id):
if isinstance(name_or_id, six.binary_type):
name_or_id = name_or_id.decode('utf-8', 'strict')
return manager.find(name=name_or_id)
except exceptions.NotFound:
except ksa_exceptions.NotFound:
msg = ("No %s with a name or ID of '%s' exists." %
(manager.resource_class.__name__.lower(), name_or_id))
raise exceptions.CommandError(msg)
except exceptions.NoUniqueMatch:
raise ksc_exceptions.CommandError(msg)
except ksc_exceptions.NoUniqueMatch:
msg = ("Multiple %s matches found for '%s', use an ID to be more"
" specific." % (manager.resource_class.__name__.lower(),
name_or_id))
raise exceptions.CommandError(msg)
raise ksc_exceptions.CommandError(msg)
def unauthenticated(f):

View File

@@ -10,12 +10,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from keystoneauth1 import exceptions
from keystoneauth1 import plugin
from positional import positional
from keystoneclient import access
from keystoneclient import base
from keystoneclient import exceptions
from keystoneclient.i18n import _

View File

@@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from keystoneauth1 import exceptions
from keystoneauth1 import plugin
from keystoneclient import base
from keystoneclient import exceptions
from keystoneclient.v3 import domains
from keystoneclient.v3 import projects

View File

@@ -12,11 +12,11 @@
import abc
from keystoneauth1 import exceptions
from keystoneauth1 import plugin
import six
from keystoneclient import base
from keystoneclient import exceptions
@six.add_metaclass(abc.ABCMeta)
@@ -33,7 +33,7 @@ class EntityManager(base.Manager):
url = '/auth/%s' % self.object_type
try:
tenant_list = self._list(url, self.object_type)
except exceptions.EndpointException:
except exceptions.CatalogException:
endpoint_filter = {'interface': plugin.AUTH_INTERFACE}
tenant_list = self._list(url, self.object_type,
endpoint_filter=endpoint_filter)