Browse Source

Refactoring of the cli lister module

Removed unused imports.
Fixed up typos in help strings.
Replaced loop with list comprehesion in the `list_validations`
method of the `ValidationActions`.

Docstrings ammended to reflect actual state of the code.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Ie8deccf4c9c60872418a9c29da39f0d5baaad0bf
changes/74/793274/4
Jiri Podivin 2 months ago
parent
commit
254d4472f0
  1. 9
      validations_libs/cli/lister.py
  2. 5
      validations_libs/utils.py
  3. 26
      validations_libs/validation_actions.py

9
validations_libs/cli/lister.py

@ -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

5
validations_libs/utils.py

@ -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)

26
validations_libs/validation_actions.py

@ -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