Skip to content

Commit

Permalink
fix: strip the '\x00' from the ibm_fw_vernum_encoded before parsing (#…
Browse files Browse the repository at this point in the history
…3378)

* fix: strip the '\x00' from the ibm_fw_vernum_encoded before parsing

Signed-off-by: Xiangce Liu <[email protected]>

* use  instead of

Signed-off-by: Xiangce Liu <[email protected]>

* fix typo

Signed-off-by: Xiangce Liu <[email protected]>

* add test

Signed-off-by: Xiangce Liu <[email protected]>
  • Loading branch information
xiangce authored Apr 19, 2022
1 parent 56ce4dd commit e68bcd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 5 additions & 4 deletions insights/parsers/ibm_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class IBMFirmwareLevel(Parser):
Typical content looks like::
FW950.30 (VL950_092)
FW950.30 (VL950_092)\x00
Attributes:
raw (str): The RAW content of the `ibm,fw-vernum_encoded` file.
firmware_level (str): The firmware level required by FLRT.
Examples:
Expand All @@ -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('()')
self.firmware_level = self.raw[self.raw.index('(') + 1:self.raw.index(')')]
9 changes: 8 additions & 1 deletion insights/parsers/tests/test_ibm_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
""".strip()

PROC_IBM_FWL = """
FW950.30 (VL950_092)
FW950.30 (VL950_092)\x00
""".strip()

PROC_IBM_FWL_NG = """
FW950.30 VL950_092\x00
""".strip()


Expand All @@ -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 = {
Expand Down

0 comments on commit e68bcd9

Please sign in to comment.