refactor(keystone): clean up code

This patch set cleans up a few items in the keystone code in the
airship-shipyard code base:

* Change the provided util function to load the session from
  [keystone_authtoken] section of the cfg.CONF rather than picking at
  the fields to use v3.Password.
* (trivial) the import order is now alphabetical
* (trivial) keystoneauth1 exception no longer imports to the actual module

Change-Id: I29da2c4d0b24a1baf5f90c52807c3b1c31b82191
Signed-off-by: Tin Lam <tin@irrational.io>
This commit is contained in:
Tin Lam 2018-06-02 13:34:30 -05:00
parent 37ec369c14
commit 83bccfd337
1 changed files with 7 additions and 12 deletions

View File

@ -20,11 +20,10 @@ import enum
import logging
import falcon
from keystoneauth1 import session
from keystoneauth1.identity import v3
from keystoneauth1.exceptions.auth import AuthorizationFailure
from keystoneauth1.exceptions.catalog import EndpointNotFound
from keystoneauth1 import exceptions as exc
from keystoneauth1 import loading
from oslo_config import cfg
from shipyard_airflow.errors import AppError
CONF = cfg.CONF
@ -86,7 +85,7 @@ def get_endpoint(endpoint):
return _get_ks_session().get_endpoint(
interface='internal',
service_type=service_type)
except EndpointNotFound:
except exc.EndpointNotFound:
LOG.error('Could not find a public interface for %s',
endpoint.name)
raise AppError(
@ -113,14 +112,10 @@ def get_session():
def _get_ks_session():
# Establishes a keystone session
keystone_auth = {}
for attr in ('auth_url', 'password', 'project_domain_name',
'project_name', 'username', 'user_domain_name'):
keystone_auth[attr] = CONF.get('keystone_authtoken').get(attr)
try:
auth = v3.Password(**keystone_auth)
return session.Session(auth=auth)
except AuthorizationFailure as aferr:
return loading.load_session_from_conf_options(
CONF, group="keystone_authtoken")
except exc.AuthorizationFailure as aferr:
LOG.error('Could not authorize against keystone: %s',
str(aferr))
raise AppError(