Fix static-inventory option for minor update

The generate-inventory is always true in the current
code, when we want to provide a static inventory
it won't be taken in account.
the patch aim to fix this bug

Change-Id: If204b3da9b279d7b001d8cfe8c77106f8bf594af
This commit is contained in:
Mathieu Bultel 2017-10-25 11:22:35 +02:00
parent 04a5193092
commit 098e9da9af
2 changed files with 14 additions and 21 deletions

View File

@ -101,8 +101,7 @@ class TestOvercloudUpdate(fakes.TestOvercloudUpdate):
verifylist = [
('stack', 'overcloud'),
('nodes', 'Compute'),
('generate_inventory', True),
('static_inventory', 'tripleo-hosts-inventory'),
('static_inventory', None),
('playbook', 'fake-playbook.yaml')
]

View File

@ -72,18 +72,13 @@ class UpdateOvercloud(command.Command):
default="update_steps_playbook.yaml",
help=_('Playbook to use for update')
)
parser.add_argument('--generate-inventory',
dest='generate_inventory',
action='store_true',
default=True,
help=_("Generate inventory for the ansible "
"playbook"),
)
parser.add_argument('--static-inventory',
dest='static_inventory',
action="store",
default='tripleo-hosts-inventory',
help=_('Path to the static inventory to use')
default=None,
help=_('Path to an existing ansible inventory to '
'use. If not specified, one will be '
'generated in ~/tripleo-ansible-inventory')
)
return parser
@ -117,22 +112,21 @@ class UpdateOvercloud(command.Command):
# Run ansible:
nodes = parsed_args.nodes
playbook = parsed_args.playbook
inventory_path = '%s/%s' % (os.path.expanduser('~'),
parsed_args.static_inventory)
if parsed_args.generate_inventory:
inventory_file = parsed_args.static_inventory
if inventory_file is None:
inventory_file = '%s/%s' % (os.path.expanduser('~'),
'tripleo-ansible-inventory')
try:
processutils.execute('/bin/tripleo-ansible-inventory',
'--static-inventory', inventory_path)
'--static-inventory', inventory_file)
except processutils.ProcessExecutionError as e:
message = "Failed to generate inventory file: %s" % str(e)
message = "Failed to generate inventory: %s" % str(e)
raise exceptions.InvalidConfiguration(message)
if os.path.exists(inventory_path):
inventory = open(inventory_path, 'r').read()
if os.path.exists(inventory_file):
inventory = open(inventory_file, 'r').read()
else:
raise exceptions.InvalidConfiguration(
"Inventory file missing, provide an inventory file or "
"generate an inventory by using the --generate-inventory "
"option")
"Inventory file %s can not be found." % inventory_file)
output = package_update.update_ansible(
clients, nodes=nodes,
inventory_file=inventory,