From f223ed784998555fc4761be87d6fd025a0e7dcc3 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 28 Apr 2015 13:58:39 -0400 Subject: [PATCH] Clean up strings from FRU Often, a vendor will pad their data fields with spaces. Compensate through use of strip. Similarly, some devices elect to use spaces rather than ascii zeroes on Lenovo devices, recognize those as not present fields as well. Change-Id: I3e1d1ffd5dae4d4febc727e7193fa6652050b267 --- pyghmi/ipmi/fru.py | 4 +++- pyghmi/ipmi/oem/lenovo.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pyghmi/ipmi/fru.py b/pyghmi/ipmi/fru.py index 23c50abd..be7f9fbc 100644 --- a/pyghmi/ipmi/fru.py +++ b/pyghmi/ipmi/fru.py @@ -221,7 +221,7 @@ class FRU(object): retinfo = retinfo.decode('utf-16le') except UnicodeDecodeError: pass - retinfo = retinfo.replace('\x00', '') + retinfo = retinfo.replace('\x00', '').strip() return retinfo, newoffset elif currtype == 1: # BCD 'plus' retdata = '' @@ -229,9 +229,11 @@ class FRU(object): byte = hex(byte).replace('0x', '').replace('a', ' ').replace( 'b', '-').replace('c', '.') retdata += byte + retdata = retdata.strip() return retdata, newoffset elif currtype == 2: # 6-bit ascii retinfo = unpack6bitascii(retinfo) + retinfo = retinfo.strip() return retinfo, newoffset def _parse_chassis(self): diff --git a/pyghmi/ipmi/oem/lenovo.py b/pyghmi/ipmi/oem/lenovo.py index 296d8c9e..290b662e 100644 --- a/pyghmi/ipmi/oem/lenovo.py +++ b/pyghmi/ipmi/oem/lenovo.py @@ -32,13 +32,13 @@ class OEMHandler(generic.OEMHandler): # Thinkserver lays out specific interpretation of the # board extra fields _, _, wwn1, wwn2, mac1, mac2 = fru['board_extra'] - if wwn1 != '0000000000000000': + if wwn1 not in ('0000000000000000', ''): fru['WWN 1'] = wwn1 - if wwn2 != '0000000000000000': + if wwn2 not in ('0000000000000000', ''): fru['WWN 2'] = wwn2 - if mac1 != '00:00:00:00:00:00': + if mac1 not in ('00:00:00:00:00:00', ''): fru['MAC Address 1'] = mac1 - if mac2 != '00:00:00:00:00:00': + if mac2 not in ('00:00:00:00:00:00', ''): fru['MAC Address 2'] = mac2 # The product_extra is just UUID, we have that plenty of other ways # So for now, leave that portion of the data alone