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:
parent
a9a7caf934
commit
bf090c69c2
@ -37,7 +37,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from keystoneclient import session as ksc_session
|
from keystoneauth1 import session as ks_session
|
||||||
|
|
||||||
from openstackclient.api import auth
|
from openstackclient.api import auth
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ def make_session(opts, **kwargs):
|
|||||||
)
|
)
|
||||||
auth_p = auth_plugin.load_from_options(**auth_params)
|
auth_p = auth_plugin.load_from_options(**auth_params)
|
||||||
|
|
||||||
session = ksc_session.Session(
|
session = ks_session.Session(
|
||||||
auth=auth_p,
|
auth=auth_p,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
|
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
from keystoneclient import exceptions as ksc_exceptions
|
from keystoneauth1 import exceptions as ks_exceptions
|
||||||
from keystoneclient import session as ksc_session
|
from keystoneauth1 import session as ks_session
|
||||||
|
|
||||||
from openstackclient.common import exceptions
|
from openstackclient.common import exceptions
|
||||||
|
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ class KeystoneSession(object):
|
|||||||
"""Wrapper for the Keystone Session
|
"""Wrapper for the Keystone Session
|
||||||
|
|
||||||
Restore some requests.session.Session compatibility;
|
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.
|
arguments swapped from the rest of the requests-using world.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -70,7 +71,7 @@ class KeystoneSession(object):
|
|||||||
if not session:
|
if not session:
|
||||||
session = self.session
|
session = self.session
|
||||||
if not session:
|
if not session:
|
||||||
session = ksc_session.Session()
|
session = ks_session.Session()
|
||||||
|
|
||||||
if self.endpoint:
|
if self.endpoint:
|
||||||
if url:
|
if url:
|
||||||
@ -255,7 +256,7 @@ class BaseAPI(KeystoneSession):
|
|||||||
return data[0]
|
return data[0]
|
||||||
if len(data) > 1:
|
if len(data) > 1:
|
||||||
msg = "Multiple %s exist with %s='%s'"
|
msg = "Multiple %s exist with %s='%s'"
|
||||||
raise ksc_exceptions.CommandError(
|
raise exceptions.CommandError(
|
||||||
msg % (resource, attr, value),
|
msg % (resource, attr, value),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -314,7 +315,7 @@ class BaseAPI(KeystoneSession):
|
|||||||
num_bulk = len(bulk_list)
|
num_bulk = len(bulk_list)
|
||||||
if num_bulk == 0:
|
if num_bulk == 0:
|
||||||
msg = "none found"
|
msg = "none found"
|
||||||
raise ksc_exceptions.NotFound(msg)
|
raise exceptions.NotFound(msg)
|
||||||
elif num_bulk > 1:
|
elif num_bulk > 1:
|
||||||
msg = "many found"
|
msg = "many found"
|
||||||
raise RuntimeError(msg)
|
raise RuntimeError(msg)
|
||||||
@ -338,12 +339,12 @@ class BaseAPI(KeystoneSession):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ret = self._request('GET', "/%s/%s" % (path, value)).json()
|
ret = self._request('GET', "/%s/%s" % (path, value)).json()
|
||||||
except ksc_exceptions.NotFound:
|
except ks_exceptions.NotFound:
|
||||||
kwargs = {attr: value}
|
kwargs = {attr: value}
|
||||||
try:
|
try:
|
||||||
ret = self.find_one("/%s/detail" % (path), **kwargs)
|
ret = self.find_one("/%s/detail" % (path), **kwargs)
|
||||||
except ksc_exceptions.NotFound:
|
except ks_exceptions.NotFound:
|
||||||
msg = "%s not found" % value
|
msg = "%s not found" % value
|
||||||
raise ksc_exceptions.NotFound(msg)
|
raise exceptions.NotFound(msg)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""Subclass of keystoneclient.session"""
|
"""Subclass of keystoneauth1.session"""
|
||||||
|
|
||||||
from keystoneclient import session
|
from keystoneauth1 import session
|
||||||
|
|
||||||
|
|
||||||
class TimingSession(session.Session):
|
class TimingSession(session.Session):
|
||||||
|
@ -23,7 +23,7 @@ from cliff import command
|
|||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
|
||||||
from keystoneclient import exceptions as ksc_exc
|
from keystoneauth1 import exceptions as ks_exc
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from novaclient.v2 import security_group_rules
|
from novaclient.v2 import security_group_rules
|
||||||
@ -241,7 +241,7 @@ class ListSecurityGroup(lister.Lister):
|
|||||||
project_hash = {}
|
project_hash = {}
|
||||||
try:
|
try:
|
||||||
projects = self.app.client_manager.identity.projects.list()
|
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
|
# This fails when the user is not an admin, just move along
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -21,7 +21,7 @@ import six
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
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 parseractions
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
@ -88,7 +88,7 @@ class CreateProject(show.ShowOne):
|
|||||||
enabled=enabled,
|
enabled=enabled,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
except ksc_exc.Conflict as e:
|
except ks_exc.Conflict as e:
|
||||||
if parsed_args.or_show:
|
if parsed_args.or_show:
|
||||||
project = utils.find_resource(
|
project = utils.find_resource(
|
||||||
identity_client.tenants,
|
identity_client.tenants,
|
||||||
@ -264,7 +264,7 @@ class ShowProject(show.ShowOne):
|
|||||||
parsed_args.project,
|
parsed_args.project,
|
||||||
)
|
)
|
||||||
info.update(project._info)
|
info.update(project._info)
|
||||||
except ksc_exc.Forbidden as e:
|
except ks_exc.Forbidden as e:
|
||||||
auth_ref = self.app.client_manager.auth_ref
|
auth_ref = self.app.client_manager.auth_ref
|
||||||
if (
|
if (
|
||||||
parsed_args.project == auth_ref.project_id or
|
parsed_args.project == auth_ref.project_id or
|
||||||
|
@ -21,7 +21,7 @@ import six
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
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 exceptions
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
@ -98,7 +98,7 @@ class CreateRole(show.ShowOne):
|
|||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
try:
|
try:
|
||||||
role = identity_client.roles.create(parsed_args.role_name)
|
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:
|
if parsed_args.or_show:
|
||||||
role = utils.find_resource(
|
role = utils.find_resource(
|
||||||
identity_client.roles,
|
identity_client.roles,
|
||||||
|
@ -21,7 +21,7 @@ import six
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
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.common import utils
|
||||||
from openstackclient.i18n import _ # noqa
|
from openstackclient.i18n import _ # noqa
|
||||||
@ -104,7 +104,7 @@ class CreateUser(show.ShowOne):
|
|||||||
tenant_id=project_id,
|
tenant_id=project_id,
|
||||||
enabled=enabled,
|
enabled=enabled,
|
||||||
)
|
)
|
||||||
except ksc_exc.Conflict as e:
|
except ks_exc.Conflict as e:
|
||||||
if parsed_args.or_show:
|
if parsed_args.or_show:
|
||||||
user = utils.find_resource(
|
user = utils.find_resource(
|
||||||
identity_client.users,
|
identity_client.users,
|
||||||
@ -373,7 +373,7 @@ class ShowUser(show.ShowOne):
|
|||||||
parsed_args.user,
|
parsed_args.user,
|
||||||
)
|
)
|
||||||
info.update(user._info)
|
info.update(user._info)
|
||||||
except ksc_exc.Forbidden as e:
|
except ks_exc.Forbidden as e:
|
||||||
auth_ref = self.app.client_manager.auth_ref
|
auth_ref = self.app.client_manager.auth_ref
|
||||||
if (
|
if (
|
||||||
parsed_args.user == auth_ref.user_id or
|
parsed_args.user == auth_ref.user_id or
|
||||||
|
@ -22,7 +22,7 @@ import sys
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
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.common import utils
|
||||||
from openstackclient.i18n import _ # noqa
|
from openstackclient.i18n import _ # noqa
|
||||||
@ -77,7 +77,7 @@ class CreateDomain(show.ShowOne):
|
|||||||
description=parsed_args.description,
|
description=parsed_args.description,
|
||||||
enabled=enabled,
|
enabled=enabled,
|
||||||
)
|
)
|
||||||
except ksc_exc.Conflict as e:
|
except ks_exc.Conflict as e:
|
||||||
if parsed_args.or_show:
|
if parsed_args.or_show:
|
||||||
domain = utils.find_resource(identity_client.domains,
|
domain = utils.find_resource(identity_client.domains,
|
||||||
parsed_args.name)
|
parsed_args.name)
|
||||||
|
@ -22,7 +22,7 @@ import sys
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
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.common import utils
|
||||||
from openstackclient.i18n import _ # noqa
|
from openstackclient.i18n import _ # noqa
|
||||||
@ -156,7 +156,7 @@ class CreateGroup(show.ShowOne):
|
|||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
domain=domain,
|
domain=domain,
|
||||||
description=parsed_args.description)
|
description=parsed_args.description)
|
||||||
except ksc_exc.Conflict as e:
|
except ks_exc.Conflict as e:
|
||||||
if parsed_args.or_show:
|
if parsed_args.or_show:
|
||||||
group = utils.find_resource(identity_client.groups,
|
group = utils.find_resource(identity_client.groups,
|
||||||
parsed_args.name,
|
parsed_args.name,
|
||||||
|
@ -21,7 +21,7 @@ import six
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
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 parseractions
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
@ -113,7 +113,7 @@ class CreateProject(show.ShowOne):
|
|||||||
enabled=enabled,
|
enabled=enabled,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
except ksc_exc.Conflict as e:
|
except ks_exc.Conflict as e:
|
||||||
if parsed_args.or_show:
|
if parsed_args.or_show:
|
||||||
project = utils.find_resource(identity_client.projects,
|
project = utils.find_resource(identity_client.projects,
|
||||||
parsed_args.name,
|
parsed_args.name,
|
||||||
|
@ -22,7 +22,7 @@ import sys
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
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.common import utils
|
||||||
from openstackclient.i18n import _ # noqa
|
from openstackclient.i18n import _ # noqa
|
||||||
@ -172,7 +172,7 @@ class CreateRole(show.ShowOne):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
role = identity_client.roles.create(name=parsed_args.name)
|
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:
|
if parsed_args.or_show:
|
||||||
role = utils.find_resource(identity_client.roles,
|
role = utils.find_resource(identity_client.roles,
|
||||||
parsed_args.name)
|
parsed_args.name)
|
||||||
|
@ -22,7 +22,7 @@ import six
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
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.common import utils
|
||||||
from openstackclient.i18n import _ # noqa
|
from openstackclient.i18n import _ # noqa
|
||||||
@ -122,7 +122,7 @@ class CreateUser(show.ShowOne):
|
|||||||
description=parsed_args.description,
|
description=parsed_args.description,
|
||||||
enabled=enabled
|
enabled=enabled
|
||||||
)
|
)
|
||||||
except ksc_exc.Conflict as e:
|
except ks_exc.Conflict as e:
|
||||||
if parsed_args.or_show:
|
if parsed_args.or_show:
|
||||||
user = utils.find_resource(identity_client.users,
|
user = utils.find_resource(identity_client.users,
|
||||||
parsed_args.name,
|
parsed_args.name,
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import copy
|
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.identity.v2_0 import project
|
||||||
from openstackclient.tests import fakes
|
from openstackclient.tests import fakes
|
||||||
@ -223,7 +223,7 @@ class TestProjectCreate(TestProject):
|
|||||||
|
|
||||||
def test_project_create_or_show_exists(self):
|
def test_project_create_or_show_exists(self):
|
||||||
def _raise_conflict(*args, **kwargs):
|
def _raise_conflict(*args, **kwargs):
|
||||||
raise ksc_exc.Conflict(None)
|
raise ks_exc.Conflict(None)
|
||||||
|
|
||||||
# need to make this throw an exception...
|
# need to make this throw an exception...
|
||||||
self.projects_mock.create.side_effect = _raise_conflict
|
self.projects_mock.create.side_effect = _raise_conflict
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from keystoneclient import exceptions as ksc_exc
|
from keystoneauth1 import exceptions as ks_exc
|
||||||
|
|
||||||
from openstackclient.common import exceptions
|
from openstackclient.common import exceptions
|
||||||
from openstackclient.identity.v2_0 import role
|
from openstackclient.identity.v2_0 import role
|
||||||
@ -146,7 +146,7 @@ class TestRoleCreate(TestRole):
|
|||||||
|
|
||||||
def test_role_create_or_show_exists(self):
|
def test_role_create_or_show_exists(self):
|
||||||
def _raise_conflict(*args, **kwargs):
|
def _raise_conflict(*args, **kwargs):
|
||||||
raise ksc_exc.Conflict(None)
|
raise ks_exc.Conflict(None)
|
||||||
|
|
||||||
# need to make this throw an exception...
|
# need to make this throw an exception...
|
||||||
self.roles_mock.create.side_effect = _raise_conflict
|
self.roles_mock.create.side_effect = _raise_conflict
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
import copy
|
import copy
|
||||||
import mock
|
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.identity.v2_0 import user
|
||||||
from openstackclient.tests import fakes
|
from openstackclient.tests import fakes
|
||||||
from openstackclient.tests.identity.v2_0 import fakes as identity_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 test_user_create_or_show_exists(self):
|
||||||
def _raise_conflict(*args, **kwargs):
|
def _raise_conflict(*args, **kwargs):
|
||||||
raise ksc_exc.Conflict(None)
|
raise ks_exc.Conflict(None)
|
||||||
|
|
||||||
# need to make this throw an exception...
|
# need to make this throw an exception...
|
||||||
self.users_mock.create.side_effect = _raise_conflict
|
self.users_mock.create.side_effect = _raise_conflict
|
||||||
|
Loading…
Reference in New Issue
Block a user