-
Notifications
You must be signed in to change notification settings - Fork 235
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
Refactor(eos_designs): Refactor eos_designs structured_config code for ip_igmp_snooping.py #5012
Draft
laxmikantchintakindi
wants to merge
4
commits into
aristanetworks:devel
Choose a base branch
from
laxmikantchintakindi:refactor/designs/ip-igmp-snooping
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+27
−51
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ | |
# that can be found in the LICENSE file. | ||
from __future__ import annotations | ||
|
||
from functools import cached_property | ||
from typing import TYPE_CHECKING, Protocol | ||
|
||
from pyavd._utils import append_if_not_duplicate, default, strip_empties_from_dict | ||
from pyavd._eos_cli_config_gen.schema import EosCliConfigGen | ||
from pyavd._eos_designs.structured_config.structured_config_generator import structured_config_contributor | ||
from pyavd._utils import default, strip_empties_from_dict | ||
|
||
if TYPE_CHECKING: | ||
from pyavd._eos_designs.schema import EosDesigns | ||
|
@@ -21,51 +22,32 @@ class IpIgmpSnoopingMixin(Protocol): | |
Class should only be used as Mixin to a AvdStructuredConfig class. | ||
""" | ||
|
||
@cached_property | ||
def ip_igmp_snooping(self: AvdStructuredConfigNetworkServicesProtocol) -> dict | None: | ||
"""Return structured config for ip_igmp_snooping.""" | ||
@structured_config_contributor | ||
def ip_igmp_snooping(self: AvdStructuredConfigNetworkServicesProtocol) -> None: | ||
"""Set structured config for ip_igmp_snooping.""" | ||
if not self.shared_utils.network_services_l2: | ||
return None | ||
return | ||
|
||
igmp_snooping_enabled = self.shared_utils.igmp_snooping_enabled | ||
ip_igmp_snooping = {"globally_enabled": igmp_snooping_enabled} | ||
if not igmp_snooping_enabled: | ||
return ip_igmp_snooping | ||
self.structured_config.ip_igmp_snooping.globally_enabled = igmp_snooping_enabled | ||
return | ||
Shivani-gslab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
vlans = [] | ||
for tenant in self.shared_utils.filtered_tenants: | ||
for vrf in tenant.vrfs: | ||
for svi in vrf.svis: | ||
if vlan := self._ip_igmp_snooping_vlan(svi, tenant): | ||
append_if_not_duplicate( | ||
list_of_dicts=vlans, | ||
primary_key="id", | ||
new_dict=vlan, | ||
context=f"IGMP snooping for SVIs in VRF '{vrf.name}'", | ||
context_keys=["id"], | ||
) | ||
|
||
self._ip_igmp_snooping_vlan(svi, tenant) | ||
for l2vlan in tenant.l2vlans: | ||
if vlan := self._ip_igmp_snooping_vlan(l2vlan, tenant): | ||
append_if_not_duplicate( | ||
list_of_dicts=vlans, | ||
primary_key="id", | ||
new_dict=vlan, | ||
context="IGMP snooping for L2VLANs", | ||
context_keys=["id"], | ||
) | ||
|
||
if vlans: | ||
ip_igmp_snooping["vlans"] = vlans | ||
self._ip_igmp_snooping_vlan(l2vlan, tenant) | ||
|
||
return ip_igmp_snooping | ||
self.structured_config.ip_igmp_snooping.globally_enabled = igmp_snooping_enabled | ||
|
||
def _ip_igmp_snooping_vlan( | ||
self: AvdStructuredConfigNetworkServicesProtocol, | ||
vlan: EosDesigns._DynamicKeys.DynamicNetworkServicesItem.NetworkServicesItem.VrfsItem.SvisItem | ||
| EosDesigns._DynamicKeys.DynamicNetworkServicesItem.NetworkServicesItem.L2vlansItem, | ||
tenant: EosDesigns._DynamicKeys.DynamicNetworkServicesItem.NetworkServicesItem, | ||
) -> dict: | ||
) -> None: | ||
""" | ||
ip_igmp_snooping logic for one vlan. | ||
|
||
|
@@ -87,24 +69,18 @@ def _ip_igmp_snooping_vlan( | |
if self.shared_utils.network_services_l3 and self.shared_utils.uplink_type in ["p2p", "p2p-vrfs"]: | ||
igmp_snooping_querier_enabled = default(vlan.igmp_snooping_querier.enabled, tenant.igmp_snooping_querier.enabled) | ||
|
||
ip_igmp_snooping_vlan = strip_empties_from_dict( | ||
{ | ||
"enabled": igmp_snooping_enabled, | ||
"querier": { | ||
"enabled": igmp_snooping_querier_enabled, | ||
"address": ( | ||
default(vlan.igmp_snooping_querier.source_address, tenant.igmp_snooping_querier.source_address, self.shared_utils.router_id) | ||
if igmp_snooping_querier_enabled | ||
else None | ||
), | ||
"version": default(vlan.igmp_snooping_querier.version, tenant.igmp_snooping_querier.version) if igmp_snooping_querier_enabled else None, | ||
}, | ||
# IGMP snooping fast-leave feature is enabled only when evpn_l2_multicast is enabled | ||
"fast_leave": default(vlan.igmp_snooping_querier.fast_leave, tenant.evpn_l2_multicast.fast_leave) if evpn_l2_multicast_enabled else None, | ||
} | ||
vlan_item = EosCliConfigGen.IpIgmpSnooping.VlansItem( | ||
enabled=igmp_snooping_enabled, | ||
querier=EosCliConfigGen.IpIgmpSnooping.VlansItem.Querier( | ||
enabled=igmp_snooping_querier_enabled, | ||
address=default(vlan.igmp_snooping_querier.source_address, tenant.igmp_snooping_querier.source_address, self.shared_utils.router_id) | ||
if igmp_snooping_querier_enabled | ||
else None, | ||
version=default(vlan.igmp_snooping_querier.version, tenant.igmp_snooping_querier.version) if igmp_snooping_querier_enabled else None, | ||
), | ||
fast_leave=default(vlan.igmp_snooping_querier.fast_leave, tenant.evpn_l2_multicast.fast_leave) if evpn_l2_multicast_enabled else None, | ||
) | ||
|
||
if ip_igmp_snooping_vlan: | ||
return {"id": vlan.id, **ip_igmp_snooping_vlan} | ||
|
||
return ip_igmp_snooping_vlan | ||
if strip_empties_from_dict(vlan_item._as_dict()): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check if we can avoid to use this method. Will check and update |
||
vlan_item._update(id=vlan.id) | ||
self.structured_config.ip_igmp_snooping.vlans.append(vlan_item) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move out this line from if code so you dont need to write it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and there is no case of igmp_snooping_enabled: false in molecule so can you recheck that it return None or globally_enabled: false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add this coverage part in any other PR. In first part we need to add globally_enabled: false only when igmp_snooping_enabled is false and return. If I move out of if condition code will return even when igmp_snooping_enabled is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check the false case locally to make sure it works fine