Skip to content

Commit

Permalink
Merge c9e4ce6 into 2b60f94
Browse files Browse the repository at this point in the history
  • Loading branch information
hthiery committed Oct 7, 2018
2 parents 2b60f94 + c9e4ce6 commit 53a4d64
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
16 changes: 16 additions & 0 deletions pyipmi/fru.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import array
import codecs
import datetime
import os

from .errors import DecodingError, CompletionCodeError
from .msgs import constants
Expand Down Expand Up @@ -87,6 +88,21 @@ def get_fru_inventory(self, fru_id=0):
return FruInventory(self.read_fru_data(fru_id=fru_id))


def get_fru_inventory_from_file(filename):
try:
file = open(filename, "rb")
except IOError:
print('Error open file "%s"' % filename)

################################
# get file size
file_size = os.stat(filename).st_size
file_data = file.read(file_size)
data = array.array('B', file_data)
file.close()
return FruInventory(data)


class FruDataField(object):
TYPE_BINARY = 0
TYPE_BCD_PLUS = 1
Expand Down
2 changes: 1 addition & 1 deletion pyipmi/interfaces/ipmb.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def rx_filter(header, data):

for left, right, msg in checks:
if left != right:
log().debug('{:s}: {:s} {:s}'.format(msg, left, right))
log().debug('{:s}: {:d} {:d}'.format(msg, left, right))
match = False

return match
2 changes: 1 addition & 1 deletion pyipmi/interfaces/rmcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def close_session(self):
check_completion_code(rsp.completion_code)
self._session.activated = False

self._q.join()
# self._q.join()

def _inc_sequence_number(self):
self.next_sequence_number = (self.next_sequence_number + 1) % 64
Expand Down
Binary file added tests/fru_bin/kontron_am4010.bin
Binary file not shown.
Binary file added tests/fru_bin/kontron_am4904.bin
Binary file not shown.
37 changes: 35 additions & 2 deletions tests/test_fru.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os

from nose.tools import eq_

from pyipmi.fru import FruData, InventoryCommonHeader
from pyipmi.fru import (FruData, InventoryCommonHeader,
get_fru_inventory_from_file)


def test_frudata_object():
Expand All @@ -20,5 +22,36 @@ def test_frudata_object():
eq_(fru_field.data[3], 3)


def test_inventorycommonheader_object():
def test_commonheader_object():
InventoryCommonHeader((0, 1, 2, 3, 4, 5, 6, 235))


def test_fru_inventory_from_file():
path = os.path.dirname(os.path.abspath(__file__))
fru_file = os.path.join(path, 'fru_bin/kontron_am4010.bin')
fru = get_fru_inventory_from_file(fru_file)
eq_(fru.chassis_info_area, None)


def test_board_area():
path = os.path.dirname(os.path.abspath(__file__))
fru_file = os.path.join(path, 'fru_bin/kontron_am4010.bin')
fru = get_fru_inventory_from_file(fru_file)

board_area = fru.board_info_area
eq_(board_area.manufacturer.value, 'Kontron')
eq_(board_area.product_name.value, 'AM4010')
eq_(board_area.serial_number.value, '0023721003')
eq_(board_area.part_number.value, '35943')


def test_product_area():
path = os.path.dirname(os.path.abspath(__file__))
fru_file = os.path.join(path, 'fru_bin/kontron_am4010.bin')
fru = get_fru_inventory_from_file(fru_file)

product_area = fru.product_info_area
eq_(product_area.manufacturer.value, 'Kontron')
eq_(product_area.name.value, 'AM4010')
eq_(product_area.serial_number.value, '0000000000000000000000000')
eq_(product_area.part_number.value, '0012')
7 changes: 7 additions & 0 deletions tests/test_sel.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ class TestSelInfo(object):

class TestSelEnty(object):

def test_from_data(self):
data = [0xff, 0x03, 0x02, 0xf7, 0x61, 0xef, 0x52, 0x7e,
0x00, 0x04, 0xf2, 0x09, 0x6f, 0x00, 0xff, 0xff]
entry = SelEntry(data)
eq_(entry.type, 2)
eq_(entry.sensor_type, 0xf2)

def test_type_to_string(self):
eq_(SelEntry.type_to_string(0), None)
eq_(SelEntry.type_to_string(0x02),
Expand Down

0 comments on commit 53a4d64

Please sign in to comment.