6262import sys
6363import argparse
6464import os .path
65+ import subprocess
6566import struct
6667import binascii
6768import zlib
69+ import tempfile
70+ import shutil
6871
6972
7073#############################
@@ -566,7 +569,7 @@ def parse_fru_mlnx_bin(data, FRU_ITEMS, verbose=False):
566569 sanity_str = ""
567570 if sanity_str != "MLNX" :
568571 printv ("MLNX Sanitiy check fail" , verbose )
569- return fru_dict
572+ return None
570573 printv ("Sanitiy check is OK" , verbose )
571574 out_str = ""
572575 base_pos = hdr_size + 4
@@ -613,7 +616,7 @@ def parse_fru_onie_bin(data, FRU_ITEMS, verbose=False):
613616 tlv_header = bin_decode (fru_dict ['tlv_header' ])
614617 except BaseException :
615618 tlv_header = ""
616- if 'TlvInfo' not in tlv_header and fru_dict ['ver' ] not in SUPPORTED_FRU_VER :
619+ if 'TlvInfo' not in tlv_header or fru_dict ['ver' ] not in SUPPORTED_FRU_VER :
617620 return None
618621
619622 fru_dict ['items' ] = []
@@ -645,6 +648,41 @@ def parse_fru_onie_bin(data, FRU_ITEMS, verbose=False):
645648 return fru_dict
646649
647650
651+ def parse_ipmu_fru_bin (data , verbose ):
652+ retcode = 1
653+ ipmi_fru_exec_path_list = ["/usr/sbin/ipmi-fru" , "/usr/bin/ipmi-fru" ]
654+ # Create a binary temporary file, read/write, not deleted automatically
655+ with tempfile .NamedTemporaryFile (mode = 'w+b' ) as tmp :
656+ # Write some binary data
657+ tmp .write (data )
658+ # Move cursor to the beginning for reading
659+ tmp .seek (0 )
660+ ipmi_fru_path = shutil .which ("ipmi-fru" )
661+ if not ipmi_fru_path :
662+ for path in ipmi_fru_exec_path_list :
663+ if os .path .exists (path ):
664+ ipmi_fru_path = path
665+ break
666+ print ("ipmi_fru_path: {}" .format (ipmi_fru_path ))
667+ if ipmi_fru_path :
668+ cmd = [ipmi_fru_path , "--fru-file={}" .format (tmp .name )]
669+ print ("cmd: {}" .format (cmd ))
670+ try :
671+ result = subprocess .run (cmd , capture_output = True , text = True )
672+ output_str = result .stdout .strip () # Command's standard output
673+ retcode = result .returncode # Command's return code
674+ print ("output_str: {}" .format (output_str ))
675+ except Exception as e :
676+ return None
677+
678+ if not retcode :
679+ output_str = output_str .split ("\n " )[2 :]
680+ output_str = "\n " .join (output_str )
681+ return {'items' : [["" , output_str ]]}
682+ else :
683+ return None
684+
685+
648686def parse_fru_bin (data , VPD_TYPE , verbose ):
649687 res = None
650688 if VPD_TYPE in globals ().keys ():
@@ -662,6 +700,9 @@ def parse_fru_bin(data, VPD_TYPE, verbose):
662700 res = parse_fru_onie_bin (data , SYSTEM_VPD , verbose )
663701 if not res :
664702 res = parse_fru_mlnx_bin (data , MLNX_VENDOR_BLK , verbose )
703+ if not res :
704+ res = parse_ipmu_fru_bin (data , verbose )
705+
665706 return res
666707
667708
0 commit comments