Skip to content

Conversation

@DaanHoogland
Copy link
Member

Fixes #15

@DaanHoogland
Copy link
Member Author

@SchoolGuy , this is what you want, right? can you test it?

@SchoolGuy
Copy link

@DaanHoogland Yes, that is what I want. Is there no automatic testsuite that can verify that this change is working as desired?

@DaanHoogland
Copy link
Member Author

@DaanHoogland Yes, that is what I want. Is there no automatic testsuite that can verify that this change is working as desired?

No it is mainly a testtool for integration tests in Apache CloudStack . It doesn’t get much TLC on its own :(

@SchoolGuy
Copy link

I'll see what I can do. What is the minimum required Python version I need to test with? I am aware that Apache CloudStack is used in an enterprise context and, as such, probably needs more than the most recent Python version.

@DaanHoogland
Copy link
Member Author

DaanHoogland commented Jun 17, 2025

@SchoolGuy , we have upgraded most scripts to python3 but have no specific version requirement as far as I know. Any not too old version should do. it runs with so many operating systems that we cannot be specific about the versions of runtime elements.

ad. there should be no 2.x python scripts left.

@SchoolGuy
Copy link

@DaanHoogland So I have used an openSUSE Leap 15.6 podman container with Python 3.6.15 and the last available pycryptodome version is 3.21.0.

Furthermore, I noticed that the readme is stating how to replace pycrypto with pycryptodome, this section is either incomplete (as you need to break the deps on purpose) or we should remove it in this PR.

Another thing that I noticed in the README is that using localhost doesn't work; one has to specify 127.0.0.1. This may be related to my podman container, but I wanted to mention it anyway.

Finally, I am unable to test the code because of a cryptic error that I cannot decipher, even by reading the source code. The command I used to verify the server:

ipmitool -R1 -I lanplus -p 9001 -H 127.0.0.1 -U admin -P password chassis power status

Server Output:

0528effbb476:~ # python3 bmc.py
/usr/lib/python3.6/site-packages/pyghmi/ipmi/private/session.py:31: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  from cryptography.hazmat.backends import default_backend
2025-06-17 08:09:21,818 - ipmisim - INFO - IPMI BMC initialized.
2025-06-17 08:09:21,818 - ipmisim - INFO - CloudStack IPMI Sim BMC initialized
2025-06-17 08:09:21,818 - ipmisim - INFO - Started IPMI Server on 0.0.0.0:9001
2025-06-17 08:09:24,165 - ipmisim - INFO - New IPMI traffic from ('127.0.0.1', 51866)
2025-06-17 08:09:24,166 - ipmisim - INFO - New IPMI session initialized for client (('127.0.0.1', 51866))
2025-06-17 08:09:24,166 - ipmisim - DEBUG - Connection established with ('127.0.0.1', 51866)
2025-06-17 08:09:24,166 - ipmisim - DEBUG - IPMI response sent to ('127.0.0.1', 51866)
2025-06-17 08:09:24,166 - ipmisim - DEBUG - Incoming IPMI traffic from ('127.0.0.1', 51866)
2025-06-17 08:09:24,166 - ipmisim - DEBUG - IPMI Session closed 127.0.0.1
2025-06-17 08:09:25,173 - ipmisim - INFO - New IPMI traffic from ('127.0.0.1', 51866)
2025-06-17 08:09:25,174 - ipmisim - INFO - New IPMI session initialized for client (('127.0.0.1', 51866))
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 51866)
Traceback (most recent call last):
  File "/usr/lib64/python3.6/socketserver.py", line 654, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib64/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib64/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/usr/lib/python3.6/site-packages/ipmisim/ipmisim.py", line 443, in handle
    return IpmiServerContext().handle(data, address, socket)
  File "/usr/lib/python3.6/site-packages/ipmisim/ipmisim.py", line 118, in handle
    self.initiate_session(data, address, self.session)
  File "/usr/lib/python3.6/site-packages/ipmisim/ipmisim.py", line 146, in initiate_session
    self.sock, data[16:], self.uuid, bmc=self)
  File "/usr/lib/python3.6/site-packages/pyghmi/ipmi/private/serversession.py", line 82, in __init__
    ipmisession.Session.bmc_handlers[clientaddr] = {bmc.port: self}
AttributeError: 'IpmiServerContext' object has no attribute 'port'
----------------------------------------

bmc.py:

#!/usr/bin/python3

import logging
import signal
import socketserver
import sys
import threading
from types import FrameType
from typing import Optional

# https://github.com/shapeblue/ipmisim/issues/16
from ipmisim.ipmisim import IpmiServer, ThreadedIpmiServer, IpmiServerContext  # type: ignore

logger = logging.getLogger('ipmisim')

def main(address: str = "0.0.0.0", port: int = 9001):
    logging.disable(logging.NOTSET)
    logger.setLevel(logging.DEBUG)

    ch = logging.StreamHandler(sys.stdout)
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    port = 9001
    ctx = IpmiServerContext()

    try:
        ThreadedIpmiServer.allow_reuse_address = True
        server = ThreadedIpmiServer(('0.0.0.0', port), IpmiServer)
        logger.info("Started IPMI Server on 0.0.0.0:" + str(port))
        server.serve_forever()
    except KeyboardInterrupt:
        server.shutdown()
        server.server_close()
        sys.exit(0)


if __name__ == "__main__":
    main()

@DaanHoogland
Copy link
Member Author

@SchoolGuy , I see but can not explain it as the root cause the following: python 3.6 is no longer supported. Can you install and try a newer python version?

I will have to investigate the stacktrace (no field port in object for IpmiServerContext) but at first glance you should add the port to the ctx object.

@SchoolGuy
Copy link

@DaanHoogland But Python 3.6 is supported until 2038 at least in SUSE Linux Enterprise Server. Other Linux enterprise distros have this as their default as well, if I am informed correctly. I will very happily use a more recent Python version, but then I would highly recommend documenting this for the entirety of the CloudStack project (I didn't find the info in the Developer Confluence or the building from source section of the installation documentation).

@SchoolGuy
Copy link

Testing with Python 3.11 (latest available on Leap 15.6), I get the same results.

Furthermore, I now have a bunch of warnings:

0528effbb476:~ # pip3.11 install pyghmi==1.2.16 future==0.18.2 pycryptodome==3.21.0
Collecting pyghmi==1.2.16
  Using cached pyghmi-1.2.16.tar.gz (152 kB)
  Preparing metadata (setup.py) ... done
Collecting future==0.18.2
  Using cached future-0.18.2.tar.gz (829 kB)
  Preparing metadata (setup.py) ... done
Collecting pycryptodome==3.21.0
  Using cached pycryptodome-3.21.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB)
Collecting cryptography>=2.1
  Downloading cryptography-45.0.4-cp311-abi3-manylinux_2_34_x86_64.whl (4.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 39.0 MB/s eta 0:00:00
Collecting cffi>=1.14
  Downloading cffi-1.17.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (467 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 467.2/467.2 kB 102.2 MB/s eta 0:00:00
Collecting pycparser
  Downloading pycparser-2.22-py3-none-any.whl (117 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 117.6/117.6 kB 91.9 MB/s eta 0:00:00
Installing collected packages: pycryptodome, pycparser, future, cffi, cryptography, pyghmi
  DEPRECATION: future is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for future ... done
  DEPRECATION: pyghmi is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for pyghmi ... done
Successfully installed cffi-1.17.1 cryptography-45.0.4 future-0.18.2 pycparser-2.22 pycryptodome-3.21.0 pyghmi-1.2.16
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
0528effbb476:~ # pip3.11 install --no-deps ipmisim
Collecting ipmisim
  Using cached ipmisim-0.10.tar.gz (10 kB)
  Preparing metadata (setup.py) ... done
Installing collected packages: ipmisim
  DEPRECATION: ipmisim is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for ipmisim ... done
Successfully installed ipmisim-0.10
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

@DaanHoogland
Copy link
Member Author

/usr/lib/python3.6/site-packages/pyghmi/ipmi/private/session.py:31: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.

I was looking at this line ^

With the newer version we obviously have other work to do. Not sure when, but I’ll have a go at it.

Copy link
Member

@rohityadavcloud rohityadavcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't test but LGTM,
FWIW this was mentioned in the docs https://github.com/shapeblue/ipmisim?tab=readme-ov-file#ipmisim

@DaanHoogland
Copy link
Member Author

@SchoolGuy , If you want this done, you are kind of on your own (not that we won’t answer any questions, but) we have all but abandoned the project as it has no current use for us.

@aversecat
Copy link

@SchoolGuy I spent too much time looking to see if I can use this project in CI for testing IPMI traffic, and I can fix the AttributeError: 'IpmiServerContext' object has no attribute 'port' error, that's not too difficcult:

@@ -49,6 +51,9 @@ class FakeSession(Session):
         self.bmc = bmc
         self.port = port
         self.bmc_handlers = {}
+        self.timeout = 5
+        self.maxtimeout = 15
+        self.logontries = 3
         try:
             self.userid = userid.encode('utf-8')
             self.password = password.encode('utf-8')

But, that leads to another issue later on, during a conversation with ipmitool:

2025-10-21 09:41:05,357 - ipmisim - INFO - IPMI BMC initialized.
2025-10-21 09:41:05,357 - ipmisim - INFO - CloudStack IPMI Sim BMC initialized
2025-10-21 09:41:05,357 - ipmisim - INFO - Started IPMI Server on 0.0.0.0:1623
2025-10-21 09:41:07,671 - ipmisim - INFO - New IPMI traffic from ('127.0.0.1', 40772)
FakeSession __init__
2025-10-21 09:41:07,672 - ipmisim - INFO - New IPMI session initialized for client (('127.0.0.1', 40772))
sending
packet 20
2025-10-21 09:41:08,678 - ipmisim - INFO - New IPMI traffic from ('127.0.0.1', 40772)
FakeSession __init__
2025-10-21 09:41:08,679 - ipmisim - INFO - New IPMI session initialized for client (('127.0.0.1', 40772))
2025-10-21 09:41:09,686 - ipmisim - INFO - New IPMI traffic from ('127.0.0.1', 40772)
----------------------------------------
Exception occurred during processing of request from ('127.0.0.1', 40772)
Traceback (most recent call last):
  File "/usr/lib64/python3.13/socketserver.py", line 697, in process_request_thread
    self.finish_request(request, client_address)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.13/socketserver.py", line 362, in finish_request
    self.RequestHandlerClass(request, client_address, self)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.13/socketserver.py", line 766, in __init__
    self.handle()
    ~~~~~~~~~~~^^
  File "/home/auke/git/scoutfs-fence-agent/test/./ipmisim/ipmisim/ipmisim.py", line 445, in handle
    return IpmiServerContext().handle(data, address, socket)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/auke/git/scoutfs-fence-agent/test/./ipmisim/ipmisim/ipmisim.py", line 109, in handle
    self.session = FakeSession(address[0], "", "", address[1])
                   ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/auke/.local/lib/python3.13/site-packages/pyghmi/ipmi/private/session.py", line 450, in __new__
    if not ((self.logged or self.logging)
             ^^^^^^^^^^^
AttributeError: 'ServerSession' object has no attribute 'logged'

I'd love to start using this project. If you or anyone is interested in unclogging these bugs with me, please lmk. We can fork if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace pycrypto with pycryptodome

5 participants