Skip to content

Update pycrypto to pycryptodome in setup.py #17

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

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
3 participants