Browse Source

Merge "Refactoring of the cli lister module"

changes/13/790913/3
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
48f2435436
3 changed files with 21 additions and 19 deletions
  1. +3
    -6
      validations_libs/cli/lister.py
  2. +3
    -2
      validations_libs/utils.py
  3. +15
    -11
      validations_libs/validation_actions.py

+ 3
- 6
validations_libs/cli/lister.py View File

@ -14,9 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import sys
from cliff.lister import Lister
from validations_libs.validation_actions import ValidationActions
@ -34,7 +31,7 @@ class ValidationList(Lister):
metavar='<group>[,<group>,...]',
action=CommaListAction,
default=[],
help=("Run specific group validations, "
help=("List specific group of validations, "
"if more than one group is required "
"separate the group names with commas: "
"--group pre-upgrade,prep | "
@ -42,12 +39,12 @@ class ValidationList(Lister):
parser.add_argument('--validation-dir', dest='validation_dir',
default=constants.ANSIBLE_VALIDATION_DIR,
help=("Path where the validation playbooks "
"is located."))
"are located."))
return parser
def take_action(self, parsed_args):
"""Take validation action"""
# Get parameters:
group = parsed_args.group
validation_dir = parsed_args.validation_dir


+ 3
- 2
validations_libs/utils.py View File

@ -66,6 +66,7 @@ def parse_all_validations_on_disk(path, groups=None):
:type path: `string`
:param groups: Groups of validations. Could be a `list` or a
comma-separated `string` of groups
:type groups: `list` or `string`
:return: A list of validations metadata.
:rtype: `list`
@ -90,8 +91,8 @@ def parse_all_validations_on_disk(path, groups=None):
validations_abspath = glob.glob("{path}/*.yaml".format(path=path))
for pl in validations_abspath:
val = Validation(pl)
for playbook in validations_abspath:
val = Validation(playbook)
if not groups or set(groups).intersection(val.groups):
results.append(val.get_metadata)


+ 15
- 11
validations_libs/validation_actions.py View File

@ -46,10 +46,17 @@ class ValidationActions(object):
else constants.ANSIBLE_VALIDATION_DIR)
def list_validations(self, group=None):
"""Get a list of the available validations
"""Get a list of the validations selected by group
membership. With their names and group membership information.
This is used to print table from python ``Tuple`` with ``PrettyTable``.
:param group: Group or multiple groups of validations.
Additional groups have to be separated by comma.
:type group: `string`
:return: Column names and a list of the selected validations
:rtype: `tuple`
.. code:: text
----------------+--------------------------+----------------------+
@ -60,9 +67,6 @@ class ValidationActions(object):
| validation3 | Name of the validation3 | ['group4] |
+---------------+--------------------------+----------------------+
:return: The list of the available validations
:rtype: `tuple`
:Example:
>>> path = "/foo/bar"
@ -77,13 +81,13 @@ class ValidationActions(object):
validations = v_utils.parse_all_validations_on_disk(
self.validation_path, group)
return_values = []
column_name = ('ID', 'Name', 'Groups')
return_values = [
(val.get('id'), val.get('name'), val.get('groups'))
for val in validations]
column_names = ('ID', 'Name', 'Groups')
for val in validations:
return_values.append((val.get('id'), val.get('name'),
val.get('groups')))
return (column_name, return_values)
return (column_names, return_values)
def show_validations(self, validation,
log_path=constants.VALIDATIONS_LOG_BASEDIR):


Loading…
Cancel
Save