Merge "Use MultiKeyActionValue action for extra-[env-]vars arguments" into stable/ussuri

This commit is contained in:
Zuul 2021-03-27 08:34:25 +00:00 committed by Gerrit Code Review
commit 71693e3209
1 changed files with 37 additions and 14 deletions

View File

@ -19,6 +19,7 @@ import logging
import yaml import yaml
from openstack import exceptions as os_exceptions from openstack import exceptions as os_exceptions
from osc_lib.cli import parseractions
from osc_lib import exceptions from osc_lib import exceptions
from osc_lib.i18n import _ from osc_lib.i18n import _
from prettytable import PrettyTable from prettytable import PrettyTable
@ -257,12 +258,13 @@ class TripleOValidatorRun(command.Command):
extra_vars_group.add_argument( extra_vars_group.add_argument(
'--extra-vars', '--extra-vars',
action='store', metavar="key1=<val1>[,key2=val2 --extra-vars key3=<val3>]",
default={}, action=parseractions.MultiKeyValueAction,
type=json.loads,
help=_( help=_(
"Add a dictionary as extra variable to a validation: " "Add Ansible extra variables to the validation(s) execution "
"--extra-vars '{\"min_undercloud_ram_gb\": 24}'") "as KEY=VALUE pair(s). Note that if you pass the same "
"KEY multiple times, the last given VALUE for that same KEY "
"will override the other(s)")
) )
extra_vars_group.add_argument( extra_vars_group.add_argument(
@ -280,13 +282,14 @@ class TripleOValidatorRun(command.Command):
extra_vars_group.add_argument( extra_vars_group.add_argument(
'--extra-env-vars', '--extra-env-vars',
action='store', metavar="key1=<val1>[,key2=val2 --extra-env-vars key3=<val3>]",
default={}, action=parseractions.MultiKeyValueAction,
type=json.loads,
help=_( help=_(
"A dictionary as extra environment variables you may need " "Add extra environment variables you may need "
"to provide to your Ansible execution example:" "to provide to your Ansible execution "
"ANSIBLE_STDOUT_CALLBACK=default") "as KEY=VALUE pairs. Note that if you pass the same "
"KEY multiple times, the last given VALUE for that same KEY "
"will override the other(s)")
) )
extra_vars_group.add_argument( extra_vars_group.add_argument(
@ -358,7 +361,14 @@ class TripleOValidatorRun(command.Command):
msg = "Running Validations without Overcloud settings." msg = "Running Validations without Overcloud settings."
LOG.warning("{}{}{}".format(YELLOW, msg, RESET)) LOG.warning("{}{}{}".format(YELLOW, msg, RESET))
limit = parsed_args.limit limit = parsed_args.limit
extra_vars = parsed_args.extra_vars
extra_vars = dict()
if parsed_args.extra_vars:
# if using multiple --extra-vars argument in the command-line
# we will get a list of multiple dictionaries.
for keypair in parsed_args.extra_vars:
extra_vars.update(keypair)
if parsed_args.extra_vars_file: if parsed_args.extra_vars_file:
try: try:
with open(parsed_args.extra_vars_file, 'r') as env_file: with open(parsed_args.extra_vars_file, 'r') as env_file:
@ -369,6 +379,19 @@ class TripleOValidatorRun(command.Command):
"Details: %s." % e) "Details: %s." % e)
raise exceptions.CommandError(error_msg) raise exceptions.CommandError(error_msg)
# Ansible execution should be quiet while using the validations_json
# default callback and be verbose while passing ANSIBLE_SDTOUT_CALLBACK
# environment variable to Ansible through the --extra-env-vars argument
quiet_mode = True
extra_env_vars = dict()
if parsed_args.extra_env_vars:
# if using multiple --extra-env-vars argument in the command-line
# we will get a list of multiple dictionaries.
for keypair in parsed_args.extra_env_vars:
if "ANSIBLE_STDOUT_CALLBACK" in keypair.keys():
quiet_mode = False
extra_env_vars.update(keypair)
# We don't check if the file exists in order to support # We don't check if the file exists in order to support
# passing a string such as "localhost,", like we can do with # passing a string such as "localhost,", like we can do with
# the "-i" option of ansible-playbook. # the "-i" option of ansible-playbook.
@ -392,8 +415,8 @@ class TripleOValidatorRun(command.Command):
extra_vars=extra_vars, extra_vars=extra_vars,
validations_dir=constants.ANSIBLE_VALIDATION_DIR, validations_dir=constants.ANSIBLE_VALIDATION_DIR,
validation_name=parsed_args.validation_name, validation_name=parsed_args.validation_name,
extra_env_vars=parsed_args.extra_env_vars, extra_env_vars=extra_env_vars,
quiet=True) quiet=quiet_mode)
except RuntimeError as e: except RuntimeError as e:
raise exceptions.CommandError(e) raise exceptions.CommandError(e)