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

Use PySNMP >6 asyncio API #1497

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Emantor
Copy link
Member

@Emantor Emantor commented Sep 24, 2024

Description
Update pysnmp and it's users to use the new async API, this should fix CI and also ensures we can properly use pysnmp in the future.
Pushed additional fixes for no longer required pylint disables.

Checklist

  • PR has been tested

Fixes #1493
Closes #1456

Comment on lines 16 to 21
except RuntimeError:
# no previous, external or running loop found, create a new one
self.loop = asyncio.new_event_loop()
Copy link
Member

Choose a reason for hiding this comment

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

Client code does the same, but only in start_session() when no loop is provided otherwise (and stashes the loop for later use).

How would other code retrieve the newly created event loop from here?

I think this must rely on an existing event loop, similar to EthernetPortManager:

self.loop = asyncio.get_event_loop()

Copy link
Member Author

@Emantor Emantor Sep 25, 2024

Choose a reason for hiding this comment

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

But get_event_loop is deprecated, so I chose not to use this.
I also think that get_running_loop almost always returns a runtime error here.

Copy link
Member

Choose a reason for hiding this comment

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

No, get_event_loop() is not deprecated per se: only if there is no current event loop. That's why I think we should simply expect a loop here. If there is none, that's an error that needs to be fixed outside of labgrid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Using labgrid as a library means that there is not necessarily an available loop and we need to support this (which is exactly the case where there is no loop).

Copy link
Member Author

Choose a reason for hiding this comment

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

Testing this inside of labgrid client reveals that get_running_loop does not find the running client event loop and instead no loop is found and another is created for SNMP.

Copy link
Member

Choose a reason for hiding this comment

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

Using labgrid as a library means that there is not necessarily an available loop and we need to support this (which is exactly the case where there is no loop).

I disagree. There are certain "entry points" into labgrid where a loop can be passed or labgrid tries to find one or sets a new one up as a fallback. Exporter, coordinator and client are these "entry points". Client and libraries typically use labgrid.remote.client.start_session() to start a session. So that makes sure there is a loop.

For all other cases, code that uses labgrid as a library needs to make sure a loop exists. Maybe that needs to be documented better.

Using get_event_loop() in EthernetPortManager was an active decision. Using that makes sure there is an event loop. Otherwise you get a warning (and a new event loop) or an error, depending on the Python version.

Testing this inside of labgrid client reveals that get_running_loop does not find the running client event loop and instead no loop is found and another is created for SNMP.

That's because get_running_loop() does not work in sync contexts and there is no other way to achieve that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this is fine for the SNMP switch handling, but isn't the correct requirement for the simple power backend handling we had beforehand. So how do we proceed with this? Requiring an event loop for sync library usage is not really feasible.

Copy link
Member

Choose a reason for hiding this comment

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

How does the simple power backend handling work without a session?

Copy link
Member Author

Choose a reason for hiding this comment

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

How does the simple power backend handling work without a session?

What do you mean? You can totally describe all of the NetworkPowerPorts inside of the YAML configuration and not use a RemotePlace to retrieve the resources.

Copy link
Member

@Bastian-Krause Bastian-Krause Sep 26, 2024

Choose a reason for hiding this comment

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

Yes, I see.

See commit messages of da95c44, 0e1e4fb and 606af35 for context.

What about calling labgrid.remote.client.ensure_event_loop() whenever we need an event loop? That would restore the original behavior of using labgrid as a library without a coordinator session.

We could add a function that allows library users to pass their own event loop into labgrid (stashing it) for use cases without labgrid.remote.client.start_session() (which already allows passing an external loop).

Wrap the now asyncio based co-routines in loop.run_until_complete().

Signed-off-by: Rouven Czerwinski <[email protected]>
With the new asyncio based handling we can unlock the pysnmp dependency.
The lexstudio fork has also taken over maintenance of pysnmp on pypi, so
switch back to pysnmp.

Signed-off-by: Rouven Czerwinski <[email protected]>
Follow the sync API deprecation and use an internal asyncio loop if no
external loop can be retrieved.

Signed-off-by: Rouven Czerwinski <[email protected]>
This is no longer required since pylint has moved it to an optional
extension, see [1].

[1]: https://pylint.readthedocs.io/en/latest/whatsnew/2/2.14/summary.html#removed-checkers.

Signed-off-by: Rouven Czerwinski <[email protected]>
This is no longer required since pylint has moved it to an optional
extension, see [1].

[1]: https://pylint.readthedocs.io/en/latest/whatsnew/2/2.14/summary.html#removed-checkers.

Signed-off-by: Rouven Czerwinski <[email protected]>
Bastian-Krause added a commit to Bastian-Krause/labgrid that referenced this pull request Sep 28, 2024
pysnmp depends on pyasn1. `pyasn1.compat.octets` was removed in pyasn1
0.6.1 [1] leading to ModuleNotFoundErrors in labgrid's "eaton" and
"poe_mib" power backends:

  _______________ TestNetworkPowerDriver.test_import_backend_eaton _______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bfdd0>

      def test_import_backend_eaton(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.eaton

  tests/test_powerdriver.py:295:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/eaton.py:2: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError
  ______________ TestNetworkPowerDriver.test_import_backend_poe_mib ______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bd910>

      def test_import_backend_poe_mib(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.poe_mib

  tests/test_powerdriver.py:307:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/poe_mib.py:4: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError

The issue is documented upstream [2]. [3] limited the pysnmp version to
<6. pysnmp 6.1.4, 6.2.6, and 7.1.0 are not affected.

For stable, limit compatible pyasn1 versions to <0.6.1. On master, [5]
switches labgrid to pysnmp's asyncio API, thereby dropping the upper
bound introduced by [3].

[1] https://github.com/pyasn1/pyasn1/releases/tag/v0.6.1
[2] pyasn1/pyasn1#76
[3] labgrid-project#1332
[4] lextudio/pysnmp#113 (comment)
[5] labgrid-project#1497

Signed-off-by: Bastian Krause <[email protected]>
Bastian-Krause added a commit to Bastian-Krause/labgrid that referenced this pull request Sep 30, 2024
pysnmp depends on pyasn1. `pyasn1.compat.octets` was removed in pyasn1
0.6.1 [1] leading to ModuleNotFoundErrors in labgrid's "eaton" and
"poe_mib" power backends:

  _______________ TestNetworkPowerDriver.test_import_backend_eaton _______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bfdd0>

      def test_import_backend_eaton(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.eaton

  tests/test_powerdriver.py:295:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/eaton.py:2: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError
  ______________ TestNetworkPowerDriver.test_import_backend_poe_mib ______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bd910>

      def test_import_backend_poe_mib(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.poe_mib

  tests/test_powerdriver.py:307:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/poe_mib.py:4: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError

The issue is documented upstream [2]. [3] limited the pysnmp version to
<6. pysnmp 6.1.4, 6.2.6, and 7.1.0 are not affected.

For stable, limit compatible pyasn1 versions to <0.6.1. On master, [5]
switches labgrid to pysnmp's asyncio API, thereby dropping the upper
bound introduced by [3].

[1] https://github.com/pyasn1/pyasn1/releases/tag/v0.6.1
[2] pyasn1/pyasn1#76
[3] labgrid-project#1332
[4] lextudio/pysnmp#113 (comment)
[5] labgrid-project#1497

Signed-off-by: Bastian Krause <[email protected]>
Bastian-Krause added a commit to Bastian-Krause/labgrid that referenced this pull request Sep 30, 2024
pysnmp depends on pyasn1. `pyasn1.compat.octets` was removed in pyasn1
0.6.1 [1] leading to ModuleNotFoundErrors in labgrid's "eaton" and
"poe_mib" power backends:

  _______________ TestNetworkPowerDriver.test_import_backend_eaton _______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bfdd0>

      def test_import_backend_eaton(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.eaton

  tests/test_powerdriver.py:295:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/eaton.py:2: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError
  ______________ TestNetworkPowerDriver.test_import_backend_poe_mib ______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bd910>

      def test_import_backend_poe_mib(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.poe_mib

  tests/test_powerdriver.py:307:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/poe_mib.py:4: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError

The issue is documented upstream [2]. [3] limited the pysnmp version to
<6. pysnmp 6.1.4, 6.2.6, and 7.1.0 are not affected.

For stable, limit compatible pyasn1 versions to <0.6.1. On master, [5]
switches labgrid to pysnmp's asyncio API, thereby dropping the upper
bound introduced by [3].

[1] https://github.com/pyasn1/pyasn1/releases/tag/v0.6.1
[2] pyasn1/pyasn1#76
[3] labgrid-project#1332
[4] lextudio/pysnmp#113 (comment)
[5] labgrid-project#1497

Signed-off-by: Bastian Krause <[email protected]>
Bastian-Krause added a commit to Bastian-Krause/labgrid that referenced this pull request Sep 30, 2024
pysnmp depends on pyasn1. `pyasn1.compat.octets` was removed in pyasn1
0.6.1 [1] leading to ModuleNotFoundErrors in labgrid's "eaton" and
"poe_mib" power backends:

  _______________ TestNetworkPowerDriver.test_import_backend_eaton _______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bfdd0>

      def test_import_backend_eaton(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.eaton

  tests/test_powerdriver.py:295:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/eaton.py:2: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError
  ______________ TestNetworkPowerDriver.test_import_backend_poe_mib ______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bd910>

      def test_import_backend_poe_mib(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.poe_mib

  tests/test_powerdriver.py:307:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/poe_mib.py:4: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError

The issue is documented upstream [2]. [3] limited the pysnmp version to
<6. pysnmp 6.1.4, 6.2.6, and 7.1.0 are not affected.

For stable, limit compatible pyasn1 versions to <0.6.1. On master, [5]
switches labgrid to pysnmp's asyncio API, thereby dropping the upper
bound introduced by [3].

[1] https://github.com/pyasn1/pyasn1/releases/tag/v0.6.1
[2] pyasn1/pyasn1#76
[3] labgrid-project#1332
[4] lextudio/pysnmp#113 (comment)
[5] labgrid-project#1497

Signed-off-by: Bastian Krause <[email protected]>
Bastian-Krause added a commit to Bastian-Krause/labgrid that referenced this pull request Oct 10, 2024
pysnmp depends on pyasn1. `pyasn1.compat.octets` was removed in pyasn1
0.6.1 [1] leading to ModuleNotFoundErrors in labgrid's "eaton" and
"poe_mib" power backends:

  _______________ TestNetworkPowerDriver.test_import_backend_eaton _______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bfdd0>

      def test_import_backend_eaton(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.eaton

  tests/test_powerdriver.py:295:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/eaton.py:2: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError
  ______________ TestNetworkPowerDriver.test_import_backend_poe_mib ______________

  self = <test_powerdriver.TestNetworkPowerDriver object at 0x7f84794bd910>

      def test_import_backend_poe_mib(self):
          pytest.importorskip("pysnmp")
  >       import labgrid.driver.power.poe_mib

  tests/test_powerdriver.py:307:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  labgrid/driver/power/poe_mib.py:4: in <module>
      from ...util.snmp import SimpleSNMP
  labgrid/util/snmp.py:1: in <module>
      from pysnmp import hlapi
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/hlapi/__init__.py:7: in <module>
      from pysnmp.proto.rfc1902 import *
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1902.py:8: in <module>
      from pysnmp.proto import rfc1155, error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/rfc1155.py:10: in <module>
      from pysnmp.proto import error
  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/proto/error.py:9: in <module>
      from pysnmp import debug
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

      #
      # This file is part of pysnmp software.
      #
      # Copyright (c) 2005-2019, Ilya Etingof <[email protected]>
      # License: https://www.pysnmp.com/pysnmp/license.html
      #
      import logging
  >   from pyasn1.compat.octets import octs2ints
  E   ModuleNotFoundError: No module named 'pyasn1.compat.octets'

  /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/pysnmp/debug.py:8: ModuleNotFoundError

The issue is documented upstream [2]. [3] limited the pysnmp version to
<6. pysnmp 6.1.4, 6.2.6, and 7.1.0 are not affected.

Limit compatible pyasn1 versions to <0.6.1 until [5]
switches labgrid to pysnmp's asyncio API, thereby dropping the upper
bound introduced by [3].

While at it, switch from "pysnmp-lextudio" to "pysnmp". The original
author of pysnmp passed away and the lextudio folks took over maintenanc.
While the request to take over the pysnmp PyPi project was pending, the
maintained fork was called pysnmp-lextudio (see labgrid-project#1186, aa2549c). Now that
the migration is complete, let's move back to the original package name.

See: [6]

[1] https://github.com/pyasn1/pyasn1/releases/tag/v0.6.1
[2] pyasn1/pyasn1#76
[3] labgrid-project#1332
[4] lextudio/pysnmp#113 (comment)
[5] labgrid-project#1497
[6] etingof/pysnmp#429

Signed-off-by: Bastian Krause <[email protected]>
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.

pyasn1 0.6.1 breaks eaton and poe_mib power backends
2 participants