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

Await async handle_trap function in bgp trap tests #323

Merged
Merged
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
16 changes: 9 additions & 7 deletions tests/trapobservers/bgp_traps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,39 @@ async def test_when_backward_transition_trap_is_received_it_should_change_bgp_pe
assert len(device.bgp_peers) == 1
assert device.bgp_peers[peer].oper_state == BGPOperState.ACTIVE

def test_when_trap_is_missing_required_varbinds_it_should_do_nothing(self, backward_transition_trap):
"""jnxBgpM2PeerLocalAddrType is required to be present, according to legacy Zino"""
@pytest.mark.asyncio
async def test_when_trap_is_missing_required_varbinds_it_should_do_nothing(self, backward_transition_trap):
device = backward_transition_trap.agent.device
peer = next(iter(device.bgp_peers.keys()))
addr_type = backward_transition_trap.get_all("jnxBgpM2PeerLocalAddrType")[0]
backward_transition_trap.variables.remove(addr_type)

observer = BgpTrapObserver(state=Mock())
observer.handle_trap(trap=backward_transition_trap)
await observer.handle_trap(trap=backward_transition_trap)

assert len(device.bgp_peers) == 1
assert device.bgp_peers[peer].oper_state == BGPOperState.ESTABLISHED

def test_when_trap_has_invalid_remote_addr_it_should_do_nothing(self, backward_transition_trap):
@pytest.mark.asyncio
async def test_when_trap_has_invalid_remote_addr_it_should_do_nothing(self, backward_transition_trap):
device = backward_transition_trap.agent.device
peer = next(iter(device.bgp_peers.keys()))
backward_transition_trap.get_all("jnxBgpM2PeerRemoteAddr")[0].raw_value = b"INVALID"

observer = BgpTrapObserver(state=Mock())
observer.handle_trap(trap=backward_transition_trap)
await observer.handle_trap(trap=backward_transition_trap)

assert len(device.bgp_peers) == 1
assert device.bgp_peers[peer].oper_state == BGPOperState.ESTABLISHED

def test_when_trap_has_invalid_oper_state_it_should_do_nothing(self, backward_transition_trap):
@pytest.mark.asyncio
async def test_when_trap_has_invalid_oper_state_it_should_do_nothing(self, backward_transition_trap):
device = backward_transition_trap.agent.device
peer = next(iter(device.bgp_peers.keys()))
backward_transition_trap.get_all("jnxBgpM2PeerState")[0].value = "INVALIDFOOBAR"

observer = BgpTrapObserver(state=Mock())
observer.handle_trap(trap=backward_transition_trap)
await observer.handle_trap(trap=backward_transition_trap)

assert len(device.bgp_peers) == 1
assert device.bgp_peers[peer].oper_state == BGPOperState.ESTABLISHED
Expand Down
Loading