Skip to content

Commit

Permalink
Switch to ksa Session
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Dean Troyer authored and Steve Martinelli committed Dec 2, 2015
1 parent a9a7caf commit bf090c6
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 39 deletions.
4 changes: 2 additions & 2 deletions examples/common.py
Expand Up @@ -37,7 +37,7 @@
import sys
import traceback

from keystoneclient import session as ksc_session
from keystoneauth1 import session as ks_session

from openstackclient.api import auth

Expand Down Expand Up @@ -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
)
Expand Down
19 changes: 10 additions & 9 deletions openstackclient/api/api.py
Expand Up @@ -15,16 +15,17 @@

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


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.
"""
Expand Down Expand Up @@ -70,7 +71,7 @@ def _request(self, method, url, session=None, **kwargs):
if not session:
session = self.session
if not session:
session = ksc_session.Session()
session = ks_session.Session()

if self.endpoint:
if url:
Expand Down Expand Up @@ -255,7 +256,7 @@ def getlist(kw):
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),
)

Expand Down Expand Up @@ -314,7 +315,7 @@ def find_one(
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)
Expand All @@ -338,12 +339,12 @@ def find(

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
4 changes: 2 additions & 2 deletions openstackclient/common/session.py
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/compute/v2/security_group.py
Expand Up @@ -23,7 +23,7 @@
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
Expand Down Expand Up @@ -241,7 +241,7 @@ def _get_project(project_id):
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:
Expand Down
6 changes: 3 additions & 3 deletions openstackclient/identity/v2_0/project.py
Expand Up @@ -21,7 +21,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

from openstackclient.common import parseractions
from openstackclient.common import utils
Expand Down Expand Up @@ -88,7 +88,7 @@ def take_action(self, parsed_args):
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,
Expand Down Expand Up @@ -264,7 +264,7 @@ def take_action(self, parsed_args):
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
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/identity/v2_0/role.py
Expand Up @@ -21,7 +21,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

from openstackclient.common import exceptions
from openstackclient.common import utils
Expand Down Expand Up @@ -98,7 +98,7 @@ def take_action(self, parsed_args):
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,
Expand Down
6 changes: 3 additions & 3 deletions openstackclient/identity/v2_0/user.py
Expand Up @@ -21,7 +21,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

from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
Expand Down Expand Up @@ -104,7 +104,7 @@ def take_action(self, parsed_args):
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,
Expand Down Expand Up @@ -373,7 +373,7 @@ def take_action(self, parsed_args):
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
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/identity/v3/domain.py
Expand Up @@ -22,7 +22,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

from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
Expand Down Expand Up @@ -77,7 +77,7 @@ def take_action(self, parsed_args):
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)
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/identity/v3/group.py
Expand Up @@ -22,7 +22,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

from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
Expand Down Expand Up @@ -156,7 +156,7 @@ def take_action(self, parsed_args):
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,
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/identity/v3/project.py
Expand Up @@ -21,7 +21,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

from openstackclient.common import parseractions
from openstackclient.common import utils
Expand Down Expand Up @@ -113,7 +113,7 @@ def take_action(self, parsed_args):
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,
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/identity/v3/role.py
Expand Up @@ -22,7 +22,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

from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
Expand Down Expand Up @@ -172,7 +172,7 @@ def take_action(self, parsed_args):

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)
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/identity/v3/user.py
Expand Up @@ -22,7 +22,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

from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
Expand Down Expand Up @@ -122,7 +122,7 @@ def take_action(self, parsed_args):
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,
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/tests/identity/v2_0/test_project.py
Expand Up @@ -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
Expand Down Expand Up @@ -223,7 +223,7 @@ def test_project_create_property(self):

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
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/tests/identity/v2_0/test_role.py
Expand Up @@ -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
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_role_create_no_options(self):

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
Expand Down
5 changes: 3 additions & 2 deletions openstackclient/tests/identity/v2_0/test_user.py
Expand Up @@ -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
Expand Down Expand Up @@ -345,7 +346,7 @@ def test_user_create_disable(self):

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
Expand Down

0 comments on commit bf090c6

Please sign in to comment.