Skip to content

Refactor(eos_designs): Improve pytest coverage for network_services/route_maps.py #5317

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

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from

Conversation

MaheshGSLAB
Copy link
Contributor

@MaheshGSLAB MaheshGSLAB commented Apr 21, 2025

Change Summary

Improve the pytest coverage for network_services/route_maps.py

Related Issue(s)

Fixes #

Component(s) name

arista.avd.eos_designs

Proposed changes

Improve the pytest coverage for network_services/route_maps.py. Coverage is 100% now

How to test

Run tox

Checklist

User Checklist

  • N/A

Repository Checklist

  • My code has been rebased from devel before I start
  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation and documentation have been updated accordingly.
  • I have updated molecule CI testing accordingly. (check the box if not applicable)

@MaheshGSLAB MaheshGSLAB self-assigned this Apr 21, 2025
Copy link

Review docs on Read the Docs

To test this pull request:

# Create virtual environment for this testing below the current directory
python -m venv test-avd-pr-5317
# Activate the virtual environment
source test-avd-pr-5317/bin/activate
# Install all requirements including PyAVD
pip install "pyavd[ansible] @ git+https://github.com/MaheshGSLAB/ansible-avd.git@route-maps-coverage#subdirectory=python-avd" --force
# Point Ansible collections path to the Python virtual environment
export ANSIBLE_COLLECTIONS_PATH=$VIRTUAL_ENV/ansible_collections
# Install Ansible collection
ansible-galaxy collection install git+https://github.com/MaheshGSLAB/ansible-avd.git#/ansible_collections/arista/avd/,route-maps-coverage --force
# Optional: Install AVD examples
cd test-avd-pr-5317
ansible-playbook arista.avd.install_examples

@github-actions github-actions bot added the state: CI Updated CI scenario have been updated in the PR label Apr 21, 2025
@@ -81,9 +81,6 @@ def _route_maps_vrf_default(self: AvdStructuredConfigNetworkServicesProtocol) ->
self._redistribute_static_to_bgp_route_map()

def _route_maps_vrf_default_check(self: AvdStructuredConfigNetworkServicesProtocol) -> bool:
if not self._vrf_default_evpn:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In network_services/router_bgp.py the method _route_maps_vrf_default_check is call and with that we are already checking it self._vrf_default_evpn so this condition is useless and never met.

@@ -158,8 +155,7 @@ def _evpn_export_vrf_default_route_map(self: AvdStructuredConfigNetworkServicesP
type="permit",
match=EosCliConfigGen.RouteMapsItem.SequenceNumbersItem.Match(["ip address prefix-list PL-STATIC-VRF-DEFAULT"]),
)
if not sequence_numbers:
Copy link
Contributor Author

@MaheshGSLAB MaheshGSLAB Apr 25, 2025

Choose a reason for hiding this comment

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

There will be always sequence number because to be reach this method one of the if condition always required

Copy link
Contributor

Choose a reason for hiding this comment

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

What if I have vrf default without any subnets or static routes? or if I only have ipv6?

Copy link
Contributor Author

@MaheshGSLAB MaheshGSLAB Apr 29, 2025

Choose a reason for hiding this comment

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

This condition, defined in the _evpn_export_vrf_default_route_map method, is guaranteed to be true because the preceding checks in the _route_maps_vrf_default method ensure the host is either a WAN router, has a default VRF with a subnet, or has a default VRF with a static route. Otherwise, the code would have returned earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also i believe we can optimize this module later on because we are iterating the filtered_tenants more then 2 times

Copy link
Contributor

@gmuloc gmuloc Apr 30, 2025

Choose a reason for hiding this comment

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

I agree with Mahesh regarding the fact that right now the function is only called when one of the three conditions (cf line 62) is true and so there will always be one sequence number.

That being said the code was built like this before a split I think and in case we are tented to reuse the method in another context, maybe we should mention it in the docstring?

@@ -188,9 +184,6 @@ def _bgp_underlay_peers_route_map(self: AvdStructuredConfigNetworkServicesProtoc
match=EosCliConfigGen.RouteMapsItem.SequenceNumbersItem.Match(["ip address prefix-list PL-STATIC-VRF-DEFAULT"]),
)

if not sequence_numbers:
Copy link
Contributor Author

@MaheshGSLAB MaheshGSLAB Apr 25, 2025

Choose a reason for hiding this comment

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

There will be always sequence number because to reach this method one of the if condition always required

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with this statement based on where the function is being called from today.

@MaheshGSLAB MaheshGSLAB changed the title Test(eos_designs): Add pytest coverage for network_services/route_maps.py(WIP) Test(eos_designs): Add pytest coverage for network_services/route_maps.py Apr 25, 2025
@MaheshGSLAB MaheshGSLAB changed the title Test(eos_designs): Add pytest coverage for network_services/route_maps.py Refactor(eos_designs): Improve pytest coverage for network_services/route_maps.py Apr 25, 2025
@Shivani-gslab Shivani-gslab marked this pull request as ready for review April 29, 2025 06:59
@Shivani-gslab Shivani-gslab requested review from a team as code owners April 29, 2025 06:59
@@ -158,8 +155,7 @@ def _evpn_export_vrf_default_route_map(self: AvdStructuredConfigNetworkServicesP
type="permit",
match=EosCliConfigGen.RouteMapsItem.SequenceNumbersItem.Match(["ip address prefix-list PL-STATIC-VRF-DEFAULT"]),
)
if not sequence_numbers:
Copy link
Contributor

Choose a reason for hiding this comment

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

What if I have vrf default without any subnets or static routes? or if I only have ipv6?

@@ -81,9 +81,6 @@ def _route_maps_vrf_default(self: AvdStructuredConfigNetworkServicesProtocol) ->
self._redistribute_static_to_bgp_route_map()

def _route_maps_vrf_default_check(self: AvdStructuredConfigNetworkServicesProtocol) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def _route_maps_vrf_default_check(self: AvdStructuredConfigNetworkServicesProtocol) -> bool:
def _route_maps_vrf_default_check(self: AvdStructuredConfigNetworkServicesProtocol) -> bool:
"""This should only be called when self._vrf_default_evpn is true."""

Copy link
Contributor

Choose a reason for hiding this comment

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

similar for the others where we rely on other logic

Copy link

sonarqubecloud bot commented May 5, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: CI Updated CI scenario have been updated in the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants