Migrate from keystoneclient to keystoneauth

Since novaclient 7.0.0, the tripleo-ansible-inventory silently ignores
a novaclient error and skips all overcloud nodes in its output.

Switching to keystoneauth solves the issue in a clean fashion.

Change-Id: I2019ceebda8bf6bf2e1f01bba9e1d5c143c8738d
Closes-Bug: #1666662
This commit is contained in:
Martin André 2017-02-21 15:09:36 -05:00
parent 01c81e2762
commit f6a8d3d9cd
3 changed files with 33 additions and 46 deletions

View File

@ -0,0 +1,5 @@
---
features:
- |
Migrate tripleo-ansible-inventory to use keystoneauth instead of
keystoneclient.

View File

@ -4,6 +4,6 @@
pbr>=2.0.0 # Apache-2.0 pbr>=2.0.0 # Apache-2.0
oslo.config!=3.18.0,>=3.14.0 # Apache-2.0 oslo.config!=3.18.0,>=3.14.0 # Apache-2.0
keystoneauth1>=2.18.0 # Apache-2.0
python-heatclient>=1.6.1 # Apache-2.0 python-heatclient>=1.6.1 # Apache-2.0
python-keystoneclient>=3.8.0 # Apache-2.0
python-novaclient>=7.1.0 # Apache-2.0 python-novaclient>=7.1.0 # Apache-2.0

View File

@ -25,8 +25,9 @@ import json
import os import os
import sys import sys
from heatclient.v1 import client as heat_client from heatclient import client as heat_client
from keystoneclient.v3 import client as keystone_client from keystoneauth1.identity import v3
from keystoneauth1 import session
import mistralclient.api.base import mistralclient.api.base
import mistralclient.api.client import mistralclient.api.client
from novaclient import client as nova_client from novaclient import client as nova_client
@ -68,6 +69,7 @@ def _parse_config():
class TripleoInventory(object): class TripleoInventory(object):
def __init__(self, configs): def __init__(self, configs):
self.configs = configs self.configs = configs
self._session = None
self._ksclient = None self._ksclient = None
self._hclient = None self._hclient = None
self._mclient = None self._mclient = None
@ -163,41 +165,31 @@ class TripleoInventory(object):
print(json.dumps({})) print(json.dumps({}))
@property @property
def ksclient(self): def session(self):
if self._ksclient is None: if self._session is None:
try: if self.configs.auth_token:
if self.configs.auth_token: auth = v3.Token(auth_url=self.configs.auth_url,
self._ksclient = keystone_client.Client( token=self.configs.auth_token,
auth_url=self.configs.auth_url, project_name=self.configs.project_name,
username=self.configs.username, user_domain_id='default',
token=self.configs.auth_token, project_domain_id='default')
project_name=self.configs.project_name, else:
cacert=self.configs.cacert) auth = v3.Password(auth_url=self.configs.auth_url,
else: username=self.configs.username,
self._ksclient = keystone_client.Client( password=self.configs.password,
auth_url=self.configs.auth_url, project_name=self.configs.project_name,
username=self.configs.username, user_domain_id='default',
password=self.configs.password, project_domain_id='default')
project_name=self.configs.project_name,
cacert=self.configs.cacert) self._session = session.Session(auth=auth,
self._ksclient.authenticate() verify=self.configs.cacert)
except Exception as e: return self._session
print("Error connecting to Keystone: {}".format(e.message),
file=sys.stderr)
sys.exit(1)
return self._ksclient
@property @property
def hclient(self): def hclient(self):
if self._hclient is None: if self._hclient is None:
ksclient = self.ksclient
endpoint = ksclient.service_catalog.url_for(
service_type='orchestration', endpoint_type='publicURL')
try: try:
self._hclient = heat_client.Client( self._hclient = heat_client.Client('1', session=self.session)
endpoint=endpoint,
token=ksclient.auth_token,
ca_file=self.configs.cacert)
except Exception as e: except Exception as e:
print("Error connecting to Heat: {}".format(e.message), print("Error connecting to Heat: {}".format(e.message),
file=sys.stderr) file=sys.stderr)
@ -207,15 +199,8 @@ class TripleoInventory(object):
@property @property
def nclient(self): def nclient(self):
if self._nclient is None: if self._nclient is None:
ksclient = self.ksclient
endpoint = ksclient.service_catalog.url_for(
service_type='compute', endpoint_type='publicURL')
try: try:
self._nclient = nova_client.Client( self._nclient = nova_client.Client('2', session=self.session)
'2',
bypass_url=endpoint,
auth_token=ksclient.auth_token,
cacert=self.configs.cacert)
except Exception as e: except Exception as e:
print("Error connecting to Nova: {}".format(e.message), print("Error connecting to Nova: {}".format(e.message),
file=sys.stderr) file=sys.stderr)
@ -225,13 +210,11 @@ class TripleoInventory(object):
@property @property
def mclient(self): def mclient(self):
if self._mclient is None: if self._mclient is None:
ksclient = self.ksclient
endpoint = ksclient.service_catalog.url_for(
service_type='workflowv2', endpoint_type='publicURL')
try: try:
endpoint = self.session.get_endpoint(service_type='workflowv2')
self._mclient = mistralclient.api.client.client( self._mclient = mistralclient.api.client.client(
mistral_url=endpoint, mistral_url=endpoint,
auth_token=ksclient.auth_token) auth_token=self.session.get_token())
except Exception as e: except Exception as e:
print("Error connecting to Mistral: {}".format(e.message), print("Error connecting to Mistral: {}".format(e.message),
file=sys.stderr) file=sys.stderr)
@ -239,7 +222,6 @@ class TripleoInventory(object):
return self._mclient return self._mclient
def main(): def main():
configs = _parse_config() configs = _parse_config()
inventory = TripleoInventory(configs) inventory = TripleoInventory(configs)