validations_libs.validation_logs module

class validations_libs.validation_logs.ValidationLog(uuid=None, validation_id=None, logfile=None, log_path='/home/zuul/src/opendev.org/openstack/validations-libs/.tox/docs/validations', extension='json')[source]

Bases: object

An object for encapsulating a Validation Log file

property get_duration

Return duration of Ansible runtime

Return type:

string

property get_host_group

Return host group

Returns:

A comma-separated list of host(s)

Return type:

string

property get_hosts_status

Return status by host(s)

Returns:

A comma-separated string of host with its status

Return type:

string

Example:

>>> logfile = '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json'
>>> val = ValidationLog(logfile=logfile)
>>> print(val.get_hosts_status)
'localhost,PASSED, webserver1,FAILED, webserver2,PASSED'
get_log_path()[source]

Return full path of a validation log

property get_logfile_content

Return logfile content

Return type:

dict

property get_logfile_datetime

Return log file datetime from a UUID and a validation ID

Returns:

The datetime of the log file

Return type:

list

Example:

>>> logfile = '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json'
>>> val = ValidationLog(logfile=logfile)
>>> print(val.get_logfile_datetime)
['2020-03-30T13:17:22.447857Z']
property get_logfile_infos

Return log file information from the log file basename

Returns:

A list with the UUID, the validation name and the datetime of the log file

Return type:

list

Example:

>>> logfile = '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json'
>>> val = ValidationLog(logfile=logfile)
>>> print(val.get_logfile_infos)
['123', 'foo', '2020-03-30T13:17:22.447857Z']
property get_plays

Return a list of Playbook data

property get_reason

Return validation reason

Returns:

hostname: reason of the failure

Return type:

string

property get_start_time

Return Ansible start time

Return type:

string

property get_status

Return validation status

Returns:

‘FAILED’ if there are any failed or unreachable validations, ‘SKIPPED’ if skipped is True and ok is false which means that the entire validation has been ignored because no host matched, ‘PASSED’ if none of those conditions.

Return type:

string

property get_tasks_data

Return a list of task from validation output

property get_unreachable_hosts

Return unreachable hosts

Returns:

A list of unreachable host(s)

Return type:

string

Example:

  • Multiple unreachable hosts

>>> logfile = '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json'
>>> val = ValidationLog(logfile=logfile)
>>> print(val.get_unreachable_hosts)
'localhost, webserver2'
  • Only one unreachable host

>>> logfile = '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json'
>>> val = ValidationLog(logfile=logfile)
>>> print(val.get_unreachable_hosts)
'localhost'
  • No unreachable host

>>> logfile = '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json'
>>> val = ValidationLog(logfile=logfile)
>>> print(val.get_unreachable_hosts)
''
property get_uuid

Return log uuid

Return type:

string

property get_validation_id

Return validation id

Return type:

string

is_valid_format()[source]

Return True if the log file is a valid validation format

The validation log file has to contain three level of data.

  • plays will contain the Ansible execution logs of the playbooks

  • stat will contain the statistics for each targeted hosts

  • validation_output will contain only the warning or failed tasks

{
  'plays': [],
  'stats': {},
  'validation_output': []
}
Returns:

True if the log file is valid, False if not.

Return type:

boolean

class validations_libs.validation_logs.ValidationLogs(logs_path='/home/zuul/src/opendev.org/openstack/validations-libs/.tox/docs/validations')[source]

Bases: object

An object for encapsulating the Validation Log files

get_all_logfiles(extension='json')[source]

Return logfiles from logs_path

Parameters:

extension (string) – The extension file (Defaults to ‘json’)

Returns:

A list of the absolute path log files

Return type:

list

get_all_logfiles_content()[source]

Return logfiles content

Returns:

A list of the contents of every log files available

Return type:

list

get_logfile_by_uuid(uuid)[source]

Return logfiles by uuid

Parameters:

uuid (string) – The UUID of the validation execution

Returns:

The list of the log files by UUID

Return type:

list

get_logfile_by_uuid_validation_id(uuid, validation_id)[source]

Return logfiles by uuid and validation_id

Parameters:
  • uuid (string) – The UUID of the validation execution

  • validation_id (string) – The ID of the validation

Returns:

A list of the log files by UUID and validation_id

Return type:

list

get_logfile_by_validation(validation_id)[source]

Return logfiles by validation_id

Parameters:

validation_id (string) – The ID of the validation

Returns:

The list of the log files for a validation

Return type:

list

get_logfile_content_by_uuid(uuid)[source]

Return logfiles content by uuid

Parameters:

uuid (string) – The UUID of the validation execution

Returns:

The list of the log files contents by UUID

Return type:

list

get_logfile_content_by_uuid_validation_id(uuid, validation_id)[source]

Return logfiles content filter by uuid and validation_id

Parameters:
  • uuid (string) – The UUID of the validation execution

  • validation_id (string) – The ID of the validation

Returns:

A list of the log files content by UUID and validation_id

Return type:

list

get_logfile_content_by_validation(validation_id)[source]

Return logfiles content by validation_id

Parameters:

validation_id (string) – The ID of the validation

Returns:

The list of the log files contents for a validation

Return type:

list

get_results(uuid, validation_id=None)[source]

Return a list of validation results by uuid Can be filter by validation_id

Parameters:
  • uuid (string` or ``list) – The UUID of the validation execution

  • validation_id (string) – The ID of the validation

Returns:

A list of the log files content by UUID and validation_id

Return type:

list

Example:

>>> v_logs = ValidationLogs()
>>> uuid = '78df1c3f-dfc3-4a1f-929e-f51762e67700'
>>> print(v_logs.get_results(uuid=uuid)
[{'Duration': '0:00:00.514',
  'Host_Group': 'undercloud,Controller',
  'Status': 'FAILED',
  'Status_by_Host': 'undercloud,FAILED, underclou1d,FAILED',
  'UUID': '78df1c3f-dfc3-4a1f-929e-f51762e67700',
  'Unreachable_Hosts': 'undercloud',
  'Validations': 'check-cpu'}]
get_validations_stats(logs)[source]

Return validations stats from log files

Parameters:

logs (list) – A list of log file contents

Returns:

Information about validation statistics. last execution date and number of execution

Return type:

dict