Skip to content

Commit cca22db

Browse files
committed
some improvements
Signed-off-by: Heiko Thiery <[email protected]>
1 parent aaf0b86 commit cca22db

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

pyipmi/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from . import msgs
3636

3737
from .errors import IpmiTimeoutError, CompletionCodeError, RetryError
38+
from .logger import log
3839
from .msgs.registry import create_request_by_name
3940
from .session import Session
4041
from .utils import check_rsp_completion_code, is_string
@@ -213,6 +214,8 @@ def send_message(self, req, retry=3):
213214
req.requester = self.requester
214215
rsp = None
215216

217+
log().debug(f'>> Msg Req: {req}')
218+
216219
while retry > 0:
217220
retry -= 1
218221
try:
@@ -224,6 +227,8 @@ def send_message(self, req, retry=3):
224227
else:
225228
raise RetryError()
226229

230+
log().debug(f'<< Msg Rsp: {rsp}')
231+
227232
return rsp
228233

229234
def send_message_with_name(self, name, *args, **kwargs):

pyipmi/interfaces/rmcp.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
import random
2323
import threading
2424
from array import array
25-
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
25+
from cryptography.hazmat.primitives.ciphers import (algorithms, Cipher, modes)
2626
from queue import Queue
2727

2828
from .. import Target
2929
from ..session import Session
3030
from ..msgs import (create_message, create_request_by_name, create_response_by_name,
3131
encode_message, decode_message, constants)
3232
from ..messaging import ChannelAuthenticationCapabilities
33-
from ..errors import DecodingError, NotSupportedError, RetryError
33+
from ..errors import (DecodingError, NotSupportedError, RetryError)
3434
from ..logger import log
3535
from ..interfaces.ipmb import (IpmbHeaderReq, encode_ipmb_msg,
3636
encode_bridged_message, decode_bridged_message,
3737
rx_filter)
38-
from ..utils import (check_rsp_completion_code, py3_array_tobytes)
38+
from ..utils import check_rsp_completion_code
3939

4040

4141
CLASS_NORMAL_MSG = 0x00
@@ -300,7 +300,7 @@ def pack(self, sdu):
300300
else:
301301
raise NotSupportedError('authentication type %s' % auth_type)
302302

303-
pdu += py3_array_tobytes(array('B', [data_len]))
303+
pdu += array('B', [data_len]).tobytes()
304304

305305
if sdu is not None:
306306
pdu += sdu
@@ -410,11 +410,11 @@ def pack(self, sdu, payload_type):
410410
)
411411

412412
if sdu is None:
413-
pdu += py3_array_tobytes(array('B', list(data_len.to_bytes(2, 'little'))))
413+
pdu += array('B', list(data_len.to_bytes(2, 'little'))).tobytes()
414414
return pdu
415415

416416
if self.session is None or self.session.is_encrypted is False:
417-
pdu += py3_array_tobytes(array('B', list(data_len.to_bytes(2, 'little'))))
417+
pdu += array('B', list(data_len.to_bytes(2, 'little'))).tobytes()
418418
pdu += sdu
419419
return pdu
420420

@@ -443,7 +443,7 @@ def pack(self, sdu, payload_type):
443443
ct = encryptor.update(sdu) + encryptor.finalize()
444444

445445
data_len = len(initialization_vector + ct)
446-
pdu += py3_array_tobytes(array('B', list(data_len.to_bytes(2, 'little'))))
446+
pdu += array('B', list(data_len.to_bytes(2, 'little'))).tobytes()
447447
pdu += initialization_vector + ct
448448

449449
# Now add the Session trailer
@@ -610,12 +610,12 @@ def _receive_asf_msg(self, cls):
610610

611611
def ping(self):
612612
ping = AsfPing()
613-
self._send_asf_msg(ping)
614-
self._receive_asf_msg(AsfPong)
613+
with self.transaction_lock:
614+
self._send_asf_msg(ping)
615+
self._receive_asf_msg(AsfPong)
615616

616617
def _get_channel_auth_cap(self, session):
617618
CHANNEL_NUMBER_FOR_THIS = 0xe
618-
# get channel auth cap
619619
req = create_request_by_name('GetChannelAuthenticationCapabilities')
620620
req.target = self.host_target
621621
req.channel.number = CHANNEL_NUMBER_FOR_THIS
@@ -985,6 +985,10 @@ def establish_session(self, session):
985985
self._session = session
986986
log().debug("Session Opened")
987987

988+
if self.keep_alive_interval:
989+
self._stop_keep_alive = call_repeatedly(
990+
self.keep_alive_interval, self._get_device_id)
991+
988992
def _send_and_receive(self, target, lun, netfn, cmdid, payload):
989993
self._inc_sequence_number()
990994

pyipmi/messaging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def _from_response(self, rsp):
156156
self.ipmi_1_5 = True
157157

158158
for function in self._functions.keys():
159+
print(rsp.support)
159160
if hasattr(rsp.support, function):
160161
if getattr(rsp.support, function):
161162
self.auth_types.append(function)

pyipmi/msgs/fru.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class GetFruInventoryAreaInfoReq(Message):
3333
UnsignedInt('fru_id', 1, 0),
3434
)
3535

36+
def __str__(self):
37+
s = super().__str__()
38+
s = s + f'[fru_id={self.fru_id}]'
39+
return s
40+
3641

3742
@register_message_class
3843
class GetFruInventoryAreaInfoRsp(Message):
@@ -57,6 +62,11 @@ class ReadFruDataReq(Message):
5762
UnsignedInt('count', 1),
5863
)
5964

65+
def __str__(self):
66+
s = super().__str__()
67+
s = s + f'[fru_id={self.fru_id}, offset={self.offset}, count={self.count}]'
68+
return s
69+
6070

6171
@register_message_class
6272
class ReadFruDataRsp(Message):

pyipmi/msgs/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def _set_field(self, name, value):
353353
# TODO walk along the properties..
354354

355355
def __str__(self):
356-
return '{} [netfn={}, cmd={}, grp={}]'.format(type(self).__name__, self.netfn, self.cmdid, self.group_extension)
356+
return f'{type(self).__name__} [netfn={self.netfn}, cmd={self.cmdid}, grp={self.group_extension}]'
357357

358358
def _create_fields(self):
359359
for field in self.__fields__:

pyipmi/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __str__(self):
169169
string += ' Host: %s:%s\n' % (self._rmcp_host, self._rmcp_port)
170170
string += ' Auth.: %s\n' % self.auth_type
171171
string += ' User: %s\n' % self._auth_username
172-
string += ' Password: %s\n' % self._auth_password
172+
string += ' Password: %s\n' % '*******'
173173
string += '\n'
174174
return string
175175

0 commit comments

Comments
 (0)