From 83bccfd3370b2655ae6f4c43c4ec5477720f3c5f Mon Sep 17 00:00:00 2001 From: Tin Lam Date: Sat, 2 Jun 2018 13:34:30 -0500 Subject: [PATCH] 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 --- .../control/service_endpoints.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/bin/shipyard_airflow/shipyard_airflow/control/service_endpoints.py b/src/bin/shipyard_airflow/shipyard_airflow/control/service_endpoints.py index f1b17a04..2758c034 100644 --- a/src/bin/shipyard_airflow/shipyard_airflow/control/service_endpoints.py +++ b/src/bin/shipyard_airflow/shipyard_airflow/control/service_endpoints.py @@ -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(