validations_libs.validation_actions module

class validations_libs.validation_actions.ValidationActions(validation_path='/usr/share/ansible/validation-playbooks', groups_path='/usr/share/ansible/groups.yaml', log_path='/home/zuul/src/opendev.org/openstack/validations-libs/.tox/docs/validations')[source]

Bases: object

An object for encapsulating the Validation Actions

This class allows the possibility to execute the following actions:

  • List the available validations

  • Show detailed information about one validation

  • Show the available parameters for one or multiple validations

  • Show the list of the validation groups

  • Run one or multiple validations, by name(s) or by group(s)

  • Show the history of the validations executions

get_status(validation_id=None, uuid=None, status='FAILED')[source]

Return validations execution details by status

Parameters:
  • validation_id (string) – The validation id

  • uuid (string) – The UUID of the execution

  • status (string) – The status of the execution (Defaults to FAILED)

Returns:

A list of validations execution with details and by status

Return type:

tuple

Example:

>>> actions = ValidationActions(validation_path='/foo/bar')
>>> status = actions.get_status(validation_id='foo'))
>>> print(status)
(['name', 'host', 'status', 'task_data'],
 [('Check if debug mode is disabled.',
 'localhost',
 'FAILED',
 {'_ansible_no_log': False,
     'action': 'fail',
     'changed': False,
     'failed': True,
     'msg': 'Debug mode is not disabled.'}),
 ('Check if debug mode is disabled.',
 'localhost',
 'FAILED',
 {'_ansible_no_log': False,
     'action': 'fail',
     'changed': False,
     'failed': True,
     'msg': 'Debug mode is not disabled.'}),
 ('Check if debug mode is disabled.',
 'localhost',
 'FAILED',
 {'_ansible_no_log': False,
     'action': 'fail',
     'changed': False,
     'failed': True,
     'msg': 'Debug mode is not disabled.'})])
group_information(groups=None, validation_config=None)[source]

Get Information about Validation Groups

This is used to print table from python Tuple with PrettyTable.

+----------+--------------------------+-----------------------+
| Groups   | Description              | Number of Validations |
+----------+--------------------------+-----------------------+
| group1   | Description of group1    |                     3 |
| group2   | Description of group2    |                    12 |
| group3   | Description of group3    |                     1 |
+----------+--------------------------+-----------------------+
Parameters:
  • groups (string) – The absolute path of the groups.yaml file. The argument is deprecated and will be removed in the next release. Use the ‘groups_path’ argument of the init method.

  • validation_config (dict) – A dictionary of configuration for Validation loaded from an validation.cfg file.

Returns:

The list of the available groups with their description and the numbers of validation belonging to them.

Return type:

tuple

Example:

>>> groups = "/foo/bar/groups.yaml"
>>> actions = ValidationActions(constants.ANSIBLE_VALIDATION_DIR, groups)
>>> group_info = actions.group_information()
>>> print(group_info)
(('Groups', 'Desciption', 'Number of Validations'),
 [('group1', 'Description of group1', 3),
  ('group2', 'Description of group2', 12),
  ('group3', 'Description of group3', 1)])
list_validations(groups=None, categories=None, products=None, validation_config=None)[source]

Get a list of the validations selected by group membership or by category. With their names, group membership information, categories and products.

This is used to print table from python Tuple with PrettyTable.

Parameters:
  • groups (list) – List of validation groups.

  • categories (list) – List of validation categories.

  • products (list) – List of validation products.

  • validation_config (dict) – A dictionary of configuration for Validation loaded from an validation.cfg file.

Returns:

Column names and a list of the selected validations

Return type:

tuple

-------+-----------+----------------------+---------------+--------------+
| ID   | Name      | Groups               | Categories    | Products     |
+------+-----------+----------------------+---------------+--------------+
| val1 | val_name1 | ['group1']           | ['category1'] | ['product1'] |
| val2 | val_name2 | ['group1', 'group2'] | ['category2'] | ['product2'] |
| val3 | val_name3 | ['group4']           | ['category3'] | ['product3'] |
+------+-----------+----------------------+---------------+--------------+
Example:

>>> path = "/foo/bar"
>>> groups = ['group1']
>>> categories = ['category1']
>>> action = ValidationActions(validation_path=path)
>>> results = action.list_validations(groups=groups,
                                      categories=categories)
>>> print(results
(('ID', 'Name', 'Groups', 'Categories', 'Products'),
 [('val1',
   'val_name1',
   ['group1'],
   ['category1'],
   ['product1']),
  ('val2',
   'val_name2',
   ['group1', 'group2'],
   ['category2'],
   ['product2'])])
run_validations(validation_name=None, inventory='localhost', group=None, category=None, product=None, extra_vars=None, validations_dir=None, extra_env_vars=None, ansible_cfg=None, quiet=True, limit_hosts=None, run_async=False, base_dir='/usr/share/ansible', python_interpreter=None, skip_list=None, callback_whitelist=None, output_callback='vf_validation_stdout', ssh_user=None, validation_config=None, exclude_validation=None, exclude_group=None, exclude_category=None, exclude_product=None)[source]

Run one or multiple validations by name(s), by group(s) or by product(s)

Parameters:
  • validation_name (list) – A list of validation names.

  • inventory (string) – Either proper inventory file, or a comma-separated list. (Defaults to localhost)

  • group (list) – A list of group names

  • category (list) – A list of category names

  • product (list) – A list of product names

  • extra_vars (Either a Dict or the absolute path of JSON or YAML) – Set additional variables as a Dict or the absolute path of a JSON or YAML file type.

  • validations_dir (string) – The absolute path of the validations playbooks

  • extra_env_vars (dict) – Set additional ansible variables using an extravar dictionary.

  • ansible_cfg (string) – Path to an ansible configuration file. One will be generated in the artifact path if this option is None.

  • quiet (Boolean) – Disable all output (Defaults to True)

  • limit_hosts (string) – Limit the execution to the hosts.

  • run_async (boolean) – Enable the Ansible asynchronous mode (Defaults to False)

  • base_dir (string) – The absolute path of the validations base directory (Defaults to constants.DEFAULT_VALIDATIONS_BASEDIR)

  • python_interpreter (string) – Path to the Python interpreter to be used for module execution on remote targets, or an automatic discovery mode (auto, auto_silent or the default one auto_legacy)

  • callback_whitelist (list or string) – Comma separated list of callback plugins. Custom output_callback is also whitelisted. (Defaults to None)

  • output_callback (string) – The Callback plugin to use. (Defaults to ‘validation_stdout’)

  • skip_list (dict) – List of validations to skip during the Run form as {‘xyz’: {‘hosts’: ‘ALL’, ‘reason’: None, ‘lp’: None} } (Defaults to ‘None’)

  • ssh_user (string) – Ssh user for Ansible remote connection

  • validation_config (dict) – A dictionary of configuration for Validation loaded from an validation.cfg file.

  • exclude_validation (list) – List of validation name(s) to exclude

  • exclude_group (list) – List of validation group(s) to exclude

  • exclude_category (list) – List of validation category(s) to exclude

  • exclude_product (list) – List of validation product(s) to exclude

Returns:

A list of dictionary containing the informations of the validations executions (Validations, Duration, Host_Group, Status, Status_by_Host, UUID and Unreachable_Hosts)

Return type:

list

Raises:

ValidationRunException

Example:

>>> path = "/u/s/a"
>>> validation_name = ['foo', 'bar']
>>> actions = ValidationActions(validation_path=path)
>>> results = actions.run_validations(inventory='localhost',
                                      validation_name=validation_name,
                                      quiet=True)
>>> print(results)
[{'Duration': '0:00:02.285',
  'Host_Group': 'all',
  'Status': 'PASSED',
  'Status_by_Host': 'localhost,PASSED',
  'UUID': '62d4d54c-7cce-4f38-9091-292cf49268d7',
  'Unreachable_Hosts': '',
  'Validations': 'foo'},
 {'Duration': '0:00:02.237',
  'Host_Group': 'all',
  'Status': 'PASSED',
  'Status_by_Host': 'localhost,PASSED',
  'UUID': '04e6165c-7c33-4881-bac7-73ff3f909c24',
  'Unreachable_Hosts': '',
  'Validations': 'bar'}]
show_history(validation_ids=None, extension='json', history_limit=None)[source]

Return validation executions history

Parameters:
  • validation_ids (a list of strings) – The validation ids

  • extension (string) – The log file extension (Defaults to json)

  • history_limit (int) – The number of most recent history logs to be displayed.

Returns:

Returns the information about the validation executions history

Return type:

tuple

Example:

>>> actions = ValidationActions(constants.ANSIBLE_VALIDATION_DIR)
>>> print(actions.show_history())
(('UUID', 'Validations', 'Status', 'Execution at', 'Duration'),
 [('5afb1597-e2a1-4635-b2df-7afe21d00de6',
 'foo',
 'PASSED',
 '2020-11-13T11:47:04.740442Z',
 '0:00:02.388'),
 ('32a5e217-d7a9-49a5-9838-19e5f9b82a77',
 'foo2',
 'PASSED',
 '2020-11-13T11:47:07.931184Z',
 '0:00:02.455'),
 ('62d4d54c-7cce-4f38-9091-292cf49268d7',
 'foo',
 'PASSED',
 '2020-11-13T11:47:47.188876Z',
 '0:00:02.285'),
 ('04e6165c-7c33-4881-bac7-73ff3f909c24',
 'foo3',
 'PASSED',
 '2020-11-13T11:47:50.279662Z',
 '0:00:02.237')])
>>> actions = ValidationActions(constants.ANSIBLE_VALIDATION_DIR)
>>> print(actions.show_history(validation_ids=['foo']))
(('UUID', 'Validations', 'Status', 'Execution at', 'Duration'),
 [('5afb1597-e2a1-4635-b2df-7afe21d00de6',
 'foo',
 'PASSED',
 '2020-11-13T11:47:04.740442Z',
 '0:00:02.388'),
 ('04e6165c-7c33-4881-bac7-73ff3f909c24',
 'foo',
 'PASSED',
 '2020-11-13T11:47:50.279662Z',
 '0:00:02.237')])
show_validations(validation, validation_config=None)[source]

Display detailed information about a Validation

Parameters:
  • validation (string) – The name of the validation

  • validation_config (dict) – A dictionary of configuration for Validation loaded from an validation.cfg file.

Returns:

The detailed information for a validation

Return type:

dict

Raises:

ValidationShowException

Example:

>>> path = "/foo/bar"
>>> validation = 'foo'
>>> action = ValidationActions(validation_path=path)
>>> results = action.show_validations(validation=validation)
>>> print(results)
{
 'Description': 'Description of the foo validation',
 'Categories': ['category1', 'category2'],
 'Groups': ['group1', 'group2'],
 'ID': 'foo',
 'Last execution date': None,
 'Name': 'Name of the validation foo',
 'Number of execution': 'Total: 0, Passed: 0, Failed: 0',
 'Parameters': {'foo1': bar1}
}
show_validations_parameters(validations=None, groups=None, categories=None, products=None, output_format='json', download_file=None, validation_config=None)[source]

Return Validations Parameters for one or several validations by their names, their groups, by their categories or by their products.

Parameters:
  • validations (list) – List of validation name(s)

  • groups (list) – List of validation group(s)

  • categories (list) – List of validation category(ies)

  • products (list) – List of validation product(s)

  • output_format (string) – Output format (Supported format are JSON or YAML)

  • download_file (string) – Path of a file in which the parameters will be stored

  • validation_config (dict) – A dictionary of configuration for Validation loaded from an validation.cfg file.

Returns:

A JSON or a YAML dump (By default, JSON). if download_file is used, a file containing only the parameters will be created in the file system.

Raises:

ValidationShowException

Example:

>>> validations = ['check-cpu', 'check-ram']
>>> groups = None
>>> categories = None
>>> products = None
>>> output_format = 'json'
>>> show_validations_parameters(validations, groups,
                                categories, products, output_format)
{
    "check-cpu": {
        "parameters": {
            "minimal_cpu_count": 8
        }
    },
    "check-ram": {
        "parameters": {
            "minimal_ram_gb": 24
        }
    }
}