Get deployment status to check if plan and stack exists on the env

This patch use deployment.get_deployment_status to check
if the stack and the plan exist on the env if a  --plan
option has been passed.

Change-Id: I23e2bba9fc9e9b0574786d8594d89102759fad64
This commit is contained in:
Mathieu Bultel 2020-11-19 15:27:54 +01:00
parent 2fff553f7f
commit c9a13bed00
2 changed files with 44 additions and 22 deletions

View File

@ -1598,17 +1598,22 @@ def get_tripleo_ansible_inventory(inventory_file=None,
constants.CLOUD_HOME_DIR, constants.CLOUD_HOME_DIR,
'tripleo-ansible-inventory.yaml' 'tripleo-ansible-inventory.yaml'
) )
try:
processutils.execute( command = ['/usr/bin/tripleo-ansible-inventory',
'/usr/bin/tripleo-ansible-inventory', '--os-cloud', 'undercloud']
'--stack', stack, if stack:
'--ansible_ssh_user', ssh_user, command.extend(['--stack', stack])
'--undercloud-connection', undercloud_connection, command.extend(['--undercloud-key-file', get_key(stack=stack)])
'--undercloud-key-file', get_key(stack=stack), if ssh_user:
'--os-cloud', 'undercloud', command.extend(['--ansible_ssh_user', ssh_user])
'--static-yaml-inventory', inventory_file) if undercloud_connection:
except processutils.ProcessExecutionError as e: command.extend(['--undercloud-connection',
message = _("Failed to generate inventory: %s") % str(e) undercloud_connection])
if inventory_file:
command.extend(['--static-yaml-inventory', inventory_file])
rc = run_command_and_log(LOG, command)
if rc != 0:
message = "Failed to generate inventory"
raise exceptions.InvalidConfiguration(message) raise exceptions.InvalidConfiguration(message)
if os.path.exists(inventory_file): if os.path.exists(inventory_file):
if return_inventory_file_path: if return_inventory_file_path:

View File

@ -26,7 +26,7 @@ from prettytable import PrettyTable
from tripleoclient import command from tripleoclient import command
from tripleoclient import constants from tripleoclient import constants
from tripleoclient import utils as oooutils from tripleoclient import utils as oooutils
from tripleoclient.workflows import plan_management from tripleoclient.workflows import deployment
from validations_libs import constants as v_consts from validations_libs import constants as v_consts
from validations_libs import utils as v_utils from validations_libs import utils as v_utils
@ -38,6 +38,7 @@ LOG = logging.getLogger(__name__ + ".TripleoValidator")
RED = "\033[1;31m" RED = "\033[1;31m"
GREEN = "\033[0;32m" GREEN = "\033[0;32m"
CYAN = "\033[36m" CYAN = "\033[36m"
YELLOW = "\033[0;33m"
RESET = "\033[0;0m" RESET = "\033[0;0m"
FAILED_VALIDATION = "{}FAILED{}".format(RED, RESET) FAILED_VALIDATION = "{}FAILED{}".format(RED, RESET)
@ -45,6 +46,8 @@ PASSED_VALIDATION = "{}PASSED{}".format(GREEN, RESET)
GROUP_FILE = constants.VALIDATION_GROUPS_INFO GROUP_FILE = constants.VALIDATION_GROUPS_INFO
NO_VALIDATION_STATE = ['DEPLOY_FAILED', 'DEPLOYING']
class _CommaListGroupAction(argparse.Action): class _CommaListGroupAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None): def __call__(self, parser, namespace, values, option_string=None):
@ -232,10 +235,17 @@ class TripleOValidatorRun(command.Command):
parser.add_argument( parser.add_argument(
'--plan', '--stack', '--plan', '--stack',
dest='plan', dest='plan',
default='overcloud', default=None,
help=_("Execute the validations using a custom plan name") help=_("Execute the validations using a custom plan name")
) )
parser.add_argument(
'--ssh-user',
dest='ssh_user',
default='heat-admin',
help=_("Ssh User name for the Overcloud ssh connection.")
)
parser.add_argument( parser.add_argument(
'--limit', action='store', required=False, help=_( '--limit', action='store', required=False, help=_(
"A string that identifies a single node or comma-separated" "A string that identifies a single node or comma-separated"
@ -321,6 +331,8 @@ class TripleOValidatorRun(command.Command):
def _run_validator_run(self, parsed_args): def _run_validator_run(self, parsed_args):
LOG = logging.getLogger(__name__ + ".ValidationsRunAnsible") LOG = logging.getLogger(__name__ + ".ValidationsRunAnsible")
plan = parsed_args.plan
# Try to perform OpenStack authentication, if no authentication # Try to perform OpenStack authentication, if no authentication
# and static inventory provided continue, else raise error. # and static inventory provided continue, else raise error.
try: try:
@ -328,18 +340,23 @@ class TripleOValidatorRun(command.Command):
clients._auth_required = True clients._auth_required = True
clients.setup_auth() clients.setup_auth()
except os_exceptions.ConfigException: except os_exceptions.ConfigException:
LOG.warning("Running Validations without authentication.") msg = "Running Validations without authentication."
LOG.warning("{}{}{}".format(YELLOW, msg, RESET))
if not parsed_args.static_inventory: if not parsed_args.static_inventory:
raise exceptions.CommandError( raise exceptions.CommandError(
_("No static inventory provided, please provide a valid" _("No static inventory provided, please provide a valid "
"inventory or use authentication.")) "inventory or use authentication."))
else: else:
plans = plan_management.list_deployment_plans(clients) if plan:
if parsed_args.plan and parsed_args.plan not in plans: status = deployment.get_deployment_status(clients, plan)
raise exceptions.CommandError( if not status or status in NO_VALIDATION_STATE:
_("The plan '{}' doesn't exist. " raise exceptions.CommandError(
"Please use one of those {}".format(parsed_args, _("The plan and the stack '{}' doesn't exist OR are "
plans))) "in 'failed' or 'deploying' state."
"Please use a valid plan".format(plan)))
else:
msg = "Running Validations without Overcloud settings."
LOG.warning("{}{}{}".format(YELLOW, msg, RESET))
limit = parsed_args.limit limit = parsed_args.limit
extra_vars = parsed_args.extra_vars extra_vars = parsed_args.extra_vars
if parsed_args.extra_vars_file: if parsed_args.extra_vars_file:
@ -359,7 +376,7 @@ class TripleOValidatorRun(command.Command):
static_inventory = parsed_args.static_inventory static_inventory = parsed_args.static_inventory
else: else:
static_inventory = oooutils.get_tripleo_ansible_inventory( static_inventory = oooutils.get_tripleo_ansible_inventory(
ssh_user='heat-admin', ssh_user=parsed_args.ssh_user,
stack=parsed_args.plan, stack=parsed_args.plan,
undercloud_connection='local', undercloud_connection='local',
return_inventory_file_path=True) return_inventory_file_path=True)