Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small fixes #44

Merged
merged 2 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyipmi/hpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ def _from_data(self, data):

class UpgradeImage(object):
def __init__(self, filename=None):
self.actions = None

if filename:
self._from_file(filename)

Expand All @@ -684,7 +686,7 @@ def _check_md5_sum(self, filedata):
def _from_file(self, filename):

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

Expand Down
2 changes: 2 additions & 0 deletions pyipmi/sdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ def __str__(self):
return s

def convert_sensor_raw_to_value(self, raw):
if raw is None:
return None
fmt = self.analog_data_format
if (fmt == self.DATA_FMT_1S_COMPLEMENT):
if raw & 0x80:
Expand Down
Binary file added tests/hpm_bin/firmware.hpm
Binary file not shown.
87 changes: 47 additions & 40 deletions tests/test_hpm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from nose.tools import eq_
import os

from nose.tools import eq_, ok_

from pyipmi.hpm import (ComponentProperty, ComponentPropertyDescriptionString,
ComponentPropertyGeneral,
Expand All @@ -10,58 +12,55 @@
ComponentPropertyRollbackVersion,
UpgradeActionRecord, UpgradeActionRecordBackup,
UpgradeActionRecordPrepare,
UpgradeActionRecordUploadForCompare,
UpgradeActionRecordUploadForUpgrade,
UpgradeActionRecordUploadForCompare, UpgradeImage,
PROPERTY_GENERAL_PROPERTIES, PROPERTY_CURRENT_VERSION,
PROPERTY_DESCRIPTION_STRING, PROPERTY_ROLLBACK_VERSION,
PROPERTY_DEFERRED_VERSION)


def test_componentpropertygeneral():
prop = ComponentProperty().from_data(PROPERTY_GENERAL_PROPERTIES, b'\xaa')
eq_(type(prop), ComponentPropertyGeneral)

prop = ComponentProperty().from_data(PROPERTY_GENERAL_PROPERTIES, (0xaa,))
eq_(type(prop), ComponentPropertyGeneral)


def test_componentpropertycurrentversion():
prop = ComponentProperty().from_data(PROPERTY_CURRENT_VERSION, b'\x01\x99')
eq_(type(prop), ComponentPropertyCurrentVersion)
class TestComponentProperty(object):
def test_general(self):
prop = ComponentProperty().from_data(PROPERTY_GENERAL_PROPERTIES, b'\xaa')
eq_(type(prop), ComponentPropertyGeneral)

prop = ComponentProperty().from_data(
PROPERTY_CURRENT_VERSION, (0x01, 0x99))
eq_(type(prop), ComponentPropertyCurrentVersion)
prop = ComponentProperty().from_data(PROPERTY_GENERAL_PROPERTIES, (0xaa,))
eq_(type(prop), ComponentPropertyGeneral)

def test_currentversion(self):
prop = ComponentProperty().from_data(PROPERTY_CURRENT_VERSION, b'\x01\x99')
eq_(type(prop), ComponentPropertyCurrentVersion)

def test_componentpropertydescriptionstring():
prop = ComponentProperty().from_data(PROPERTY_DESCRIPTION_STRING,
b'\x30\x31\x32')
eq_(type(prop), ComponentPropertyDescriptionString)
eq_(prop.description, '012')
prop = ComponentProperty().from_data(
PROPERTY_CURRENT_VERSION, (0x01, 0x99))
eq_(type(prop), ComponentPropertyCurrentVersion)

prop = ComponentProperty().from_data(
PROPERTY_DESCRIPTION_STRING, (0x33, 0x34, 0x35))
eq_(type(prop), ComponentPropertyDescriptionString)
eq_(prop.description, '345')
def test_descriptionstring(self):
prop = ComponentProperty().from_data(PROPERTY_DESCRIPTION_STRING,
b'\x30\x31\x32')
eq_(type(prop), ComponentPropertyDescriptionString)
eq_(prop.description, '012')

prop = ComponentProperty().from_data(
PROPERTY_DESCRIPTION_STRING, (0x33, 0x34, 0x35))
eq_(type(prop), ComponentPropertyDescriptionString)
eq_(prop.description, '345')

def test_componentpropertydescriptionstring_with_trailinge_zeros():
prop = ComponentProperty().from_data(PROPERTY_DESCRIPTION_STRING,
b'\x36\x37\x38\x00\x00')
eq_(type(prop), ComponentPropertyDescriptionString)
eq_(prop.description, '678')
def test_descriptionstring_with_trailinge_zeros(self):
prop = ComponentProperty().from_data(PROPERTY_DESCRIPTION_STRING,
b'\x36\x37\x38\x00\x00')
eq_(type(prop), ComponentPropertyDescriptionString)
eq_(prop.description, '678')

def test_rollbackversion(self):
prop = ComponentProperty().from_data(
PROPERTY_ROLLBACK_VERSION, (0x2, 0x88))
eq_(type(prop), ComponentPropertyRollbackVersion)

def test_componentpropertyrollbackversion():
prop = ComponentProperty().from_data(
PROPERTY_ROLLBACK_VERSION, (0x2, 0x88))
eq_(type(prop), ComponentPropertyRollbackVersion)


def test_componentpropertydeferredversion():
prop = ComponentProperty().from_data(
PROPERTY_DEFERRED_VERSION, (0x3, 0x77))
eq_(type(prop), ComponentPropertyDeferredVersion)
def test_deferredversion(self):
prop = ComponentProperty().from_data(
PROPERTY_DEFERRED_VERSION, (0x3, 0x77))
eq_(type(prop), ComponentPropertyDeferredVersion)


def test_upgradeactionrecord_create_from_data():
Expand All @@ -87,3 +86,11 @@ def test_upgradeactionrecord_create_from_data():
record = UpgradeActionRecord.create_from_data(b'\x03\x08\x02')
eq_(record.action, 3)
eq_(type(record), UpgradeActionRecordUploadForCompare)


def test_upgrade_image():
path = os.path.dirname(os.path.abspath(__file__))
hpm_file = os.path.join(path, 'hpm_bin/firmware.hpm')
image = UpgradeImage(hpm_file)
ok_(isinstance(image.actions[0], UpgradeActionRecordPrepare))
ok_(isinstance(image.actions[1], UpgradeActionRecordUploadForUpgrade))
Loading