From ffea39dfcc2564fcfab877600f2d3b095936b5d5 Mon Sep 17 00:00:00 2001 From: Xiangce Liu Date: Fri, 8 Apr 2022 11:48:20 +0800 Subject: [PATCH 1/4] fix: strip the '\x00' from the ibm_fw_vernum_encoded before parsing Signed-off-by: Xiangce Liu --- insights/parsers/ibm_proc.py | 4 ++-- insights/parsers/tests/test_ibm_proc.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/insights/parsers/ibm_proc.py b/insights/parsers/ibm_proc.py index f59e1b92d6..6e418093db 100644 --- a/insights/parsers/ibm_proc.py +++ b/insights/parsers/ibm_proc.py @@ -55,7 +55,7 @@ class IBMFirmwareLevel(Parser): Typical content looks like:: - FW950.30 (VL950_092) + FW950.30 (VL950_092)\x00 Attributes: firmware_level (str): The firmware level required by FLRT. @@ -77,4 +77,4 @@ def parse_content(self, content): if not fwl: raise SkipException("Nothing to parse.") - self.firmware_level = fwl.strip('()') + self.firmware_level = fwl.strip('()\x00') diff --git a/insights/parsers/tests/test_ibm_proc.py b/insights/parsers/tests/test_ibm_proc.py index 1be5429721..478f900743 100644 --- a/insights/parsers/tests/test_ibm_proc.py +++ b/insights/parsers/tests/test_ibm_proc.py @@ -11,7 +11,7 @@ """.strip() PROC_IBM_FWL = """ -FW950.30 (VL950_092) +FW950.30 (VL950_092)\x00 """.strip() From 3719affec8057942746cdafee7a24c383c06029a Mon Sep 17 00:00:00 2001 From: Xiangce Liu Date: Tue, 19 Apr 2022 11:38:25 +0800 Subject: [PATCH 2/4] use instead of Signed-off-by: Xiangce Liu --- insights/parsers/ibm_proc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/insights/parsers/ibm_proc.py b/insights/parsers/ibm_proc.py index 6e418093db..98e61a7d43 100644 --- a/insights/parsers/ibm_proc.py +++ b/insights/parsers/ibm_proc.py @@ -58,6 +58,7 @@ class IBMFirmwareLevel(Parser): FW950.30 (VL950_092)\x00 Attributes: + raw (str): The RAW value of the `ibm,fw-vernum_encoded` file. firmware_level (str): The firmware level required by FLRT. Examples: @@ -72,9 +73,9 @@ def parse_content(self, content): if not content: raise SkipException("Empty output.") - _, fwl = content[0].split(None, 1) + self.raw = content[0] - if not fwl: + if "(" not in self.raw or ")" not in self.raw: raise SkipException("Nothing to parse.") - self.firmware_level = fwl.strip('()\x00') + self.firmware_level = self.raw[self.raw.index('(')+1:self.raw.index(')')] From 38edd497f2baba782d01ab0b4a58aa52409dc03f Mon Sep 17 00:00:00 2001 From: Xiangce Liu Date: Tue, 19 Apr 2022 11:40:52 +0800 Subject: [PATCH 3/4] fix typo Signed-off-by: Xiangce Liu --- insights/parsers/ibm_proc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/insights/parsers/ibm_proc.py b/insights/parsers/ibm_proc.py index 98e61a7d43..56191e9856 100644 --- a/insights/parsers/ibm_proc.py +++ b/insights/parsers/ibm_proc.py @@ -58,7 +58,7 @@ class IBMFirmwareLevel(Parser): FW950.30 (VL950_092)\x00 Attributes: - raw (str): The RAW value of the `ibm,fw-vernum_encoded` file. + raw (str): The RAW content of the `ibm,fw-vernum_encoded` file. firmware_level (str): The firmware level required by FLRT. Examples: @@ -78,4 +78,4 @@ def parse_content(self, content): if "(" not in self.raw or ")" not in self.raw: raise SkipException("Nothing to parse.") - self.firmware_level = self.raw[self.raw.index('(')+1:self.raw.index(')')] + self.firmware_level = self.raw[self.raw.index('(') + 1:self.raw.index(')')] From 4c19a279f1bbb0b90c47bc3431cbb9bddf6bb5e0 Mon Sep 17 00:00:00 2001 From: Xiangce Liu Date: Tue, 19 Apr 2022 13:04:40 +0800 Subject: [PATCH 4/4] add test Signed-off-by: Xiangce Liu --- insights/parsers/tests/test_ibm_proc.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/insights/parsers/tests/test_ibm_proc.py b/insights/parsers/tests/test_ibm_proc.py index 478f900743..2b095c3125 100644 --- a/insights/parsers/tests/test_ibm_proc.py +++ b/insights/parsers/tests/test_ibm_proc.py @@ -14,6 +14,10 @@ FW950.30 (VL950_092)\x00 """.strip() +PROC_IBM_FWL_NG = """ +FW950.30 VL950_092\x00 +""".strip() + def test_ibm_proc(): results = IBMPpcLparCfg(context_wrap(PROC_PPC_LPARCFG)) @@ -31,6 +35,9 @@ def test_ibm_proc_empty(): with pytest.raises(SkipException): IBMFirmwareLevel(context_wrap('')) + with pytest.raises(SkipException): + IBMFirmwareLevel(context_wrap(PROC_IBM_FWL_NG)) + def test_ibm_proc_doc_examples(): env = {