Add new CLI option openstack tripleo validate run
This submission starts with the integration of the current supported Mistral workflows for running the validations. This submission integrates the running of all current installed validations based on group validations or single validations. Change-Id: Ib86005596e046587a4608a755a15ce8620105f8b Implements: blueprint validation-framework Depends-On: I294ab0016fda9587b405ef08dba3212b8e46a816
This commit is contained in:
parent
6f6d6332bb
commit
b3af96f74e
@ -107,6 +107,7 @@ openstack.tripleoclient.v1 =
|
||||
undercloud_upgrade = tripleoclient.v1.undercloud:UpgradeUndercloud
|
||||
undercloud_backup = tripleoclient.v1.undercloud_backup:BackupUndercloud
|
||||
tripleo_validator_list = tripleoclient.v1.tripleo_validator:TripleOValidatorList
|
||||
tripleo_validator_run = tripleoclient.v1.tripleo_validator:TripleOValidatorRun
|
||||
oslo.config.opts =
|
||||
undercloud_config = tripleoclient.config.undercloud:list_opts
|
||||
standalone_config = tripleoclient.config.standalone:list_opts
|
||||
|
@ -21,7 +21,6 @@ from osc_lib.i18n import _
|
||||
|
||||
from tripleoclient import constants
|
||||
from tripleoclient import utils as oooutils
|
||||
|
||||
from tripleoclient.workflows import validations
|
||||
|
||||
LOG = logging.getLogger(__name__ + ".TripleoValidator")
|
||||
@ -39,6 +38,11 @@ class _CommaListGroupAction(argparse.Action):
|
||||
setattr(namespace, self.dest, values.split(','))
|
||||
|
||||
|
||||
class _CommaListAction(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
setattr(namespace, self.dest, values.split(','))
|
||||
|
||||
|
||||
class TripleOValidatorList(command.Command):
|
||||
"""List the available validations"""
|
||||
|
||||
@ -98,3 +102,78 @@ class TripleOValidatorList(command.Command):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self._run_validator_list(parsed_args)
|
||||
|
||||
|
||||
class TripleOValidatorRun(command.Command):
|
||||
"""Run the available validations"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = argparse.ArgumentParser(
|
||||
description=self.get_description(),
|
||||
prog=prog_name,
|
||||
add_help=False
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--plan',
|
||||
action='store',
|
||||
default='overcloud',
|
||||
help=_("Execute the validations using a "
|
||||
"custom plan name. "
|
||||
"Defaults to: overcloud")
|
||||
)
|
||||
|
||||
ex_group = parser.add_mutually_exclusive_group(required=True)
|
||||
|
||||
ex_group.add_argument(
|
||||
'--validation-name',
|
||||
metavar='<validation_id>[,<validation_id>,...]',
|
||||
action=_CommaListAction,
|
||||
default=[],
|
||||
help=_("Run specific validations, "
|
||||
"if more than one validation is required "
|
||||
"separate the names with commas"
|
||||
"Defaults to: [] "
|
||||
"i.e. --validation-name check-ftype,512e "
|
||||
" --validation-name 512e")
|
||||
)
|
||||
|
||||
ex_group.add_argument(
|
||||
'--group',
|
||||
metavar='<group>[,<group>,...]',
|
||||
action=_CommaListGroupAction,
|
||||
default=[],
|
||||
help=_("Run specific group validations, "
|
||||
"if more than one group is required "
|
||||
"separate the group names with commas"
|
||||
"Defaults to: ['pre-deployment'] "
|
||||
"i.e. --group pre-upgrade,prep "
|
||||
" --group openshift-on-openstack")
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def _run_validator_run(self, parsed_args):
|
||||
clients = self.app.client_manager
|
||||
|
||||
if not parsed_args.validation_name:
|
||||
workflow_input = {
|
||||
"plan": parsed_args.plan,
|
||||
"group_names": parsed_args.group
|
||||
}
|
||||
else:
|
||||
workflow_input = {
|
||||
"plan": parsed_args.plan,
|
||||
"validation_names": parsed_args.validation_name
|
||||
}
|
||||
|
||||
LOG.debug(_('Runnning the validations'))
|
||||
try:
|
||||
output = validations.run_validations(clients, workflow_input)
|
||||
print(oooutils.get_validations_json(output))
|
||||
except Exception as e:
|
||||
print(_("Running the validations finished with errors"))
|
||||
print('Output: {}'.format(e))
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self._run_validator_run(parsed_args)
|
||||
|
@ -16,6 +16,8 @@ import pprint
|
||||
|
||||
from tripleoclient.workflows import base
|
||||
|
||||
from tripleoclient import exceptions
|
||||
|
||||
|
||||
def list_validations(clients, workflow_input):
|
||||
|
||||
@ -33,3 +35,37 @@ def list_validations(clients, workflow_input):
|
||||
if 'message' in payload:
|
||||
assert payload['status'] == "SUCCESS", pprint.pformat(payload)
|
||||
return payload['validations']
|
||||
|
||||
|
||||
def run_validations(clients, workflow_input):
|
||||
|
||||
workflow_client = clients.workflow_engine
|
||||
tripleoclients = clients.tripleoclient
|
||||
|
||||
with tripleoclients.messaging_websocket() as ws:
|
||||
|
||||
if 'group_names' in workflow_input:
|
||||
print('Running group validations')
|
||||
execution = base.start_workflow(
|
||||
workflow_client,
|
||||
'tripleo.validations.v1.run_groups',
|
||||
workflow_input=workflow_input
|
||||
)
|
||||
else:
|
||||
print('Running single validations')
|
||||
execution = base.start_workflow(
|
||||
workflow_client,
|
||||
'tripleo.validations.v1.run_validations',
|
||||
workflow_input=workflow_input
|
||||
)
|
||||
|
||||
for payload in base.wait_for_messages(workflow_client, ws, execution):
|
||||
if 'message' in payload:
|
||||
if payload['status'] == 'SUCCESS':
|
||||
return payload['message']
|
||||
|
||||
if payload['status'] == 'FAILED':
|
||||
raise exceptions.RegisterOrUpdateError(
|
||||
'Exception running validations: {}'.format(
|
||||
payload['message'])
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user