43 Commits

Author SHA1 Message Date
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
Gael Chamoulaud (Strider)
1bbf282356
Add new CLI sub command to create community validations
Presently, the operator(s) can only execute the official and supported
validations coming from tripleo-validations and validations-common.
Community validations enable a sysadmin to create and execute
validations unique to their environment.

This patch introduces the new Command Line Interface sub command to
create a new community validation skeleton. First, this latter will
check if there is an existing role or a playbook either in the community
validations catalog or the official validations catalog.  And it will
create an Ansible role (with ansible-galaxy[1]) and a playbook in the
~/community-validations directory.

By default, the community validations feature is enabled but may be
disabled by setting [DEFAULT].enable_community_validations to ``False``
in the validation configuration file.

Example:

[stack@localhost]$ validation init my-new-validation
Validation config file found: /etc/validation.cfg
New role created successfully in /home/stack/community-validations/roles/my_new_validation
New playbook created successfully in /home/stack/community-validations/playbooks/my-new-validation.yaml

For a full demo of this new CLI sub command, please take a look at this
asciinema[2].

[1] - https://docs.ansible.com/ansible/latest/cli/ansible-galaxy.html
[2] - https://asciinema.org/a/445105

Change-Id: I8fb16e3456696187d4a9d3820740a7639a96e315
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2021-10-29 15:39:39 +02: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
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
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
Jiri Podivin
4d1df7b0e7 New optional param for log path
As we now have a mechanism for falling back to
a default directory for logs and artifacts, we can allow
the customers to specify their own.

This patch add the argument to the CLI along with
minimum necessary information about the usage.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Id31a7ce2dfc4d9a132fea7d600e8beb8adc0739b
(cherry picked from commit 7876cab41586157a1b5e8fd426deb16d79567a52)
2021-06-10 14:07:10 +02:00
Jiri Podivin
48cc737446 Fixing the recursive path handling.
The patch f2830c52446b1bd57383e91e6eb3da84cfdab1c7 introduced
several potentially breaking bugs, which have to be fixed.
Namely, several of the termination conditionals lacked proper
return statements.

In addition to the fix of the previously describe issues
the following changes are included to prevent more arising in
the future.

Every major behavioral branch now has a dedicated log statement.
Test coverage included.
Expanded docstrings.
Increased expressiveness of var names.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Ie7471361acf1f4ae197e76b22eb7ba4d3f62fe92
2021-06-10 11:25:21 +02:00
Zuul
1d33aa38f6 Merge "Constants path formatting unification" 2021-06-07 19:15:11 +00:00
Zuul
84fe505f26 Merge "Expansion of logging for the list action" 2021-06-07 13:44:57 +00:00
Zuul
2dc6b358f5 Merge "Expansion of logging for the show action." 2021-06-07 13:44:36 +00:00
Jiri Podivin
a70ad12043 Constants path formatting unification
Paths in the constants.py are now formatted
using a single function, the os.path.join.

This both normalizes the code and reduces
chance of errors and confusion arising
from nonstandard paths.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I761c4449579590b9081a78627eeac754d6b04e2a
2021-06-04 14:18:28 +02: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
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
eb439a35db Expansion of logging for the show action.
New logging calls on the debug level.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I3b2f0bfaa9d92e9cc664dea8ba5f7966c6931837
2021-05-31 05:16:00 +00:00
Jiri Podivin
12cd88dfe2 Fixes string formatting of the error msg log
Apart from incomplete output the incorrect formatting
causes followup exception further obfuscating the original issue.
Minor issue related to:
	BGZ:1895045

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Ibed0bc4b78be957819205bed76073e72820ab2a1
2021-03-10 09:13:39 +01:00
Daniel Bengtsson
28e069f170 Remove the condition to check the groups.
The code of the groups property in the Validation class changed. Before
the code didn't check if the key groups was there. You can see the
change[1] to have more information.

[1] eb62054a33

Closes-bug: #1917785
Co-authored-by: Owen McGonagle <omcgonag@redhat.com>
Change-Id: Ib11fd1b829bd56c19f82081d53440b4dd8237f3f
2021-03-04 17:35:45 +01:00
Owen McGonagle
e21f6f11f8 Add an error message when groups is not found in the playbook
If there are no groups in the playbook, we currently get a python error
when running command 'openstack tripleo validator group info'

Change-Id: Ice089c33d566e90bea55e18fe7f77f9d33fe81f3
2021-01-27 13:20:38 -05:00
Gael Chamoulaud (Strider)
a6271afa38
Add docstrings to utils.py
This patch also adds new unittests for the following functions:
- from validations_libs.utils import get_validations_data
  > test_get_validations_data_wrong_type(..)
- from validations_libs.utils import get_validations_details
  > test_get_validations_details_wrong_type(..)

Change-Id: Iac9ba971a73ed09b26d3e41efb38ad72dd942bbc
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2020-11-09 15:03:08 +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
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
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
Mathieu Bultel
cba2ce087d Add parameters values to the validation show command
The parameters was missing to the validation show output.

Change-Id: I1d2ebeb3fbe8a1438e8acec77d3a15b2816f786f
2020-10-14 07:47:09 +02:00
Mathieu Bultel
c0de9faa41 Format output in json or yaml for validations show param
Change-Id: I93b35cd1619e2c2b4a3b1294171dddf56033e94f
2020-04-16 08:26:04 +00:00
Mathieu Bultel
c940a0c30d Add unit tests coverage for validation, group and logs classes
Increase the unit tests coverage for recent code:
validation, group and logs classes.
(Increase of 54 unit tests)

Move per action files into one test file:
test_validation_actions

Change-Id: I7a1a8b0681c13ebd758a5686b2398a0a9e87a4eb
2020-04-02 09:41:30 +00:00
Mathieu Bultel
1daa430f9a Fix behavior for Show command to stick to tripleoclient
The behavior of the Show command wasn't exactly as tripleoclient
This review aims to fix it

Change-Id: I4e1af84675bfe722e232217f15c29fbc3d006333
2020-03-26 14:58:34 +01:00
Mathieu Bultel
c98ea9195a Add get validation playbook function and cleanup
Remove unsed function and add get validation playbook function

Change-Id: I5fbcbab7a402dd1149fa6df718f530a3ee5c6af2
2020-03-24 00:01:22 +01:00
Mathieu Bultel
bcd72301f6 Add validation log object representation
Create two classes for Log and Logs in order to get
a simpler representation of the validation Log and
provide easy way to manage the log data informations

Change-Id: I743355cef943e43492264d4c4700bebbeab9a37d
2020-03-23 21:54:21 +00:00
Mathieu Bultel
fd95a175b7 Implement Validation Show Parameters
Change-Id: Ie3366f4f32dd87871315cc9f95f7c2335df25e4b
2020-03-20 13:45:12 +00:00
Mathieu Bultel
491a27b53c Add validation_actions class and group info implementation
Move all validation actions into a ValidationActions class
in order to have one object with several validations actions

Add group info implementation
And add group object like validation object to have
a simpler representation of the validation group.

Change-Id: Idc7a55e26de20968f0a6a90f2a005d21a30c9e70
2020-03-20 13:44:53 +00:00
Mathieu Bultel
95edef7a8c Move validation data as object
Change-Id: I1b82f3ef24b80d55f96bd76c17278b988e4b611d
2020-03-20 13:21:13 +00:00
Mathieu Bultel
132735a697 Remove unused classes for PushD and Tempdir
Change-Id: I169036ef7556e7d259c0b84dd357eba7230d9313
2020-03-17 16:10:17 +01:00
Mathieu Bultel
d2c91c8080 Add validations show functions
This review add functionnalities to parse and show
validations output as dict with the required format

Change-Id: I57ca3d18397c7fbdb084b06224d7cab3d4592d30
2020-03-17 09:54:28 +00:00
Gael Chamoulaud (Strider)
84aa2b6846
Improve the way we log on the file system
Improve the way we log on the file system and share
the same uuid for callback logging and ansible
runner and artifact logging

This patch also adds zuul.d directory:
* Adds zuul.d/layout.yaml
* Adds .gitreview file
* Fixes ansible-runner requirements issue

Co-Authored-By: Gael Chamoulaud <gchamoul@redhat.com>
Change-Id: I4da8c1974362029754aa5b09cd8e6c7d6a27dd0d
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
2020-03-11 17:07:56 +01:00
Mathieu Bultel
07e56863b9 remove untested get_result functions from this PR 2020-03-09 14:44:24 +01:00
Mathieu Bultel
32d15b6a1b Add unit tests for ansible runner library 2020-03-09 14:21:03 +01:00
Mathieu Bultel
0a71d73e4e fix nits 2020-03-04 15:26:35 +01:00
Mathieu Bultel
9e308dbae4 fix pep8 lint 2020-03-04 10:50:14 +01:00
Mathieu Bultel
138ef53e5b Add run and ansible_runner execution 2020-03-04 10:50:14 +01:00
Mathieu Bultel
ec9c986de8 fix module import 2020-03-03 18:57:40 +01:00
Mathieu Bultel
8cce4bfd64 Add utils functions and validations List object 2020-03-03 16:55:20 +01:00