Skip to content

Commit

Permalink
Merge pull request #40 from hthiery/merge
Browse files Browse the repository at this point in the history
Merge latest master with merge
  • Loading branch information
hthiery committed Oct 5, 2018
2 parents d52c51c + ff36340 commit 0869507
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 43 deletions.
4 changes: 2 additions & 2 deletions pyipmi/ipmitool.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def cmd_bmc_info(ipmi, args):
print(' %s' % s)

if device_id.aux is not None:
print('Aux Firmware Rev Info: [%s]' % (
' '.join('0x%02x' % d for d in device_id.aux)))
print('Aux Firmware Rev Info: [{:s}]'.format(
' '.join('%02x' % d for d in device_id.aux)))


def cmd_sel_clear(ipmi, args):
Expand Down
81 changes: 42 additions & 39 deletions pyipmi/sdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _from_response(self, rsp):


class SdrCommon(object):
def __init__(self, data, next_id=None):
def __init__(self, data=None, next_id=None):
if data:
self.data = data
self._common_header(data)
Expand Down Expand Up @@ -254,7 +254,7 @@ class SdrFullSensorRecord(SdrCommon):
DATA_FMT_2S_COMPLEMENT = 2
DATA_FMT_NONE = 3

def __init__(self, data, next_id=None):
def __init__(self, data=None, next_id=None):
super(SdrFullSensorRecord, self).__init__(data, next_id)
if data:
self._from_data(data)
Expand Down Expand Up @@ -325,38 +325,13 @@ def l(self):

@staticmethod
def _convert_complement(value, size):
if (value & (1 << (size-1))):
if (value & (1 << (size - 1))):
value = -(1 << size) + value
return value

def _from_data(self, data):
buffer = ByteBuffer(data[5:])
# record key bytes
self._common_record_key(buffer.pop_slice(3))
# record body bytes
self._entity(buffer.pop_slice(2))

# byte 11
initialization = buffer.pop_unsigned_int(1)
self.initialization = []
if initialization & 0x40:
self.initialization.append('scanning')
if initialization & 0x20:
self.initialization.append('events')
if initialization & 0x10:
self.initialization.append('thresholds')
if initialization & 0x08:
self.initialization.append('hysteresis')
if initialization & 0x04:
self.initialization.append('type')
if initialization & 0x02:
self.initialization.append('default_event_generation')
if initialization & 0x01:
self.initialization.append('default_scanning')

# byte 12 - sensor capabilities
capabilities = buffer.pop_unsigned_int(1)
def _decode_capabilities(self, capabilities):
self.capabilities = []

# ignore sensor
if capabilities & 0x80:
self.capabilities.append('ignore_sensor')
Expand All @@ -378,11 +353,11 @@ def _from_data(self, data):
elif capabilities & HYSTERESIS_MASK == HYSTERESIS_IS_FIXED:
self.capabilities.append('hysteresis_fixed')
# sensor threshold support
THRESHOLD_MASK = 0x30
THRESHOLD_MASK = 0x0C
THRESHOLD_IS_NOT_SUPPORTED = 0x00
THRESHOLD_IS_READABLE = 0x10
THRESHOLD_IS_READ_AND_SETTABLE = 0x20
THRESHOLD_IS_FIXED = 0x30
THRESHOLD_IS_READABLE = 0x08
THRESHOLD_IS_READ_AND_SETTABLE = 0x04
THRESHOLD_IS_FIXED = 0x0C
if capabilities & THRESHOLD_MASK == THRESHOLD_IS_NOT_SUPPORTED:
self.capabilities.append('threshold_not_supported')
elif capabilities & THRESHOLD_MASK == THRESHOLD_IS_READABLE:
Expand All @@ -401,6 +376,34 @@ def _from_data(self, data):
if (capabilities & 0x03) is 3:
pass

def _from_data(self, data):
buffer = ByteBuffer(data[5:])
# record key bytes
self._common_record_key(buffer.pop_slice(3))
# record body bytes
self._entity(buffer.pop_slice(2))

# byte 11
initialization = buffer.pop_unsigned_int(1)
self.initialization = []
if initialization & 0x40:
self.initialization.append('scanning')
if initialization & 0x20:
self.initialization.append('events')
if initialization & 0x10:
self.initialization.append('thresholds')
if initialization & 0x08:
self.initialization.append('hysteresis')
if initialization & 0x04:
self.initialization.append('type')
if initialization & 0x02:
self.initialization.append('default_event_generation')
if initialization & 0x01:
self.initialization.append('default_scanning')

# byte 12 - sensor capabilities
self._decode_capabilities(buffer.pop_unsigned_int(1))

self.sensor_type_code = buffer.pop_unsigned_int(1)
self.event_reading_type_code = buffer.pop_unsigned_int(1)
self.assertion_mask = buffer.pop_unsigned_int(2)
Expand Down Expand Up @@ -478,7 +481,7 @@ def _from_data(self, data):
# SDR type 0x02
##################################################
class SdrCompactSensorRecord(SdrCommon):
def __init__(self, data, next_id=None):
def __init__(self, data=None, next_id=None):
super(SdrCompactSensorRecord, self).__init__(data, next_id)
if data:
self._from_data(data)
Expand Down Expand Up @@ -521,7 +524,7 @@ def _from_data(self, data):
# SDR type 0x03
##################################################
class SdrEventOnlySensorRecord(SdrCommon):
def __init__(self, data, next_id=None):
def __init__(self, data=None, next_id=None):
super(SdrEventOnlySensorRecord, self).__init__(data, next_id)
if data:
self._from_data(data)
Expand Down Expand Up @@ -551,7 +554,7 @@ def _from_data(self, data):
# SDR type 0x11
##################################################
class SdrFruDeviceLocator(SdrCommon):
def __init__(self, data, next_id=None):
def __init__(self, data=None, next_id=None):
super(SdrFruDeviceLocator, self).__init__(data, next_id)
if data:
self._from_data(data)
Expand Down Expand Up @@ -581,7 +584,7 @@ def _from_data(self, data):
# SDR type 0x12
##################################################
class SdrManagementControllerDeviceLocator(SdrCommon):
def __init__(self, data, next_id=None):
def __init__(self, data=None, next_id=None):
super(SdrManagementControllerDeviceLocator, self).__init__(
data, next_id)
if data:
Expand Down Expand Up @@ -611,7 +614,7 @@ def _from_data(self, data):
# SDR type 0xC0
##################################################
class SdrOEMSensorRecord(SdrCommon):
def __init__(self, data, next_id=None):
def __init__(self, data=None, next_id=None):
super(SdrOEMSensorRecord, self).__init__(data, next_id)
if data:
self._from_data(data)
Expand Down
44 changes: 42 additions & 2 deletions tests/test_sdr.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

from nose.tools import eq_, raises
from nose.tools import eq_, ok_, raises

from pyipmi.errors import DecodingError
from pyipmi.sdr import (SdrCommon, SdrFullSensorRecord, SdrCompactSensorRecord,
SdrEventOnlySensorRecord, SdrFruDeviceLocator,
SdrManagementControllerDeviceLocator)


def test_convert_complement():
eq_(SdrFullSensorRecord()._convert_complement(0x8, 4), -8)
eq_(SdrFullSensorRecord()._convert_complement(0x80, 8), -128)
eq_(SdrFullSensorRecord()._convert_complement(0x8000, 16), -32768)


def test__decode_capabilities():
record = SdrFullSensorRecord()

record._decode_capabilities(0)
ok_('ignore_sensor' not in record.capabilities)
ok_('auto_rearm' not in record.capabilities)
ok_('hysteresis_not_supported' in record.capabilities)
ok_('threshold_not_supported' in record.capabilities)

record._decode_capabilities(0x80)
ok_('ignore_sensor' in record.capabilities)
ok_('auto_rearm' not in record.capabilities)
ok_('hysteresis_not_supported' in record.capabilities)
ok_('threshold_not_supported' in record.capabilities)

record._decode_capabilities(0x40)
ok_('ignore_sensor' not in record.capabilities)
ok_('auto_rearm' in record.capabilities)
ok_('hysteresis_not_supported' in record.capabilities)
ok_('threshold_not_supported' in record.capabilities)

record._decode_capabilities(0x30)
ok_('ignore_sensor' not in record.capabilities)
ok_('auto_rearm' not in record.capabilities)
ok_('hysteresis_fixed' in record.capabilities)
ok_('threshold_not_supported' in record.capabilities)

record._decode_capabilities(0x0c)
ok_('ignore_sensor' not in record.capabilities)
ok_('auto_rearm' not in record.capabilities)
ok_('hysteresis_not_supported' in record.capabilities)
ok_('threshold_fixed' in record.capabilities)


@raises(DecodingError)
def test_sdrcommon_invalid_data_length():
data = (0x00, 0x01, 0x02, 0x03)
Expand Down

0 comments on commit 0869507

Please sign in to comment.