From d0718a1566a1aebe32409364cf8da6d31c9d15e9 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 5 Apr 2023 09:58:07 -0400 Subject: [PATCH] Handle FRU with blank mac area Some FRU may omit this feature Change-Id: Ie76aaf4bfc1af42951d4c2dc433f1d41e8303c7d --- pyghmi/ipmi/oem/lenovo/handler.py | 43 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/handler.py b/pyghmi/ipmi/oem/lenovo/handler.py index 803879aa..1d10ee1a 100755 --- a/pyghmi/ipmi/oem/lenovo/handler.py +++ b/pyghmi/ipmi/oem/lenovo/handler.py @@ -718,27 +718,28 @@ class OEMHandler(generic.OEMHandler): fru['FRU Number'] = bextra[0] fru['Revision'] = bextra[4] macs = bextra[6] - macprefix = None - idx = 0 - endidx = len(macs) - 5 - macprefix = None - while idx < endidx: - currmac = macs[idx:idx + 6] - if not isinstance(currmac, bytearray): - # invalid vpd format, abort attempts to extract - # mac in this way - break - if currmac == b'\x00\x00\x00\x00\x00\x00': - break - # VPD may veer off, detect and break off - if macprefix is None: - macprefix = currmac[:3] - elif currmac[:3] != macprefix: - break - ms = mac_format.format(*currmac) - ifidx = idx / 6 + 1 - fru['MAC Address {0}'.format(ifidx)] = ms - idx = idx + 6 + if macs: + macprefix = None + idx = 0 + endidx = len(macs) - 5 + macprefix = None + while idx < endidx: + currmac = macs[idx:idx + 6] + if not isinstance(currmac, bytearray): + # invalid vpd format, abort attempts to extract + # mac in this way + break + if currmac == b'\x00\x00\x00\x00\x00\x00': + break + # VPD may veer off, detect and break off + if macprefix is None: + macprefix = currmac[:3] + elif currmac[:3] != macprefix: + break + ms = mac_format.format(*currmac) + ifidx = idx / 6 + 1 + fru['MAC Address {0}'.format(ifidx)] = ms + idx = idx + 6 except (AttributeError, KeyError, IndexError): pass if self.has_xcc and name and name.startswith('PSU '):