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

fix(anta.tests): First round of cleaning up BGP tests module #888

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

carl-baillargeon
Copy link
Contributor

@carl-baillargeon carl-baillargeon commented Oct 17, 2024

Description

Refactoring BGP tests module to address the following issues:

Focusing on VerifyBGPPeerCount, VerifyBGPPeersHealth, VerifyBGPSpecificPeers

Task list:

  • Update unit tests for VerifyBGPPeersHealth & VerifyBGPSpecificPeers
    • Success
    • VRF not configured
    • No peers found
    • Session not established
    • AFI/SAFI not negotiated
    • TCP session queues not empty if check_tcp_queues is True
  • Add unit tests for check_bgp_neighbor_capability (IMP: Added unit tests in test_tools.)
  • Add unit tests for format_data

Changes

  • Updated InQ & OutQ steps as or evaluates lazily, meaning if the first part (InQ := value) != 0 is True, the second part (OutQ := value) != 0 will not be evaluated, results OutQ is never assigned, leading to a NameError.
  • In VerifyBGPSpecificPeers test, added check for peers have correct AFI/SAFI negotiated.
  • Added _check_bgp_neighbor_capability to bgp module as intended to BGP module only.

Copy link

codspeed-hq bot commented Oct 29, 2024

CodSpeed Performance Report

Merging #888 will not alter performance

Comparing carl-baillargeon:feat/bgp_modules (c9f240d) with main (206de52)

Summary

✅ 8 untouched benchmarks

Copy link
Collaborator

@gmuloc gmuloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems quite breaking for the tests as we are suddenly checking more things.
to get a success like Count is now dpeendent on the state of the peer when it did not used to be.

Ideally we could add a flag for this one to not be concerned with the the state (default being we are not) to be backward compatible

# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Package related to all ANTA tests input models."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_input_models?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package or module starting with test could be confusing with pytest.


Please refer to the Input class attributes below for details.
1. Confirms that the specified VRF is configured.
2. Counts the number of peers that are:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is breaking right? before we were "just" counting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. As discussed, let's add a flag like you mentionned in your requested changes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update this to specify that if check_peer_state: true we also check the Established state + AFI/SAFI

anta/tests/routing/bgp.py Outdated Show resolved Hide resolved
anta/tests/routing/bgp.py Show resolved Hide resolved
tests/units/anta_tests/routing/test_bgp.py Outdated Show resolved Hide resolved
tests/units/anta_tests/routing/test_bgp.py Show resolved Hide resolved
tests/units/anta_tests/routing/test_bgp.py Show resolved Hide resolved
tests/units/test_tools.py Outdated Show resolved Hide resolved
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link
Contributor

github-actions bot commented Nov 5, 2024

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link

sonarcloud bot commented Nov 6, 2024

Comment on lines +67 to +68
check_peer_state: bool = True
"""Flag to check if the peers are established with negotiated AFI/SAFI. Defaults to `True`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default should be False to follow the current behavior where we just check the number of peers.

@@ -209,129 +145,80 @@ class VerifyBGPPeerCount(AntaTest):
```
"""

description = "Verifies the count of BGP peers."
name = "VerifyBGPPeerCount"
description = "Verifies the count of established BGP peers with negotiated AFI/SAFI for given address families."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too :)

Comment on lines +119 to +122
* Success: If the count of established BGP peers with negotiated AFI/SAFI matches the expected count for all specified address families.
* Failure: If any of the following occur:
- The specified VRF is not configured.
- The count of established peers with negotiated AFI/SAFI does not match the expected count for any address family.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update this as well per the check_peer_state flag.

peers_data = vrf_output.get("peers", {}).values()
if not address_family.check_peer_state:
# Count the number of peers without considering the state and negotiated AFI/SAFI check if the count matches the expected count
peer_count = sum(1 for peer_data in peers_data if address_family.eos_key in peer_data)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of sum(). Cleaner this way thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants