def pursue(identity, candidate): """Try to detain this identity if applicable If profile says to not keep closed, we lift the detention for this identity after detaining the new interface. This also means that when detaining manually we keep all interfaces closed as this was the behavior in the old code. """ LOGGER.info("%s is active on interface %s" % ( candidate.mac, candidate.interface )) # Check if this reason is a part of any detention profile. If it is we # need to fetch the vlans from that profile and see if the new ip is on # one of those vlans or have to be skipped. profile = is_detained_by_profile(identity) if profile and not should_pursue(identity, profile): return try: raise_if_detainment_not_allowed(candidate.interface) except DetainmentNotAllowedError, error: LOGGER.error(error) return
def pursue(identity, candidate): """Try to detain this identity if applicable If profile says to not keep closed, we lift the detention for this identity after detaining the new interface. This also means that when detaining manually we keep all interfaces closed as this was the behavior in the old code. """ _logger.info("%s is active on interface %s", candidate.mac, candidate.interface) # Check if this reason is a part of any detention profile. If it is we # need to fetch the vlans from that profile and see if the new ip is on # one of those vlans or have to be skipped. profile = is_detained_by_profile(identity) if profile and not should_pursue(identity, profile): return try: raise_if_detainment_not_allowed(candidate.interface) except DetainmentNotAllowedError as error: _logger.error(error) return identity.autoenablestep = find_autoenable_step(identity) detain(identity, candidate) if profile and profile.keep_closed == 'n': try: open_port(identity, getpass.getuser(), 'Blocked on another interface') except GeneralException as error: _logger.error(error)
def test_should_detain_blockontrunk(mock_getconfig, interface): """Test that BlockonTrunkError is properly thrown""" get_config = mock_getconfig.return_value get_config.get.return_value = 'SW,EDGE' interface.trunk = True with pytest.raises(BlockonTrunkError): raise_if_detainment_not_allowed(interface)
def test_should_detain_wrongcatid(mock_getconfig, interface): """Test that WrongCatidError is properly thrown""" get_config = mock_getconfig.return_value get_config.get.return_value = 'SW,EDGE' category = interface.netbox.category category.id = 'GW' with pytest.raises(WrongCatidError): raise_if_detainment_not_allowed(interface)