diff --git a/python/nav/portadmin/snmp/base.py b/python/nav/portadmin/snmp/base.py index dcb550defb..f2eb65b0f0 100644 --- a/python/nav/portadmin/snmp/base.py +++ b/python/nav/portadmin/snmp/base.py @@ -14,13 +14,12 @@ # details. You should have received a copy of the GNU General Public License # along with NAV. If not, see . # -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, @@ -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, ) @@ -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, ) diff --git a/tests/unittests/portadmin/conftest.py b/tests/unittests/portadmin/conftest.py index d6ff307574..66102a03eb 100644 --- a/tests/unittests/portadmin/conftest.py +++ b/tests/unittests/portadmin/conftest.py @@ -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