1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
From 16b46604a1eb4e93dc00f628ef0880239d447a4b Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.drung@cloud.ionos.com>
Date: Mon, 28 Sep 2020 13:10:41 +0200
Subject: [PATCH] Fix AttributeError: 'ByteBuffer' object has no attribute
'tobytes'
Following Python code fails:
```python
interface = pyipmi.interfaces.create_interface(interface='ipmitool', interface_type='lanplus')
ipmi = pyipmi.create_connection(interface)
ipmi.session.set_session_type_rmcp(host=fqdn, port=port)
ipmi.session.set_auth_type_user(username=username, password=password)
ipmi.target = pyipmi.Target()
ipmi.session.establish()
ipmi_info = ipmi.get_device_id()
```
```
Traceback (most recent call last):
File "example.py", line 7
ipmi_info = ipmi.get_device_id()
File "pyipmi/bmc.py", line 25, in get_device_id
return DeviceId(self.send_message_with_name('GetDeviceId'))
File "pyipmi/__init__.py", line 206, in send_message_with_name
rsp = self.send_message(req)
File "pyipmi/__init__.py", line 190, in send_message
rsp = self.interface.send_and_receive(req)
File "pyipmi/interfaces/ipmitool.py", line 147, in send_and_receive
py3_array_tobytes(req_data))
File "pyipmi/utils.py", line 57, in py3_array_tobytes
return msg.tobytes()
AttributeError: 'ByteBuffer' object has no attribute 'tobytes'
```
Add a `ByteBuffer.tobytes` method. `ByteBuffer.tobytes` will only be
called if Python's array.array has a `tobytes` method. Therefore the
helper `py3_array_tobytes` is not needed.
Bug: https://github.com/kontron/python-ipmi/issues/80
Forwarded: https://github.com/kontron/python-ipmi/pull/81
Signed-off-by: Benjamin Drung <benjamin.drung@cloud.ionos.com>
---
pyipmi/utils.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/pyipmi/utils.py b/pyipmi/utils.py
index 04ff91b..a6a55d0 100644
--- a/pyipmi/utils.py
+++ b/pyipmi/utils.py
@@ -110,6 +110,9 @@ class ByteBuffer(object):
self.__delslice__(0, length)
return c
+ def tobytes(self):
+ return self.array.tobytes()
+
def tostring(self):
return py3_array_tobytes(self.array)
--
2.25.1
|