kontron / python-ipmi

A pure python IPMI library
GNU Lesser General Public License v2.1
185 stars 74 forks source link

fru: 6bitascii decode is not supported #154

Closed bkmetzler closed 1 year ago

bkmetzler commented 1 year ago

When trying to run the following, I get the associated exception.

`

$ ipmitool.py -I ipmitool -H REDACTED -U root -P "REDACTED" fru print
Traceback (most recent call last):
  File "venv/bin/ipmitool.py", line 8, in <module>
    sys.exit(main())
  File "venv/lib/python3.7/site-packages/pyipmi/ipmitool.py", line 615, in main
    cmd(ipmi, args)
  File "venv/lib/python3.7/site-packages/pyipmi/ipmitool.py", line 222, in cmd_fru_print
    inv = ipmi.get_fru_inventory(fru_id)
  File "venv/lib/python3.7/site-packages/pyipmi/fru.py", line 153, in get_fru_inventory
    fru.board_info_area = self.get_fru_board_area(fru_id=fru_id)
  File "venv/lib/python3.7/site-packages/pyipmi/fru.py", line 112, in get_fru_board_area
    return InventoryBoardInfoArea(data)
  File "venv/lib/python3.7/site-packages/pyipmi/fru.py", line 199, in __init__
    self._from_data(data)
  File "venv/lib/python3.7/site-packages/pyipmi/fru.py", line 271, in _from_data
    self.manufacturer = FruTypeLengthString(data, offset)
  File "venv/lib/python3.7/site-packages/pyipmi/fields.py", line 99, in __init__
    sdr=False)
  File "venv/lib/python3.7/site-packages/pyipmi/fields.py", line 70, in __init__
    self._from_data(data, offset, force_lang_eng)
  File "venv/lib/python3.7/site-packages/pyipmi/fields.py", line 89, in _from_data
    self.string = chr_data.decode('6bitascii')
AttributeError: 'str' object has no attribute 'decode'

`

After debugging, I found the following values on init input of FruTypeLengthString: `

data = b'\x01\t\x00\x00\x00\x00\x83d\xc9\xb2\xdePowerEdge R515                \xceCN717033AI0058\xc90RMRF7A05A\x03\xc1\x00\x00*'
offset = 6

`

Python Version: $ python --version Python 3.7.17 Ipmitool version: $ ipmitool -V ipmitool version 1.8.18 python-ipmi version: python-ipmi==0.5.4

Target Server: Dell PowerEdge R515

Information:

Board Info Area:
  Mfg. Date / Time:   1996-01-01 00:00:00
  Manufacturer:       dɲ
  Product Name:       PowerEdge R515                
  Serial Number:      CN717033AI0058
  Part Number:        0RMRF7A05
  FRU File ID:        

Product Info Area:
  Manufacturer:       dɲ
  Name:               PowerEdgeR515-H4F8CZ1
  Part/Model Number:  
  Version:            02
  Serial Number:      H4F8CZ1
  Asset:                        
  FRU File ID:        `
bkmetzler commented 1 year ago

The underlying issue seems that the following line is converts a single character to a string instead of a bytes-string. https://github.com/kontron/python-ipmi/blob/master/pyipmi/fields.py#L85

hthiery commented 1 year ago

Could you create a unit test that shows the error and then fix it ;-)

bkmetzler commented 1 year ago

I'll put it on my todo list, but if someone else can get to it before I do, please feel free.

hthiery commented 1 year ago

Hi, there is a PR that you could test please. https://github.com/kontron/python-ipmi/pull/156

bkmetzler commented 1 year ago

Looks good.