diff --git a/python/nav/portadmin/handlers.py b/python/nav/portadmin/handlers.py index 5a2e8816a1..7c74e559df 100644 --- a/python/nav/portadmin/handlers.py +++ b/python/nav/portadmin/handlers.py @@ -352,7 +352,3 @@ class POEStateNotSupportedError(ManagementError): class XMLParseError(ManagementError): """Raised when failing to parse XML""" - - -class POEIndexNotFoundError(ManagementError): - """Raised when a PoE index could not be found for an interface""" diff --git a/python/nav/portadmin/snmp/cisco.py b/python/nav/portadmin/snmp/cisco.py index bbe1a9d18e..d2f4fa5b0c 100644 --- a/python/nav/portadmin/snmp/cisco.py +++ b/python/nav/portadmin/snmp/cisco.py @@ -28,7 +28,6 @@ PoeState, POEStateNotSupportedError, POENotSupportedError, - POEIndexNotFoundError, ) from nav.models import manage @@ -351,7 +350,7 @@ def _get_poe_indexes_for_interface( try: poeport = manage.POEPort.objects.get(interface=interface) except manage.POEPort.DoesNotExist: - raise POEIndexNotFoundError( + raise POENotSupportedError( "This interface does not have PoE indexes defined" ) unit_number = poeport.poegroup.index diff --git a/python/nav/web/portadmin/views.py b/python/nav/web/portadmin/views.py index 211910965a..e021807750 100644 --- a/python/nav/web/portadmin/views.py +++ b/python/nav/web/portadmin/views.py @@ -56,7 +56,6 @@ NoResponseError, ProtocolError, ManagementError, - POEIndexNotFoundError, XMLParseError, POEStateNotSupportedError, ) @@ -248,7 +247,6 @@ def populate_infodict(request, netbox, interfaces): messages.error(request, str(error)) except ( - POEIndexNotFoundError, XMLParseError, POEStateNotSupportedError, ) as error: diff --git a/tests/unittests/portadmin/portadmin_poe_cisco_test.py b/tests/unittests/portadmin/portadmin_poe_cisco_test.py index 2c48c638d0..717d0252d2 100644 --- a/tests/unittests/portadmin/portadmin_poe_cisco_test.py +++ b/tests/unittests/portadmin/portadmin_poe_cisco_test.py @@ -3,10 +3,7 @@ import pytest from nav.portadmin.snmp.cisco import Cisco -from nav.portadmin.handlers import ( - POEIndexNotFoundError, - POEStateNotSupportedError, -) +from nav.portadmin.handlers import POEStateNotSupportedError from nav.models import manage @@ -23,24 +20,24 @@ class TestGetPoeState: @pytest.mark.usefixtures('poeport_get_mock') def test_should_raise_exception_if_unknown_poe_state(self, handler_cisco): handler_cisco._query_netbox = Mock(return_value=76) - interface = Mock(interface="interface") + interface = Mock(ifname="interface") with pytest.raises(POEStateNotSupportedError): handler_cisco.get_poe_states([interface]) @pytest.mark.usefixtures('poeport_get_mock_error') - def test_should_raise_exception_if_interface_is_missing_poeport( + def test_dict_should_give_none_if_interface_does_not_have_poeport( self, handler_cisco ): - interface = Mock(interface="interface") - with pytest.raises(POEIndexNotFoundError): - handler_cisco.get_poe_states([interface]) + interface = Mock(ifname="interface") + states = handler_cisco.get_poe_states([interface]) + assert states[interface.ifname] is None @pytest.mark.usefixtures('poeport_get_mock') def test_dict_should_give_none_if_interface_does_not_support_poe( self, handler_cisco ): handler_cisco._query_netbox = Mock(return_value=None) - interface = Mock(interface="interface") + interface = Mock(ifname="interface") states = handler_cisco.get_poe_states([interface]) assert states[interface.ifname] is None