Switch to ksa Session

* Change session imports to keystoneauth1
* Change keystoneclient.exception imports to keystoneauth1
* Change exceptions raised from internal API from keystoneclient to openstack.common

Change-Id: I046d89f561d6fe04baae53726f9749d2e7fe2056
This commit is contained in:
Dean Troyer 2015-10-21 12:01:56 -05:00 committed by Steve Martinelli
parent a9a7caf934
commit bf090c69c2
15 changed files with 41 additions and 39 deletions

View File

@ -37,7 +37,7 @@ import os
import sys
import traceback
from keystoneclient import session as ksc_session
from keystoneauth1 import session as ks_session
from openstackclient.api import auth
@ -226,7 +226,7 @@ def make_session(opts, **kwargs):
)
auth_p = auth_plugin.load_from_options(**auth_params)
session = ksc_session.Session(
session = ks_session.Session(
auth=auth_p,
**kwargs
)

View File

@ -15,8 +15,9 @@
import simplejson as json
from keystoneclient import exceptions as ksc_exceptions
from keystoneclient import session as ksc_session
from keystoneauth1 import exceptions as ks_exceptions
from keystoneauth1 import session as ks_session
from openstackclient.common import exceptions
@ -24,7 +25,7 @@ class KeystoneSession(object):
"""Wrapper for the Keystone Session
Restore some requests.session.Session compatibility;
keystoneclient.session.Session.request() has the method and url
keystoneauth1.session.Session.request() has the method and url
arguments swapped from the rest of the requests-using world.
"""
@ -70,7 +71,7 @@ class KeystoneSession(object):
if not session:
session = self.session
if not session:
session = ksc_session.Session()
session = ks_session.Session()
if self.endpoint:
if url:
@ -255,7 +256,7 @@ class BaseAPI(KeystoneSession):
return data[0]
if len(data) > 1:
msg = "Multiple %s exist with %s='%s'"
raise ksc_exceptions.CommandError(
raise exceptions.CommandError(
msg % (resource, attr, value),
)
@ -314,7 +315,7 @@ class BaseAPI(KeystoneSession):
num_bulk = len(bulk_list)
if num_bulk == 0:
msg = "none found"
raise ksc_exceptions.NotFound(msg)
raise exceptions.NotFound(msg)
elif num_bulk > 1:
msg = "many found"
raise RuntimeError(msg)
@ -338,12 +339,12 @@ class BaseAPI(KeystoneSession):
try:
ret = self._request('GET', "/%s/%s" % (path, value)).json()
except ksc_exceptions.NotFound:
except ks_exceptions.NotFound:
kwargs = {attr: value}
try:
ret = self.find_one("/%s/detail" % (path), **kwargs)
except ksc_exceptions.NotFound:
except ks_exceptions.NotFound:
msg = "%s not found" % value
raise ksc_exceptions.NotFound(msg)
raise exceptions.NotFound(msg)
return ret

View File

@ -11,9 +11,9 @@
# under the License.
#
"""Subclass of keystoneclient.session"""
"""Subclass of keystoneauth1.session"""
from keystoneclient import session
from keystoneauth1 import session
class TimingSession(session.Session):

View File

@ -23,7 +23,7 @@ from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
try:
from novaclient.v2 import security_group_rules
@ -241,7 +241,7 @@ class ListSecurityGroup(lister.Lister):
project_hash = {}
try:
projects = self.app.client_manager.identity.projects.list()
except ksc_exc.ClientException:
except ks_exc.ClientException:
# This fails when the user is not an admin, just move along
pass
else:

View File

@ -21,7 +21,7 @@ import six
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import parseractions
from openstackclient.common import utils
@ -88,7 +88,7 @@ class CreateProject(show.ShowOne):
enabled=enabled,
**kwargs
)
except ksc_exc.Conflict as e:
except ks_exc.Conflict as e:
if parsed_args.or_show:
project = utils.find_resource(
identity_client.tenants,
@ -264,7 +264,7 @@ class ShowProject(show.ShowOne):
parsed_args.project,
)
info.update(project._info)
except ksc_exc.Forbidden as e:
except ks_exc.Forbidden as e:
auth_ref = self.app.client_manager.auth_ref
if (
parsed_args.project == auth_ref.project_id or

View File

@ -21,7 +21,7 @@ import six
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import exceptions
from openstackclient.common import utils
@ -98,7 +98,7 @@ class CreateRole(show.ShowOne):
identity_client = self.app.client_manager.identity
try:
role = identity_client.roles.create(parsed_args.role_name)
except ksc_exc.Conflict as e:
except ks_exc.Conflict as e:
if parsed_args.or_show:
role = utils.find_resource(
identity_client.roles,

View File

@ -21,7 +21,7 @@ import six
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
@ -104,7 +104,7 @@ class CreateUser(show.ShowOne):
tenant_id=project_id,
enabled=enabled,
)
except ksc_exc.Conflict as e:
except ks_exc.Conflict as e:
if parsed_args.or_show:
user = utils.find_resource(
identity_client.users,
@ -373,7 +373,7 @@ class ShowUser(show.ShowOne):
parsed_args.user,
)
info.update(user._info)
except ksc_exc.Forbidden as e:
except ks_exc.Forbidden as e:
auth_ref = self.app.client_manager.auth_ref
if (
parsed_args.user == auth_ref.user_id or

View File

@ -22,7 +22,7 @@ import sys
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
@ -77,7 +77,7 @@ class CreateDomain(show.ShowOne):
description=parsed_args.description,
enabled=enabled,
)
except ksc_exc.Conflict as e:
except ks_exc.Conflict as e:
if parsed_args.or_show:
domain = utils.find_resource(identity_client.domains,
parsed_args.name)

View File

@ -22,7 +22,7 @@ import sys
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
@ -156,7 +156,7 @@ class CreateGroup(show.ShowOne):
name=parsed_args.name,
domain=domain,
description=parsed_args.description)
except ksc_exc.Conflict as e:
except ks_exc.Conflict as e:
if parsed_args.or_show:
group = utils.find_resource(identity_client.groups,
parsed_args.name,

View File

@ -21,7 +21,7 @@ import six
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import parseractions
from openstackclient.common import utils
@ -113,7 +113,7 @@ class CreateProject(show.ShowOne):
enabled=enabled,
**kwargs
)
except ksc_exc.Conflict as e:
except ks_exc.Conflict as e:
if parsed_args.or_show:
project = utils.find_resource(identity_client.projects,
parsed_args.name,

View File

@ -22,7 +22,7 @@ import sys
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
@ -172,7 +172,7 @@ class CreateRole(show.ShowOne):
try:
role = identity_client.roles.create(name=parsed_args.name)
except ksc_exc.Conflict as e:
except ks_exc.Conflict as e:
if parsed_args.or_show:
role = utils.find_resource(identity_client.roles,
parsed_args.name)

View File

@ -22,7 +22,7 @@ import six
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
@ -122,7 +122,7 @@ class CreateUser(show.ShowOne):
description=parsed_args.description,
enabled=enabled
)
except ksc_exc.Conflict as e:
except ks_exc.Conflict as e:
if parsed_args.or_show:
user = utils.find_resource(identity_client.users,
parsed_args.name,

View File

@ -15,7 +15,7 @@
import copy
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.identity.v2_0 import project
from openstackclient.tests import fakes
@ -223,7 +223,7 @@ class TestProjectCreate(TestProject):
def test_project_create_or_show_exists(self):
def _raise_conflict(*args, **kwargs):
raise ksc_exc.Conflict(None)
raise ks_exc.Conflict(None)
# need to make this throw an exception...
self.projects_mock.create.side_effect = _raise_conflict

View File

@ -16,7 +16,7 @@
import copy
import mock
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.common import exceptions
from openstackclient.identity.v2_0 import role
@ -146,7 +146,7 @@ class TestRoleCreate(TestRole):
def test_role_create_or_show_exists(self):
def _raise_conflict(*args, **kwargs):
raise ksc_exc.Conflict(None)
raise ks_exc.Conflict(None)
# need to make this throw an exception...
self.roles_mock.create.side_effect = _raise_conflict

View File

@ -16,7 +16,8 @@
import copy
import mock
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import exceptions as ks_exc
from openstackclient.identity.v2_0 import user
from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
@ -345,7 +346,7 @@ class TestUserCreate(TestUser):
def test_user_create_or_show_exists(self):
def _raise_conflict(*args, **kwargs):
raise ksc_exc.Conflict(None)
raise ks_exc.Conflict(None)
# need to make this throw an exception...
self.users_mock.create.side_effect = _raise_conflict