From eb439a35db4c588ea9da643b104de71b8e816974 Mon Sep 17 00:00:00 2001 From: Jiri Podivin Date: Wed, 12 May 2021 14:29:35 +0200 Subject: [PATCH] Expansion of logging for the show action. New logging calls on the debug level. Signed-off-by: Jiri Podivin Change-Id: I3b2f0bfaa9d92e9cc664dea8ba5f7966c6931837 --- validations_libs/utils.py | 7 +++++++ validations_libs/validation_logs.py | 30 +++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/validations_libs/utils.py b/validations_libs/utils.py index dd23c159..22847bd3 100644 --- a/validations_libs/utils.py +++ b/validations_libs/utils.py @@ -247,6 +247,13 @@ def get_validations_data(validation, path=constants.ANSIBLE_VALIDATION_DIR): data = {} val_path = "{}/{}.yaml".format(path, validation) + + LOG.debug( + "Obtaining information about validation {} from {}".format( + validation, + val_path) + ) + if os.path.exists(val_path): val = Validation(val_path) data.update(val.get_formated_data) diff --git a/validations_libs/validation_logs.py b/validations_libs/validation_logs.py index 1853c868..135d75b2 100644 --- a/validations_libs/validation_logs.py +++ b/validations_libs/validation_logs.py @@ -328,6 +328,11 @@ class ValidationLogs(object): """ log_files = glob.glob("{}/*_{}_*".format(self.logs_path, validation_id)) + LOG.debug( + "Getting log file for validation {} from {}.".format( + validation_id, + log_files) + ) return [self._get_content(log) for log in log_files] def get_logfile_by_uuid(self, uuid): @@ -417,12 +422,25 @@ class ValidationLogs(object): """ if not isinstance(logs, list): logs = [logs] + + LOG.debug( + ("`get_validations_stats` received `logs` argument " + "of type {} but it expects a list. " + "Attempting to resolve.").format( + type(logs)) + ) + # Get validation stats total_number = len(logs) failed_number = 0 passed_number = 0 last_execution = None dates = [] + + LOG.debug( + "Retreiving {} validation stats.".format(total_number) + ) + for log in logs: if log.get('validation_output'): failed_number += 1 @@ -439,11 +457,15 @@ class ValidationLogs(object): if dates: last_execution = time.strftime('%Y-%m-%d %H:%M:%S', max(dates)) + execution_stats = "Total: {}, Passed: {}, Failed: {}".format( + total_number, + passed_number, + failed_number) + + LOG.debug(execution_stats) + return {"Last execution date": last_execution, - "Number of execution": "Total: {}, Passed: {}, " - "Failed: {}".format(total_number, - passed_number, - failed_number)} + "Number of execution": execution_stats} def get_results(self, uuid, validation_id=None): """Return a list of validation results by uuid