From d727e6abb7ac47e99a596b515ac5f1fa93fc14d2 Mon Sep 17 00:00:00 2001 From: Bill Dodd Date: Thu, 12 Mar 2020 19:39:00 -0500 Subject: [PATCH 1/4] fix OSError when piping output of rf_logs.py --- scripts/rf_logs.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/rf_logs.py b/scripts/rf_logs.py index f914f76..c5a9e7a 100644 --- a/scripts/rf_logs.py +++ b/scripts/rf_logs.py @@ -12,6 +12,8 @@ """ import argparse +import sys + import redfish import redfish_utilities @@ -58,5 +60,8 @@ # Print log was requested log_entries = redfish_utilities.get_log_entries( redfish_obj, container_type, container_id, args.log ) redfish_utilities.print_log_entries( log_entries, args.details ) +except BrokenPipeError: + pass finally: redfish_obj.logout() + sys.stderr.close() From fab9c65d5d38b266c0f8217b5362b30e1fc27337 Mon Sep 17 00:00:00 2001 From: Bill Dodd Date: Thu, 12 Mar 2020 19:41:25 -0500 Subject: [PATCH 2/4] add file change missed on first commit --- redfish_utilities/logs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redfish_utilities/logs.py b/redfish_utilities/logs.py index 732fea1..0129ff5 100644 --- a/redfish_utilities/logs.py +++ b/redfish_utilities/logs.py @@ -12,7 +12,7 @@ with the log service for a given Redfish service """ -import os +import shutil from .messages import verify_response from enum import Enum @@ -75,7 +75,7 @@ def print_log_entries( log_entries, details = False ): """ # Set up templates - console_size = os.get_terminal_size() + console_size = shutil.get_terminal_size(fallback=(80, 24)) message_size = console_size.columns - 38 entry_line_format = " {:5s} | {:25s} | {}" detail_line_format = " {:33s} | {}: {}" From 57b334dec228d6565932f71596710c5e9ec22a71 Mon Sep 17 00:00:00 2001 From: Bill Dodd Date: Fri, 13 Mar 2020 10:46:21 -0500 Subject: [PATCH 3/4] move catch of BrokenPipeError to print_log_entries() --- redfish_utilities/logs.py | 28 ++++++++++++++++------------ scripts/rf_logs.py | 2 -- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/redfish_utilities/logs.py b/redfish_utilities/logs.py index 0129ff5..c3b0aa0 100644 --- a/redfish_utilities/logs.py +++ b/redfish_utilities/logs.py @@ -81,18 +81,22 @@ def print_log_entries( log_entries, details = False ): detail_line_format = " {:33s} | {}: {}" detail_list = [ "Severity", "EntryType", "OemRecordFormat", "EntryCode", "OemLogEntryCode", "SensorType", "OemSensorType", "GeneratorId", "SensorNumber", "EventType", "EventId", "EventGroupId", "MessageId", "MessageArgs" ] - print( entry_line_format.format( "Id", "Timestamp", "Message" ) ) - - # Go through each entry and print the info - for entry in log_entries: - timestamp_property = "Created" - if "EventTimestamp" in entry: - timestamp_property = "EventTimestamp" - print( entry_line_format.format( entry["Id"], entry[timestamp_property], entry["Message"].replace( "\n", "; " )[:message_size] ) ) - if details: - for detail in detail_list: - if detail in entry: - print( detail_line_format.format( "", detail, entry[detail] ) ) + + try: + print( entry_line_format.format( "Id", "Timestamp", "Message" ) ) + + # Go through each entry and print the info + for entry in log_entries: + timestamp_property = "Created" + if "EventTimestamp" in entry: + timestamp_property = "EventTimestamp" + print( entry_line_format.format( entry["Id"], entry[timestamp_property], entry["Message"].replace( "\n", "; " )[:message_size] ) ) + if details: + for detail in detail_list: + if detail in entry: + print( detail_line_format.format( "", detail, entry[detail] ) ) + except BrokenPipeError: + pass def clear_log_entries( context, container_type = log_container.MANAGER, container_id = None, log_service_id = None ): """ diff --git a/scripts/rf_logs.py b/scripts/rf_logs.py index c5a9e7a..58e37fb 100644 --- a/scripts/rf_logs.py +++ b/scripts/rf_logs.py @@ -60,8 +60,6 @@ # Print log was requested log_entries = redfish_utilities.get_log_entries( redfish_obj, container_type, container_id, args.log ) redfish_utilities.print_log_entries( log_entries, args.details ) -except BrokenPipeError: - pass finally: redfish_obj.logout() sys.stderr.close() From a33830d73becd2b780582208df2afaaf503d4e58 Mon Sep 17 00:00:00 2001 From: Bill Dodd Date: Fri, 13 Mar 2020 11:49:20 -0500 Subject: [PATCH 4/4] remove try/except from print_log_entries() --- redfish_utilities/logs.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/redfish_utilities/logs.py b/redfish_utilities/logs.py index c3b0aa0..0129ff5 100644 --- a/redfish_utilities/logs.py +++ b/redfish_utilities/logs.py @@ -81,22 +81,18 @@ def print_log_entries( log_entries, details = False ): detail_line_format = " {:33s} | {}: {}" detail_list = [ "Severity", "EntryType", "OemRecordFormat", "EntryCode", "OemLogEntryCode", "SensorType", "OemSensorType", "GeneratorId", "SensorNumber", "EventType", "EventId", "EventGroupId", "MessageId", "MessageArgs" ] - - try: - print( entry_line_format.format( "Id", "Timestamp", "Message" ) ) - - # Go through each entry and print the info - for entry in log_entries: - timestamp_property = "Created" - if "EventTimestamp" in entry: - timestamp_property = "EventTimestamp" - print( entry_line_format.format( entry["Id"], entry[timestamp_property], entry["Message"].replace( "\n", "; " )[:message_size] ) ) - if details: - for detail in detail_list: - if detail in entry: - print( detail_line_format.format( "", detail, entry[detail] ) ) - except BrokenPipeError: - pass + print( entry_line_format.format( "Id", "Timestamp", "Message" ) ) + + # Go through each entry and print the info + for entry in log_entries: + timestamp_property = "Created" + if "EventTimestamp" in entry: + timestamp_property = "EventTimestamp" + print( entry_line_format.format( entry["Id"], entry[timestamp_property], entry["Message"].replace( "\n", "; " )[:message_size] ) ) + if details: + for detail in detail_list: + if detail in entry: + print( detail_line_format.format( "", detail, entry[detail] ) ) def clear_log_entries( context, container_type = log_container.MANAGER, container_id = None, log_service_id = None ): """