From cbbf25d6aa5eef325e0a0cbb93fa2a143f0c55fc Mon Sep 17 00:00:00 2001 From: Joshua Kraitberg Date: Fri, 15 Nov 2024 15:45:17 -0500 Subject: [PATCH] Use error for logging when tasks don't work VIM was logging all tasks as debug. This made it impossible to see errors without enabling debug logging when a node fails to become enabled-available. TEST PLAN PASS: Standard + storage * No errors * Error used instead of debug when tasks fail Partial-Bug: 2088312 Change-Id: I32b58022c67305b138e0546409d579e2ad0b5b1d Signed-off-by: Joshua Kraitberg --- .../nfv_common/state_machine/_state_task.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/nfv/nfv-common/nfv_common/state_machine/_state_task.py b/nfv/nfv-common/nfv_common/state_machine/_state_task.py index 1607bc40..921fce83 100755 --- a/nfv/nfv-common/nfv_common/state_machine/_state_task.py +++ b/nfv/nfv-common/nfv_common/state_machine/_state_task.py @@ -14,6 +14,20 @@ from nfv_common.state_machine._state_task_work_result import STATE_TASK_WORK_RES DLOG = debug.debug_get_logger('nfv_common.state_machine.state_task') +RESULT_LOG_LEVELS = { + STATE_TASK_RESULT.SUCCESS: DLOG.debug, + STATE_TASK_RESULT.FAILED: DLOG.error, + STATE_TASK_RESULT.TIMED_OUT: DLOG.error, + STATE_TASK_RESULT.ABORTED: DLOG.notice, + STATE_TASK_RESULT.DEGRADED: DLOG.warn, +} + + +def result_log(result, message): + logger = RESULT_LOG_LEVELS.get(result, DLOG.debug) + logger(message) + + class StateTask(object): """ State Task @@ -226,7 +240,8 @@ class StateTask(object): State Task Work Complete """ task_work = self._task_work_list[self._current_task_work] - DLOG.debug("Task (%s) work (%s) complete, result=%s, reason=%s." + result_log(task_work_result, + "Task (%s) work (%s) complete, result=%s, reason=%s." % (self._name, task_work.name, task_work_result, task_work_result_reason)) @@ -234,7 +249,8 @@ class StateTask(object): task_work.complete(task_work_result, task_work_result_reason) if task_work_result != updated_task_work_result: - DLOG.debug("Task (%s) work (%s) complete, result updated, " + result_log(updated_task_work_result, + "Task (%s) work (%s) complete, result updated, " "was_result=%s, now_result=%s." % (self._name, task_work.name, task_work_result, updated_task_work_result))