From 4462d5d3cf8bd63e39185ecd0afa5776bb95dc85 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Fri, 15 Nov 2024 19:26:10 -0500 Subject: [PATCH 1/3] Added a performance guide. --- docs/source/development.rst | 2 +- docs/source/index.rst | 23 ++++++++--------- docs/source/performance.rst | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 docs/source/performance.rst diff --git a/docs/source/development.rst b/docs/source/development.rst index 9c8c432d..1c9b5ae6 100644 --- a/docs/source/development.rst +++ b/docs/source/development.rst @@ -1,6 +1,6 @@ .. include:: /includes/_links.rst -Further development +Further Development ------------------- Although PySNMP is already a mature software and it is being used at many diff --git a/docs/source/index.rst b/docs/source/index.rst index e1f19efc..17d7d168 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -29,16 +29,20 @@ and behavior of popular Net-SNMP snmpget/snmpset/snmpwalk utilities. They may be useful in a cross-platform situations as well as a testing and prototyping instrument for pysnmp users. -Quick Start ------------ +Quick Start and Samples +----------------------- You already know something about SNMP and have no courage to dive into this implementation? Try out quick start page! +We also have a collection of sample scripts to help you learn more about +every aspects of PySNMP. + .. toctree:: :maxdepth: 1 /quick-start + /examples/index Documentation ------------- @@ -71,26 +75,19 @@ Conceptual and API documentation are in the following section. Documentation about the SNMP protocol can be found on `PySNMP Homepage`_. -Samples -------- - -We have a collection of sample scripts to help you get started with PySNMP. - -.. toctree:: - :maxdepth: 2 - - /examples/index - Troubleshooting --------------- -If you are having trouble with PySNMP, please check the following section. +If you are having trouble with PySNMP, please check the following section +to learn troubleshooting tips, upgrade guides, and performance tuning +advice. .. toctree:: :maxdepth: 1 /troubleshooting /upgrade + /performance Downloads --------- diff --git a/docs/source/performance.rst b/docs/source/performance.rst new file mode 100644 index 00000000..1da08794 --- /dev/null +++ b/docs/source/performance.rst @@ -0,0 +1,50 @@ +.. include:: /includes/_links.rst + +Performance Tuning +================== + +PySNMP is a highly optimized software. However, there are some knobs you +can turn to make it work even faster. Here are some tips: + +Disabling MIB Support +--------------------- + +Loading MIB metadata into memory is a costly operation. If you are not +using MIBs in your application, you can disable MIB support by + +TODO: Add a code snippet here. + +Run Python Release Mode +----------------------- + +Python interpreter can run in debug and release modes. Running in release +mode can make your Python code run faster. To run Python in release mode, +you can use the following command: + +.. code-block:: bash + + $ python -O myscript.py + +Choosing the Right High-Level API +--------------------------------- + +PySNMP comes with two high-level APIs: v1 and v3. + +If you are using SNMPv1 and SNMPv2c, and you are not using any security +features in your application, you should use the v1 API. The +``SnmpDispatcher`` based API is the fastest API in PySNMP, as it simply +sends SNMP packets and does not do any heavy processing on the packets. + +If you are using SNMPv3, you have to use the v3 API with USM and VACM to +handle security and access control. The v3 API is significantly slower than +the v1 API because it builds up a local secure engine and has to do more +processing on the packets in order to be compliant with SNMPv3 standards. + +Using the right API, and using the right features in the API can make your +application run reasonably fast. + +Don't trust blindly other Python SNMP libraries claiming to be faster. They +either lack of essential features that make the comparison pointless or +they bind to native libraries that become your nightmare to maintain and +deploy. In the end the performance is limited by the Python interpreter and +the SNMP protocol itself. From 015dfe25c793976abd0b58491927e02e78a64d35 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Tue, 3 Dec 2024 21:26:21 -0500 Subject: [PATCH 2/3] Fixed duplicate value issue #152. --- pysnmp/smi/rfc1902.py | 8 +++-- .../manager/cmdgen/test_v1arch_v1_get.py | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pysnmp/smi/rfc1902.py b/pysnmp/smi/rfc1902.py index 8254f075..d6743eb4 100644 --- a/pysnmp/smi/rfc1902.py +++ b/pysnmp/smi/rfc1902.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING from pyasn1.error import PyAsn1Error -from pyasn1.type.base import AbstractSimpleAsn1Item, SimpleAsn1Type +from pyasn1.type.base import AbstractSimpleAsn1Item, SimpleAsn1Type, NoValue from pysnmp import debug from pysnmp.proto import rfc1902, rfc1905 from pysnmp.proto.api import v2c @@ -1065,7 +1065,11 @@ class instance representing MIB browsing functionality. keep_old_value = isinstance(self.__args[1], SimpleAsn1Type) if keep_old_value: old_value = self.__args[1]._value - self.__args[1] = object_identity.get_mib_node().getSyntax().clone() + self.__args[1] = ( + object_identity.get_mib_node() + .getSyntax() + .clone(NoValue(), tagSet=self.__args[1].getTagSet()) + ) self.__args[1]._value = old_value # force to keep the original value else: self.__args[1] = ( diff --git a/tests/hlapi/v1arch/asyncio/manager/cmdgen/test_v1arch_v1_get.py b/tests/hlapi/v1arch/asyncio/manager/cmdgen/test_v1arch_v1_get.py index 11dcb898..97a74fcd 100644 --- a/tests/hlapi/v1arch/asyncio/manager/cmdgen/test_v1arch_v1_get.py +++ b/tests/hlapi/v1arch/asyncio/manager/cmdgen/test_v1arch_v1_get.py @@ -269,3 +269,37 @@ async def test_v1_get_scaled_unsigned_object(): assert ( varBinds[0][1].prettyPrint() == "0.5" # GitHub issue #139 ) # IMPORTANT: test display hint "d-1". + + +@pytest.mark.asyncio +async def test_v1_get_multiple_objects(): + async with AgentContextManager(enable_custom_objects=True): + snmpDispatcher = SnmpDispatcher() + # # Step 1: Set up MIB builder and add custom MIB directory + # mibBuilder = builder.MibBuilder() + # compiler.addMibCompiler(mibBuilder) + # mibViewController = view.MibViewController(mibBuilder) + + # # Load the custom MIB + # mibBuilder.loadModules("LEXTUDIO-TEST-MIB") + # snmpDispatcher.cache["mibViewController"] = mibViewController + + netiftable = [ + ObjectIdentity("IF-MIB", "ifDescr", 1), + ObjectIdentity("IF-MIB", "ifDescr", 2), + ] + + errorIndication, errorStatus, errorIndex, varBinds = await get_cmd( + snmpDispatcher, + CommunityData("public", mpModel=0), + await UdpTransportTarget.create( + ("demo.pysnmp.com", 161), timeout=1, retries=0 + ), + *[ObjectType(x) for x in netiftable] + ) + assert errorIndication is None + assert errorIndication is None + assert errorStatus == 0 + assert errorIndex == 0 + assert len(varBinds) == 2 + assert varBinds[0][1].prettyPrint() != varBinds[1][1].prettyPrint() From e7b7f80b0fd98154ece2ec0e5a42ea50811db7ad Mon Sep 17 00:00:00 2001 From: Lex Li Date: Tue, 3 Dec 2024 21:29:12 -0500 Subject: [PATCH 3/3] Bumped the version. --- .vscode/launch.json | 16 ++++++++++++++++ CHANGES.rst | 5 +++++ SECURITY.md | 2 +- docs/source/conf.py | 2 +- pyproject.toml | 2 +- pysnmp/__init__.py | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..b9788cad --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": false + } + ] +} diff --git a/CHANGES.rst b/CHANGES.rst index 8e7ffab9..e3e21e8e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,8 @@ +Revision 7.1.14, released on Dec 03, 2024 +----------------------------------------- + +- Fixed shadow cloning issue. + Revision 7.1.13, released on Nov 07, 2024 ----------------------------------------- diff --git a/SECURITY.md b/SECURITY.md index 9ef8e65c..add12793 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,7 +6,7 @@ We provide security updates for each version until its End-of-Life (EOL) date. B | Version | Latest Release | End of Life | Notes | | ------- | -------------- | ----------- | ---------------------------------- | -| 7.1 | 7.1.13 | TBD | EOL to be determined | +| 7.1 | 7.1.14 | TBD | EOL to be determined | | 7.0 | 7.0.4 | 2025-03-11 | Supported for 6 months after 7.1.0 | | 6.2 | 6.2.6 | 2025-08-22 | Supported for 1 year after 7.0.0 | | 6.1 | 6.1.4 | 2025-01-12 | Supported for 6 months after 6.2.0 | diff --git a/docs/source/conf.py b/docs/source/conf.py index f2ce6e93..6171c7f4 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -74,7 +74,7 @@ # built documents. # # The full version, including alpha/beta/rc tags. -release = "7.1.13" +release = "7.1.14" # The short X.Y version. version = ".".join(release.split(".")[:2]) diff --git a/pyproject.toml b/pyproject.toml index 074978e7..78efb224 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pysnmp" -version = "7.1.13" +version = "7.1.14" description = "A Python library for SNMP" authors = ["Ilya Etingof ", "LeXtudio Inc. "] license = "BSD-2-Clause" diff --git a/pysnmp/__init__.py b/pysnmp/__init__.py index 3d48e29f..7dbb8a5f 100644 --- a/pysnmp/__init__.py +++ b/pysnmp/__init__.py @@ -11,7 +11,7 @@ - For backward compatibility, if the version string contains "beta", the string part is removed before converting to a tuple. """ # http://www.python.org/dev/peps/pep-0396/ -__version__ = "7.1.13" +__version__ = "7.1.14" # another variable is required to prevent semantic release from updating version in more than one place main_version = __version__ # backward compatibility