From b43ce63be3853c386e7bd8363b6a1f4e01650e06 Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Fri, 15 Dec 2023 15:55:00 +0100 Subject: [PATCH] Handle LLDP parse Unicode error Closes-Bug: #2044793 Change-Id: I939c80bb309b22e05ba7cc93686f12bbe0d71624 (cherry picked from commit db76af9c86bffb61f9b7a52a4080959fee1658fa) --- ironic_inspector/plugins/lldp_basic.py | 11 ++++++++++- .../notes/fix-lldp-decode-83f4ad3869b0c7a7.yaml | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fix-lldp-decode-83f4ad3869b0c7a7.yaml diff --git a/ironic_inspector/plugins/lldp_basic.py b/ironic_inspector/plugins/lldp_basic.py index a770b292a..7cc21b195 100644 --- a/ironic_inspector/plugins/lldp_basic.py +++ b/ironic_inspector/plugins/lldp_basic.py @@ -53,7 +53,16 @@ class LLDPBasicProcessingHook(base.ProcessingHook): {'tlv_type': tlv_type, 'msg': e}, node_info=node_info) continue - if parser.parse_tlv(tlv_type, data): + try: + parsed_tlv = parser.parse_tlv(tlv_type, data) + except UnicodeDecodeError as e: + LOG.warning("LLDP TLV type %(tlv_type)d can't be decoded: " + "%(exc)s", + {'tlv_type': tlv_type, 'exc': e}, + node_info=node_info) + continue + + if parsed_tlv: LOG.debug("Handled TLV type %d", tlv_type, node_info=node_info) else: diff --git a/releasenotes/notes/fix-lldp-decode-83f4ad3869b0c7a7.yaml b/releasenotes/notes/fix-lldp-decode-83f4ad3869b0c7a7.yaml new file mode 100644 index 000000000..6eb7435b8 --- /dev/null +++ b/releasenotes/notes/fix-lldp-decode-83f4ad3869b0c7a7.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + In case the lldp raw data collected by the inspection process + includes non utf-8 information, the parser fails breaking + the inspection process. + This patch works around that excluding the malformed data + and adding an entry in the logs to provide information + on the failed tlv.