switch from keystoneclient to keystoneauth

move glanceclient to keystoneauth as keystoneclient's auth session,
plugins and adapter code has been deprecated.

refer to [1] for more information.

1: 1a84e24fa4

implements bp: use-keystoneauth

Co-Authored-By: Itisha <ishadewan07@gmail.com>
Change-Id: I88fb327628e1bec48dc391f50d66b3deab4a8ab9
This commit is contained in:
Itisha Dewan 2016-06-14 06:57:02 +04:00 committed by Steve Martinelli
parent fec9b5f5e3
commit a9115b4cd8
7 changed files with 63 additions and 47 deletions

View File

@ -25,8 +25,8 @@ def Client(version=None, endpoint=None, session=None, *args, **kwargs):
for specific details.
:param string version: The version of API to use.
:param session: A keystoneclient session that should be used for transport.
:type session: keystoneclient.session.Session
:param session: A keystoneauth1 session that should be used for transport.
:type session: keystoneauth1.session.Session
"""
# FIXME(jamielennox): Add a deprecation warning if no session is passed.
# Leaving it as an option until we can ensure nothing break when we switch.

View File

@ -17,8 +17,8 @@ import copy
import logging
import socket
from keystoneclient import adapter
from keystoneclient import exceptions as ksc_exc
from keystoneauth1 import adapter
from keystoneauth1 import exceptions as ksa_exc
from oslo_utils import importutils
from oslo_utils import netutils
import requests
@ -329,13 +329,13 @@ class SessionClient(adapter.Adapter, _BaseHTTPClient):
headers=headers,
data=data,
**kwargs)
except ksc_exc.RequestTimeout as e:
except ksa_exc.ConnectTimeout as e:
conn_url = self.get_endpoint(auth=kwargs.get('auth'))
conn_url = "%s/%s" % (conn_url.rstrip('/'), url.lstrip('/'))
message = ("Error communicating with %(url)s %(e)s" %
dict(url=conn_url, e=e))
raise exc.InvalidEndpoint(message=message)
except ksc_exc.ConnectionRefused as e:
except ksa_exc.ConnectFailure as e:
conn_url = self.get_endpoint(auth=kwargs.get('auth'))
conn_url = "%s/%s" % (conn_url.rstrip('/'), url.lstrip('/'))
message = ("Error finding address for %(url)s: %(e)s" %

View File

@ -38,11 +38,11 @@ from glanceclient._i18n import _
from glanceclient.common import utils
from glanceclient import exc
from keystoneclient.auth.identity import v2 as v2_auth
from keystoneclient.auth.identity import v3 as v3_auth
from keystoneclient import discover
from keystoneclient import exceptions as ks_exc
from keystoneclient import session
from keystoneauth1 import discover
from keystoneauth1 import exceptions as ks_exc
from keystoneauth1.identity import v2 as v2_auth
from keystoneauth1.identity import v3 as v3_auth
from keystoneauth1 import loading
osprofiler_profiler = importutils.try_import("osprofiler.profiler")
@ -51,10 +51,14 @@ SUPPORTED_VERSIONS = [1, 2]
class OpenStackImagesShell(object):
def _append_global_identity_args(self, parser):
def _append_global_identity_args(self, parser, argv):
# register common identity args
session.Session.register_cli_options(parser)
v3_auth.Password.register_argparse_arguments(parser)
parser.set_defaults(os_auth_url=utils.env('OS_AUTH_URL'))
parser.set_defaults(os_project_name=utils.env(
'OS_PROJECT_NAME', 'OS_TENANT_NAME'))
parser.set_defaults(os_project_id=utils.env(
'OS_PROJECT_ID', 'OS_TENANT_ID'))
parser.add_argument('--key-file',
dest='os_key',
@ -68,17 +72,9 @@ class OpenStackImagesShell(object):
dest='os_cert',
help='DEPRECATED! Use --os-cert.')
parser.add_argument('--os-tenant-id',
default=utils.env('OS_TENANT_ID'),
help='Defaults to env[OS_TENANT_ID].')
parser.add_argument('--os_tenant_id',
help=argparse.SUPPRESS)
parser.add_argument('--os-tenant-name',
default=utils.env('OS_TENANT_NAME'),
help='Defaults to env[OS_TENANT_NAME].')
parser.add_argument('--os_tenant_name',
help=argparse.SUPPRESS)
@ -110,7 +106,19 @@ class OpenStackImagesShell(object):
parser.add_argument('--os_endpoint_type',
help=argparse.SUPPRESS)
def get_base_parser(self):
loading.register_session_argparse_arguments(parser)
# Peek into argv to see if os-auth-token (or the deprecated
# os_auth_token) or the new os-token or the environment variable
# OS_AUTH_TOKEN were given. In which case, the token auth plugin is
# what the user wants. Else, we'll default to password.
default_auth_plugin = 'password'
token_opts = ['os-token', 'os-auth-token', 'os_auth-token']
if argv and any(i in token_opts for i in argv):
default_auth_plugin = 'token'
loading.register_auth_argparse_arguments(
parser, argv, default=default_auth_plugin)
def get_base_parser(self, argv):
parser = argparse.ArgumentParser(
prog='glance',
description=__doc__.strip(),
@ -194,12 +202,12 @@ class OpenStackImagesShell(object):
'the profiling will not be triggered even '
'if osprofiler is enabled on server side.')
self._append_global_identity_args(parser)
self._append_global_identity_args(parser, argv)
return parser
def get_subcommand_parser(self, version):
parser = self.get_base_parser()
def get_subcommand_parser(self, version, argv=None):
parser = self.get_base_parser(argv)
self.subcommands = {}
subparsers = parser.add_subparsers(metavar='<subcommand>')
@ -261,7 +269,7 @@ class OpenStackImagesShell(object):
v2_auth_url = None
v3_auth_url = None
try:
ks_discover = discover.Discover(session=session, auth_url=auth_url)
ks_discover = discover.Discover(session=session, url=auth_url)
v2_auth_url = ks_discover.url_for('2.0')
v3_auth_url = ks_discover.url_for('3.0')
except ks_exc.ClientException as e:
@ -372,16 +380,11 @@ class OpenStackImagesShell(object):
"or prompted response"))
# Validate password flow auth
project_info = (
args.os_tenant_name or args.os_tenant_id or (
args.os_project_name and (
args.os_project_domain_name or
args.os_project_domain_id
)
) or args.os_project_id
)
if not project_info:
os_project_name = getattr(
args, 'os_project_name', getattr(args, 'os_tenant_name', None))
os_project_id = getattr(
args, 'os_project_id', getattr(args, 'os_tenant_id', None))
if not any([os_project_name, os_project_id]):
# tenant is deprecated in Keystone v3. Use the latest
# terminology instead.
raise exc.CommandError(
@ -432,7 +435,7 @@ class OpenStackImagesShell(object):
'ssl_compression': args.ssl_compression
}
else:
ks_session = session.Session.load_from_cli_options(args)
ks_session = loading.load_session_from_argparse_arguments(args)
auth_plugin_kwargs = self._get_kwargs_to_create_auth_plugin(args)
ks_session.auth = self._get_keystone_auth_plugin(
ks_session=ks_session, **auth_plugin_kwargs)
@ -490,7 +493,7 @@ class OpenStackImagesShell(object):
def _get_subparser(api_version):
try:
return self.get_subcommand_parser(api_version)
return self.get_subcommand_parser(api_version, argv)
except ImportError as e:
if not str(e):
# Add a generic import error message if the raised
@ -504,7 +507,7 @@ class OpenStackImagesShell(object):
# NOTE(flepied) Under Python3, parsed arguments are removed
# from the list so make a copy for the first parsing
base_argv = copy.deepcopy(argv)
parser = self.get_base_parser()
parser = self.get_base_parser(argv)
(options, args) = parser.parse_known_args(base_argv)
try:

View File

@ -15,8 +15,8 @@
import functools
import json
from keystoneclient.auth import token_endpoint
from keystoneclient import session
from keystoneauth1 import session
from keystoneauth1 import token_endpoint
import mock
import requests
from requests_mock.contrib import fixture

View File

@ -27,8 +27,8 @@ import traceback
import uuid
import fixtures
from keystoneclient import exceptions as ks_exc
from keystoneclient import fixture as ks_fixture
from keystoneauth1 import exceptions as ks_exc
from keystoneauth1 import fixture as ks_fixture
import mock
from requests_mock.contrib import fixture as rm_fixture
import six
@ -250,7 +250,9 @@ class ShellTest(testutils.TestCase):
def test_get_base_parser(self):
test_shell = openstack_shell.OpenStackImagesShell()
actual_parser = test_shell.get_base_parser()
# NOTE(stevemar): Use the current sys.argv for base_parser since it
# doesn't matter for this test, it just needs to initialize the CLI
actual_parser = test_shell.get_base_parser(sys.argv)
description = 'Command-line interface to the OpenStack Images API.'
expected = argparse.ArgumentParser(
prog='glance', usage=None,
@ -637,7 +639,7 @@ class ShellTestWithKeystoneV3Auth(ShellTest):
glance_shell.main(args.split())
self.assertEqual(0, self.v3_auth.call_count)
@mock.patch('keystoneclient.discover.Discover',
@mock.patch('keystoneauth1.discover.Discover',
side_effect=ks_exc.ClientException())
def test_api_discovery_failed_with_unversioned_auth_url(self,
discover):

View File

@ -0,0 +1,11 @@
---
prelude: >
Switch to using keystoneauth for session and auth plugins.
other:
- >
[`bp use-keystoneauth <https://blueprints.launchpad.net/python-glanceclient/+spec/use-keystoneauth>`_]
As of keystoneclient 2.2.0, the session and auth plugins code has
been deprecated. These modules have been moved to the keystoneauth
library. Consumers of the session and plugin modules are encouraged
to move to keystoneauth. Note that there should be no change to
end users of glanceclient.

View File

@ -4,7 +4,7 @@
pbr>=1.6 # Apache-2.0
Babel>=2.3.4 # BSD
PrettyTable<0.8,>=0.7 # BSD
python-keystoneclient!=2.1.0,>=2.0.0 # Apache-2.0
keystoneauth1>=2.10.0 # Apache-2.0
requests>=2.10.0 # Apache-2.0
warlock!=1.3.0,<2,>=1.0.1 # Apache-2.0
six>=1.9.0 # MIT