TripleO Validator CLI Refactor

This patch hardly refactors the TripleO Validator CLI. The 'List'
subcommand has been split in different new subcommands which does "one
thing and only one thing". It also adds the support for the TripleO
history file and integrates better the CLI with the openstack client
library, which simplifies it a lot.

The subcommands are:

- To display the full list of validations or by group(s):
  ```
  $ openstack tripleo validator list
  ```

- To display full details about one validation:
  ```
  $ openstack tripleo validator show
  ```

- To display the available parameters for one or multiple validations,
  export them in a JSON or YAML file:
  ```
  $ openstack tripleo validator show parameter
  ```

- To display full details about the groups used by the validations:
  ```
  $ openstack tripleo validator group info
  ```

- To run one or several validations by names or by groups:
  ```
  $ openstack tripleo validator run
  ```

Depends-On: I56b9d39c113cfb30695fe8cf2740ae147b0dd3e4
Change-Id: I09e2cba484d3a91915fb9294bc351b5d7f3aca0f
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
(cherry picked from commit 29b00170b3)
This commit is contained in:
Gael Chamoulaud
2019-11-08 16:35:53 +01:00
parent 8efc50c6dc
commit 94163f4019
6 changed files with 279 additions and 108 deletions

View File

@@ -41,7 +41,6 @@ import socket
import subprocess
import sys
import tempfile
import textwrap
import time
import yaml
@@ -61,8 +60,6 @@ from six.moves.urllib import request
from tripleoclient import constants
from tripleoclient import exceptions
from prettytable import PrettyTable
LOG = logging.getLogger(__name__ + ".utils")
@@ -1792,6 +1789,24 @@ def get_validation_parameters(validation):
return dict()
def parse_all_validation_groups_on_disk(groups_file_path=None):
results = []
if not groups_file_path:
groups_file_path = constants.VALIDATION_GROUPS_INFO
if not os.path.exists(groups_file_path):
return results
with open(groups_file_path, 'r') as grps:
contents = yaml.safe_load(grps)
for grp_name, grp_desc in sorted(contents.items()):
results.append((grp_name, grp_desc[0].get('description')))
return results
def parse_all_validations_on_disk(path, groups=None):
results = []
validations_abspath = glob.glob("{path}/*.yaml".format(path=path))
@@ -1862,34 +1877,6 @@ def get_validations_parameters(validations_data,
return params
def get_validations_table(validations_data):
"""Return the validations information as a pretty printed table"""
param_field_name = get_param_field_name(validations_data)
t = PrettyTable(border=True, header=True, padding_width=1)
t.title = "TripleO validations"
t.field_names = [
"ID", "Name",
"Description", "Groups",
param_field_name.capitalize()
]
for validation in validations_data['validations']:
t.add_row([validation['id'],
validation['name'],
"\n".join(textwrap.wrap(validation['description'])),
"\n".join(textwrap.wrap(' '.join(validation['groups']))),
validation[param_field_name]])
t.sortby = "ID"
t.align["ID"] = "l"
t.align["Name"] = "l"
t.align["Description"] = "l"
t.align["Groups"] = "l"
t.align[param_field_name.capitalize()] = "l"
return t
def get_validations_json(validations_data):
"""Return the validations information as a pretty printed json """
return json.dumps(validations_data, indent=4, sort_keys=True)