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
(cherry picked from commit c9a13bed00
)
This commit is contained in:
parent
8ff500c126
commit
8e961f4420
|
@ -1598,17 +1598,22 @@ def get_tripleo_ansible_inventory(inventory_file=None,
|
|||
constants.CLOUD_HOME_DIR,
|
||||
'tripleo-ansible-inventory.yaml'
|
||||
)
|
||||
try:
|
||||
processutils.execute(
|
||||
'/usr/bin/tripleo-ansible-inventory',
|
||||
'--stack', stack,
|
||||
'--ansible_ssh_user', ssh_user,
|
||||
'--undercloud-connection', undercloud_connection,
|
||||
'--undercloud-key-file', get_key(stack=stack),
|
||||
'--os-cloud', 'undercloud',
|
||||
'--static-yaml-inventory', inventory_file)
|
||||
except processutils.ProcessExecutionError as e:
|
||||
message = _("Failed to generate inventory: %s") % str(e)
|
||||
|
||||
command = ['/usr/bin/tripleo-ansible-inventory',
|
||||
'--os-cloud', 'undercloud']
|
||||
if stack:
|
||||
command.extend(['--stack', stack])
|
||||
command.extend(['--undercloud-key-file', get_key(stack=stack)])
|
||||
if ssh_user:
|
||||
command.extend(['--ansible_ssh_user', ssh_user])
|
||||
if undercloud_connection:
|
||||
command.extend(['--undercloud-connection',
|
||||
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)
|
||||
if os.path.exists(inventory_file):
|
||||
if return_inventory_file_path:
|
||||
|
|
|
@ -26,7 +26,7 @@ from prettytable import PrettyTable
|
|||
from tripleoclient import command
|
||||
from tripleoclient import constants
|
||||
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 utils as v_utils
|
||||
|
@ -38,6 +38,7 @@ LOG = logging.getLogger(__name__ + ".TripleoValidator")
|
|||
RED = "\033[1;31m"
|
||||
GREEN = "\033[0;32m"
|
||||
CYAN = "\033[36m"
|
||||
YELLOW = "\033[0;33m"
|
||||
RESET = "\033[0;0m"
|
||||
|
||||
FAILED_VALIDATION = "{}FAILED{}".format(RED, RESET)
|
||||
|
@ -45,6 +46,8 @@ PASSED_VALIDATION = "{}PASSED{}".format(GREEN, RESET)
|
|||
|
||||
GROUP_FILE = constants.VALIDATION_GROUPS_INFO
|
||||
|
||||
NO_VALIDATION_STATE = ['DEPLOY_FAILED', 'DEPLOYING']
|
||||
|
||||
|
||||
class _CommaListGroupAction(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
|
@ -232,10 +235,17 @@ class TripleOValidatorRun(command.Command):
|
|||
parser.add_argument(
|
||||
'--plan', '--stack',
|
||||
dest='plan',
|
||||
default='overcloud',
|
||||
default=None,
|
||||
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(
|
||||
'--limit', action='store', required=False, help=_(
|
||||
"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):
|
||||
LOG = logging.getLogger(__name__ + ".ValidationsRunAnsible")
|
||||
|
||||
plan = parsed_args.plan
|
||||
# Try to perform OpenStack authentication, if no authentication
|
||||
# and static inventory provided continue, else raise error.
|
||||
try:
|
||||
|
@ -328,18 +340,23 @@ class TripleOValidatorRun(command.Command):
|
|||
clients._auth_required = True
|
||||
clients.setup_auth()
|
||||
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:
|
||||
raise exceptions.CommandError(
|
||||
_("No static inventory provided, please provide a valid"
|
||||
_("No static inventory provided, please provide a valid "
|
||||
"inventory or use authentication."))
|
||||
else:
|
||||
plans = plan_management.list_deployment_plans(clients)
|
||||
if parsed_args.plan and parsed_args.plan not in plans:
|
||||
raise exceptions.CommandError(
|
||||
_("The plan '{}' doesn't exist. "
|
||||
"Please use one of those {}".format(parsed_args,
|
||||
plans)))
|
||||
if plan:
|
||||
status = deployment.get_deployment_status(clients, plan)
|
||||
if not status or status in NO_VALIDATION_STATE:
|
||||
raise exceptions.CommandError(
|
||||
_("The plan and the stack '{}' doesn't exist OR are "
|
||||
"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
|
||||
extra_vars = parsed_args.extra_vars
|
||||
if parsed_args.extra_vars_file:
|
||||
|
@ -359,7 +376,7 @@ class TripleOValidatorRun(command.Command):
|
|||
static_inventory = parsed_args.static_inventory
|
||||
else:
|
||||
static_inventory = oooutils.get_tripleo_ansible_inventory(
|
||||
ssh_user='heat-admin',
|
||||
ssh_user=parsed_args.ssh_user,
|
||||
stack=parsed_args.plan,
|
||||
undercloud_connection='local',
|
||||
return_inventory_file_path=True)
|
||||
|
|
Loading…
Reference in New Issue