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

Add SNMPv3 support to Portadmin #2731

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions python/nav/portadmin/snmp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
# details. You should have received a copy of the GNU General Public License
# along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
import time
from functools import wraps
from operator import attrgetter
import logging
from typing import Dict, Sequence, List, Any

from nav import Snmp
from nav.Snmp.profile import get_snmp_session_for_profile
from nav.Snmp import safestring, OID
from nav.Snmp.errors import (
UnsupportedSnmpVersionError,
Expand Down Expand Up @@ -174,15 +173,9 @@ def _get_read_only_handle(self):

if not profile:
raise NoReadOnlyManagementProfileError
if not hasattr(profile, "snmp_community") or not hasattr(
profile, "snmp_version"
):
raise InvalidManagementProfileError

self.read_only_handle = Snmp.Snmp(
self.read_only_handle = get_snmp_session_for_profile(profile)(
host=self.netbox.ip,
community=profile.snmp_community,
version=profile.snmp_version,
retries=self.retries,
timeout=self.timeout,
)
Expand All @@ -209,10 +202,8 @@ def _get_read_write_handle(self):
"""
if self.read_write_handle is None:
profile = self.netbox.get_preferred_snmp_management_profile(writeable=True)
self.read_write_handle = Snmp.Snmp(
self.read_write_handle = get_snmp_session_for_profile(profile)(
host=self.netbox.ip,
community=profile.snmp_community,
version=profile.snmp_version,
retries=self.retries,
timeout=self.timeout,
)
Expand Down
8 changes: 5 additions & 3 deletions tests/unittests/portadmin/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import pytest

from nav.enterprise.ids import VENDOR_ID_HEWLETT_PACKARD, VENDOR_ID_CISCOSYSTEMS
from nav.models.manage import ManagementProfile
from nav.portadmin.management import ManagementFactory


@pytest.fixture
def profile():
profile = Mock()
profile.snmp_version = 2
profile.snmp_community = "public"
profile = ManagementProfile(
protocol=ManagementProfile.PROTOCOL_SNMP,
configuration={"version": 2, "community": "public"},
)
return profile


Expand Down
Loading