Improve exceptions in tripleo-ansible-inventory
Adds a debug flag to surface tracebacks on failures. Also removes .message from exceptions, as this is deprecated in 2.6 and removed in py3. Change-Id: I7d2cdc37bd134370ff7edcefa3a4589024d5ce9a Closes-Bug: 1751340
This commit is contained in:
parent
6dc1ba3c1f
commit
5d30a5aa8e
|
@ -24,6 +24,7 @@ from __future__ import print_function
|
|||
import os
|
||||
import sys
|
||||
import json
|
||||
import traceback
|
||||
|
||||
from heatclient import client as heat_client
|
||||
from oslo_config import cfg
|
||||
|
@ -59,6 +60,7 @@ opts = [
|
|||
'will take precedence.')),
|
||||
cfg.StrOpt('ansible_ssh_user', default=os.environ.get('ANSIBLE_SSH_USER',
|
||||
'heat-admin')),
|
||||
cfg.BoolOpt('debug', help='Print tracebacks for exceptions')
|
||||
]
|
||||
|
||||
|
||||
|
@ -144,15 +146,19 @@ def main():
|
|||
write_static_inventory(configs.static_inventory,
|
||||
inventory_list)
|
||||
except Exception as e:
|
||||
print("Error creating inventory: {}".format(e.message),
|
||||
print("Error creating inventory: {}".format(e),
|
||||
file=sys.stderr)
|
||||
if configs.debug:
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
elif configs.static_yaml_inventory:
|
||||
try:
|
||||
inventory.write_static_inventory(configs.static_yaml_inventory)
|
||||
except Exception as e:
|
||||
print("Error creating static inventory: {}".format(e.message),
|
||||
print("Error creating static inventory: {}".format(e),
|
||||
file=sys.stderr)
|
||||
if configs.debug:
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
elif configs.host:
|
||||
print(json.dumps(inventory.host()))
|
||||
|
|
Loading…
Reference in New Issue