65 Commits

Author SHA1 Message Date
matbu
2e7216b3fe Remove log_path parameter so it can be only set by the constructor
This parameter was deprecates, this patch clean the log path parameter
in the ValidationAction function.

Change-Id: I92bc1bdc7341308fd1989f78601e491f72f9bf6c
2022-09-30 10:28:04 +02:00
Zuul
69cd8a4973 Merge "Removed explicit inheritance from object" 2022-04-28 21:27:32 +00:00
Jiri Podivin
e510ed451b Exceptions for Validations Framework
Introduces two new exceptions for Validation Framework
to be raised within appropriate context.

ValidationRunException - signifying incorrect behavior of the Run action code
ValidationShowException - signifying incorrect behavior of the Show actions code

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I87f315e7bb2e28a8572982a71fbe2be4432ff2c0
2022-03-24 09:17:37 +01:00
Jiri Podivin
9163d8bcbc Moving callbacks to validations-libs
Callback plugins were transferred from validations-common
repository to validations-libs.

Necessary adjustments were made to the module structure,
requierements, as well as installation and documentation generator config.

Associated tests were moved as well, with removal of superfluous inheritance
and imports included.

Demonstration http server module for communication with `http_json`
callback was moved with directory structure preserved.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I31768375430a2f29da71aae8f3db3882c373ced5
2022-03-10 08:59:40 +00:00
Jiri Podivin
b24d4ce792 Validation actions refactor
Unused workdir argument of the run_validations method removed.

Host and playbook skipping simplified.

Docstrings adjusted, including some of the more important
inline code examples.

Test sensitivity to API changes was increased.
More strict assertions have been put on the calls made in CLI.

Logging statements related to the run action
in validation_actions.py were expanded.

New debug level logging statements introduced.

One of the testing constants in the fakes.py was altered
as it was not accurate representation of the real data,
and as such was breaking the new logging statements
during unit test runs.

Deprecation notice for 'log_path' and 'groups' arguments,
in both docstring and logging.

Redundant conditionals for argument types were removed.

The checks of the arguments are implemented
in the function called in the subsequent statement.

As there is no scenario in which one set of these checks
passes, while the other fails with the same values,
we can consider one of them to be redundant.

Helper function 'get_validations_details' without active references
was removed from utils submodule.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I781f6a6f9fc4bd558af56b648f0e0ee9f165dfab
2022-01-21 13:33:22 +01:00
Gael Chamoulaud (Strider)
ed33291a86
Disable spinner when running validation in non quiet mode
When using the custom callback feature through the run CLI subcommand,
by passing --extra-env-vars ANSIBLE_STDOUT_CALLBACK=default, the spinner
makes the output a bit ugly.

This patch disables the spinner in non quiet mode.

Change-Id: I9f92894fe446f4881e0234b1577e49f9e7091b7b
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2021-11-24 15:55:16 +01:00
apetrich
5ba9c429d5 Add the community validation paths
The validation framework now respect and look for community
validation on the path. There config setting for
enable_community_validations is respected.

The community validations appear on validations list,
can be called by group, category, id and so on seamless
like any other validation.

Change-Id: I4a6230ac5433028c7297fa88f77728c87d60173d
Signed-off-by: Adriano Petrich (apetrich) <apetrich@redhat.com>
2021-11-18 09:55:30 +01:00
Jiri Podivin
7d416acbe8 Default value of the constructor parameter
The default value of the validation_path parameter
is now handled properly, without unnecessary conditional.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I4cc16732ea9d98ec47c2dc616105944bdd6106f0
2021-10-08 14:18:19 +02:00
matbu
b37015ee1f Expose skip list mechanism via the CLI
The skip list feature was available only via the API, this patch
allow the user to pass a file with the list of the validations
which he wants to skip during the run, example:

check-ram: hosts: all
  reason: Wrong ram value
  lp: https://lp.fake.net
check-cpu: hosts: undercloud
  reason: Unstable validation
  lp: https://lp.fake.net
Change-Id: I04059f9339085e0dcef1f018cad1be511ee7d3c7
2021-10-06 13:45:08 +00:00
matbu
11488cd88d Add validation config file mechanism
Introduce validation config file.
The config default location of the config file will be stored
in /etc/validation.cfg

The variables precedence will be the following:
* user's cli args
* config file
* default interval values

Change-Id: I05c54a43bc0a03878793cca3f51e23f4a8b63a23
2021-08-20 08:12:16 +00:00
Jiri Podivin
f1cd8eebc1 Validations show group filtering
The 'ValidationActions.group_information' method was refactored
to reflect new signature of the 'utils.parse_all_validations_on_disk' function.

Tests were adjusted accordingly.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Ic2ca556441169594792d7d5835ea057e9256a7a9
2021-08-09 16:06:12 +02:00
Gael Chamoulaud (Strider)
c46c90394c Add Products metadata key management
This patch adds the management of the new `products` metadata key in the
validation playbooks. We can now filter the validations by their groups,
by their categories or by their products while listing or running them.

The `list` sub command has now a new --product argument. When filtering
by groups, by categories or by products (see the example below), the
`list` sub command will return all the validation playbooks belonging to
the 'prep' group OR all the validation playbooks belonging to the 'os'
and/or 'system' categories OR all the validation playbooks to the
'tripleo' product:

$ validation list -h
$ validation list --group prep --category os,system --product tripleo

The `run` sub command has also its new --product argument. Note that
this new argument is mutually exclusive with the --validation, --group
and --category arguments:

$ validation run -h
$ validation run --product tripleo --inventory /etc/ansible/hosts

The `show parameter` sub command has the same new argument which is also
mutually exclusive with the --validation, --group and the --category
arguments:

$ validation show parameter -h
$ validation show parameter --product tripleo

Change-Id: Ief13e506c2bee18da47b31f1c2d5c0dbb1ad1ecf
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2021-07-27 07:01:05 +00:00
Gael Chamoulaud (Strider)
3928305329 Add Categories metadata key management
This patch adds the management of the new `categories` metadata key in
the validation playbooks. We can now filter the validations by their
groups and/or by their categories while listing or running them.

The `list` sub command has now a new --category argument. When filtering
by groups and by categories (see the example below), the `list` sub
command will return all the validation playbooks belonging to the prep
group OR all the validation playbooks belonging to the os and/or system
categories:

$ validation list -h
$ validation list --group prep --category os,system

The `run` sub command has also its new --category argument. Note that
this new argument is mutually exclusive with the --validation and
--group arguments:

$ validation run -h
$ validation run --category networking --inventory /etc/ansible/hosts

The `show parameter` sub command has the same new argument which is also
mutually exclusive with the --validation and --group arguments:

$ validation show parameter -h
$ validation show parameter --category os,system,hardware,ram

Change-Id: I4297f83355bdd209d21518fbadb17d1343fd4680
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2021-07-27 07:00:47 +00:00
Zuul
9a594f70c9 Merge "Remove convert_data function" 2021-07-16 03:27:39 +00:00
Gael Chamoulaud (Strider)
2f3b09d41e
Remove convert_data function
This patch removes the convert_data function which has been introduced
with the first one and deprecated Command Line Interface. The
--validation and --group arguments were sending comma-separated strings
instead of list. The new Command Line Interface is now enforcing this by
using its own CommaList Parser Action and only accepting List of groups
or validation names.

This function is now useless and can be removed safely. Tests and usages
have been modified accordingly.

Change-Id: Ief9459e914ea73fbd59a85c07a55c26078e0126a
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2021-07-13 22:14:19 +02:00
David J Peacock
e11b458946 add spinner to highlight progress
Implementing a Spinner class and utilizing it around a run action.  This
will add a moving icon that animates in place until output is reached,
letting the operator know that things are happening.

The interactive TTY test is included to ensure that during some unknown
usage such as logging to disk this feature doesn't spew unnecessary
clutter.

Change-Id: Ieef256a5c12b238008e9250c0ee182d80a2b6dfb
2021-07-13 11:14:41 -04:00
Zuul
84fe505f26 Merge "Expansion of logging for the list action" 2021-06-07 13:44:57 +00:00
Jiri Podivin
f2830c5244 Improved log path handling
Validations logging now has several documented fallbacks.
constants.py now includes constant default path,
in order to improve readability and provide reference.

Tests are included.

Complementary patch for validations_commons callbacks
is optional, as the behavior should stay largely the same.

Co-Authored-By: mbu <mat.bultel@gmail.com>
Change-Id: Iab5f246f22fa6998ea6cec578eec6ebb5de13ad4
2021-06-04 14:01:51 +02:00
Jiri Podivin
91c17107c5 Expansion of logging for the list action
Two new logging calls for the list action on the
info and debbug level.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I56044c93b03531159953c323f8e530d833819a5f
2021-06-03 08:39:23 +02:00
Zuul
eaf304f62e Merge "Refactoring of the cli show module" 2021-06-02 13:31:52 +00:00
Jiri Podivin
254d4472f0 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
2021-06-01 17:04:44 +02:00
Jiri Podivin
b2e87ca49a Refactoring of the cli show module
New logging statements for the action and related
method call of 'ValidationActions' class.

Expanded exception handling for the 'show_validations_parameters'
method of the 'ValidationActions' class.

Removal of superfluous imports.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I2ad5a212dcd4cdb40ca04f7cce3d18c7527f63b2
2021-05-31 05:09:04 +00:00
Jiri Podivin
6bfdb04137 Retrieve n latest validation results
New optional parameter for the CLI limiting
number of validation results returned by history subcommand.

Resolves: rhbz#1944872

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Ie79062e85351ed545c33001866773bf38fdf8517
2021-05-07 12:37:55 +02:00
matbu
5fad1a4d18 Create dedicated CLI for the Validation Framework
This review adds a CLI for the Validation Framework which will become
the only entry point to run the Validation Framework.

It will deprecate the tripleo_validatior.py CLI and the
validation.py script.

This patch uses python cliff library to provide nice helpers, shell
and output formats.

Change-Id: I66800ad51cc50f4eb37efabe85fb553dce008101
2021-04-20 11:52:35 +02:00
matbu
d83be8b169 Expose ansible ssh_user variable to the run action
Change-Id: I6ae1f55ea261064b418e25cd4cf255f386a20fb3
2021-04-15 15:56:48 +02:00
Mathieu Bultel
6a2008950f Expose callback_whitelist option to Run action
The callback_whitelist is not usable via the Run action for now.
The patch allow users to pass  a list of callbacks to whitelist
during the validation run.

Altered docstrings to include changed type spec.

Change-Id: I37eb369701ccbd1d3fd4a7601a5e626d5867381d
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Signed-off-by: Mathieu Bultel <mat.bultel@gmail.com>
2021-03-21 12:30:47 +00:00
Zuul
c54307403a Merge "show command now properly uses list of validations" 2021-02-18 16:51:15 +00:00
Mathieu Bultel
618cde0569 Add skip list option in order to provide a black list for validation
Should be formed as:
{'xyz':
  {'hosts': 'ALL',
   'reason': None,
   'lp': None}
}

Change-Id: I030344ad3ec117548b78284cb4f12265a0719c3a
2021-02-17 16:36:41 +01:00
Jiri Podivin
f60caf8e66 show command now properly uses list of validations
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Iced465a7380acc2bd7065c1fc2dc34e6ddcd9b15
2021-02-15 14:03:55 +01:00
Jiri Podivin
45b8600a1a Secondary loop removed. params_only dict now uses update method.
Performance improvement is purely hypothetical.
However, the altered code is more readable.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Iaa85213a439ee4222c3d7fa6fc513458095b8ac3
2021-01-25 17:52:44 +01:00
Zuul
528c44b4e7 Merge "Local vars were redefining builtins" 2021-01-22 17:12:53 +00:00
Jiri Podivin
a68b40af2d Removed explicit inheritance from object
All python classes already inherit from object implicitly.
There is no need to keep it there.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Ic56242fc20ef27e4b96b09319280e87db130e4cb
2021-01-22 16:07:43 +01:00
Mathieu Bultel
a0db6e4892 Allow to provide different stdout callback to the libs
This patch depends on the callback modifcation which
allow to give other custom or default/standard callback
for the stdout from the user.

With the current situation, when passing another callback
than validation_json it breaks the VF logging.
We need to separate logging and stdout.

Change-Id: I1566d9763212f9538fea1c0885208db6b949023f
2021-01-18 07:53:19 +01:00
Jiri Podivin
8dc1549ddd Local vars were redefining builtins
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Iecdcae0be0d8363668f77f9de4f8a431a8162f5e
2021-01-14 12:54:39 +01:00
Mathieu Bultel
fd226ce290 Handle dynamically the ansible artifacts dir path
Change-Id: Ic28afceca1decc6f5bf3bdd5a2630c1a44138e5a
2020-12-11 13:13:19 +00:00
Gael Chamoulaud (Strider)
c1115710c7
Add Docstrings to validations_libs/validation_action.py file
Change-Id: I69fc8bc37ff0009e9bbc4d0fe32ea444174ca9e7
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2020-11-18 12:23:39 +01:00
Gael Chamoulaud (Strider)
484d7a9a78
Remove output format test in utils.get_validations_parameters
This is now done in validation_actions.show_validations_parameters(..)
[1].

[1] https://opendev.org/openstack/validations-libs/src/branch/master/validations_libs/validation_actions.py#L206-L209

Change-Id: I9f90ba97758422a35280b91e6d3edae624564728
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2020-11-09 14:11:12 +01:00
Gael Chamoulaud (Strider)
63e30c744c
Add better conversion of string parameters into a list
The current conversion works pretty well when passing a simple string
of validation or group names. But don't work when passing multiple
validation or group name.

```
>>> groups = "check-cpu"
>>> groups = [groups]
>>> print(groups)
['check-cpu']

>>> groups = "check-cpu,check-ram"
>>> groups = [groups]
>>> print(groups)
['check-cpu,check-ram']
```

This patch brings a better conversion when multiple validations or
groups are sent through a string.

Change-Id: Iba023a704dd873ea2df75c8cc6d78f929ef45bc2
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2020-11-04 14:05:11 +01:00
Gael Chamoulaud (Strider)
9192d5826c
Don't rely on parameter file extension for downloading
This patch also adds unittests and docstrings for the
show_validations_parameters method.

Change-Id: I7da1ef5607f6a7b164f87dace3a49a14e6cbf06f
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2020-11-04 09:48:08 +01:00
Cédric Jeanneret
6d0d1ce06d Ensure we're using proper types for validation_name and _id
In some case we might get string instead of list - instead of failing,
just do a simple convertion and go on.

We also support both notation, either playbook name (foo.yaml) and
validation name (foo) in the search of valid content.

Co-Authored-By: Gael Chamoulaud (Strider) <gchamoul@redhat.com>

Change-Id: I8d0288dae3cab131a8bc65e3d0b986dc6b9aec67
Closes-Bug: #1901676
2020-10-27 15:12:40 +01:00
Zuul
0c7eda82d3 Merge "Fix parameters management" 2020-10-26 12:46:02 +00:00
Gael Chamoulaud (Strider)
d79245eb82
Fix parameters management
This patch fixes multiple things:

* from validations_libs.validation_actions import show_validations_parameters

The generated file was containing the validations names and their
existing parameters as returned by the get_validations_parameters
method. But the file should only contains the parameters.

* from validations_libs.utils import get_validations_playbook

This method was supposed to get a list of validations playbooks
abs. path either by their names or their groups. This method was working
only when giving validation names but not with groups.

This patch fixes all the problems above and make the parameters
management work again.

Change-Id: Iec30cccade1234a127ef406ed13604cce45a72fd
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2020-10-22 17:26:40 +02:00
Gael Chamoulaud (Strider)
87114686ae
[Validator Run] Detect unknown validations from the command-line
When executing multiple validations with at least one unknown
validation, the CLI was executing only the existing ones but was not
informing the user that he/she typed one or more wrong validations.

This patch fixes that issue by detecting which validations are wrong and
inform the user.

Depends-On: https://review.opendev.org/758821

Change-Id: I4910043df07f32539793a2bc464377603fe2b02f
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2020-10-21 12:29:01 +02:00
Mathieu Bultel
0e46a5b710 Fix show validation stats with correct number
Change-Id: I48a09cac03bd5dea69e216babc7f4332ad47f52b
2020-10-13 16:05:55 +02:00
Mathieu Bultel
1ac91f1f31 Allow to set python interper for ansible execution
Some environment still use python2.7 and so /usr/bin/python
interpreter for ansible.
In that case, Ansible will fail to execute.
This option allow the user to pass a specific python interpeter
for the remote.
In None python_interpreter, and connection local is set we use
the local sys.executable, if both are None we use the default.

Change-Id: I4bd25ed50091a963d0b1e5e3a727ece19b90747e
2020-09-03 11:08:01 +02:00
Mathieu Bultel
15e74046c1 Add a way to override the default validation log path
Export a log path passed by the user in order to override the default
value from the callback

Change-Id: I736c527254cf17d25eeda0a4007102838280609c
2020-07-24 15:05:28 +02:00
Mathieu Bultel
21a722adac Show history by play and add get status action
Show history filtered by plays to get a better view
if a log file contains a lot of playbooks.

Add get_status action in order to get debug information
of a given validation failure

Change-Id: I29ab90647d9ef9c86546065ca16a62c401be1969
2020-07-06 15:10:37 +00:00
Mathieu Bultel
de03576eeb Remove playbook param from run_validation
Removing playbook parameters from run_validation function
since its overlap validation_name functionality and make it
confusing.

Change-Id: Ifff9bdb327b38db07df6cac328cbd387f2bc46f1
2020-06-17 11:56:04 +02:00
Mathieu Bultel
c1d9cb9b92 Filter get_all_log_file by extension
Since the user can provide a path to a directory which can
be polute by undesirable files, filter by extension can avoid
parsing wrong files

Change-Id: I378b32d58cd1ec3a5688bba0831716bf94f18f05
2020-06-12 09:19:41 +02:00
Mathieu Bultel
b5cc8dff75 Handle multiple validation logs results
Change-Id: I49d284edc2e1c54fb8c365e52146c656440b5db2
2020-05-18 14:53:52 +02:00