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

Added ansible support for LLDP TLVs(port-vlan-id, vlan-name, link-aggregation, maximum-frame-size) #406

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

Conversation

thenmozhi-gopal
Copy link
Contributor

@thenmozhi-gopal thenmozhi-gopal commented Jun 25, 2024

SUMMARY

Added ansible support for LLDP TLVs(port-vlan-id, vlan-name, link-aggregation, maximum-frame-size)
Related PR:
ansible-network/resource_module_models#264

GitHub Issues

List the GitHub issues impacted by this PR. If no Github issues are affected, please indicate this with "N/A".

GitHub Issue #
N/A
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

Sonic_lldp_interfaces

OUTPUT
ADDITIONAL INFORMATION
Checklist:
  • I have performed a self-review of my own code to ensure there are no formatting, linting, or security issues
  • I have verified that new and existing unit tests pass locally with my changes
  • I have not allowed coverage numbers to degenerate
  • I have maintained at least 90% code coverage
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have maintained backward compatibility or have provided any relevant "breaking_changes" descriptions in a "fragment" file in the "changelogs/fragments" directory of this repository.
  • I have provided a summary for this PR in valid "fragment" file format in the "changelogs/fragments" directory of this repository branch. Reference : Ansible Change Log Document
How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also list any relevant details for your test configuration

Regression test report:
Initial regression-report.pdf
Regression-report -latest - 12 Dec 2024
regression-2024-12-12-17-26-02.html.pdf

@kerry-meyer
Copy link
Collaborator

In order to proceed with the code review and merging of these changes, please fix the sanity and UT errors flagged for the current change set posted in this PR.

@stalabi1 stalabi1 added the enhancement New feature or request label Sep 30, 2024
@stalabi1 stalabi1 added this to the v3.1.0 milestone Oct 3, 2024
@awhaley-dell awhaley-dell self-requested a review December 5, 2024 22:31
Copy link
Collaborator

@awhaley-dell awhaley-dell left a comment

Choose a reason for hiding this comment

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

The content of this looks good from my first pass. I have only a minor formatting suggestion for the fragment file and a question about a unit test validation function.

Copy link
Collaborator

@kerry-meyer kerry-meyer left a comment

Choose a reason for hiding this comment

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

This change set looks good for the most part, but I am posting several questions and requests for changes.

I would also like to check the UT coverage results after the additional changes are pushed.

Copy link
Collaborator

@kerry-meyer kerry-meyer left a comment

Choose a reason for hiding this comment

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

I'm adding a couple more comments/questions on the unit test files.

- path: data/openconfig-lldp:lldp/interfaces/interface=Ethernet0/config/openconfig-lldp-ext:allowed-vlans
method: patch
data:
openconfig-lldp-ext:allowed-vlans: '10,15-20'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This format specification is incorrect. It looks like the functional code is correct and works, but the format shown here isn't the format in which the code in the "config" file would send this request. If it did, the request would be rejected. The value associated with the allowed_vlans key should be a list containing unquoted int members and quoted ranges delimited by ".." (not "-"). This line should be:

Suggested change
openconfig-lldp-ext:allowed-vlans: '10,15-20'
openconfig-lldp-ext:allowed-vlans:
- 10
- '15..20'

This means that the unit test should be failing here. If it isn't failing on this, the reason for not detecting the failure needs to be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks okay now.

But before marking this "Issue" resolved: Did you determine why it didn't fail before? Was there some problem in the validation? If not, why did it pass?

@stalabi1
Copy link
Collaborator

stalabi1 commented Dec 6, 2024

Diff and check mode aren't implemented in for this module. Perhaps you can implement it in this PR. You can refer to the implementation of diff and check mode in the lldp_global module or any of the other several modules where it is implemented.

@thenmozhi-gopal
Copy link
Contributor Author

thenmozhi-gopal commented Dec 12, 2024

Diff and check mode aren't implemented in for this module. Perhaps you can implement it in this PR. You can refer to the implementation of diff and check mode in the lldp_global module or any of the other several modules where it is implemented.

diff and check mode implementation would be done as separate story (https://jira.cec.lab.emc.com/browse/SNC01F-55)

- Multiple Vlans or Vlan ranges can be configured.
- Ranges are specified by a start and end Vlan value separated by double dots.
- Vlans configured should be in the range 1-4094.
type: list
Copy link
Collaborator

@kerry-meyer kerry-meyer Dec 13, 2024

Choose a reason for hiding this comment

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

Although this is the only case in our collection where a range would be represented in a playbook by ".." instead of "-" and this range delimiter string is never used in the SONiC CLI, I can see the advantage of using it here and I think it is okay.

I am a little bit concerned that users will be confused by this alternate notation, but it is acceptable if the examples clearly illustrate this. (The examples have not yet been updated to this form.)

Please update the examples to show the new format. (Including the use of a list of vlans and ranges for "merged" and "deleted" states).

Comment on lines +93 to +96
try:
result.append(int(vlan))
except ValueError:
result.append(vlan)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Exceptions cause expenditure of many CPU cycles and should not be used instead of a conditional branch structure. Please use something like the following instead:

Suggested change
try:
result.append(int(vlan))
except ValueError:
result.append(vlan)
if ".." in vlan:
result.append(vlan)
else:
result.append(int(vlan))

plugins/modules/sonic_lldp_interfaces.py Outdated Show resolved Hide resolved
@@ -80,6 +82,20 @@ def get_lldp_interfaces_facts(self):
return []
return lldp_interfaces_facts

def convert_vlan_list(self, vlan_lst):
"""
Convert a list of VLANs to a new list.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please clarify what is being converted.

Suggested change
Convert a list of VLANs to a new list.
Convert a list of strings specifying single VLANs and VLAN
ranges to a new list containing integer values for single
vlans and strings for the ranges.

url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="MDI_POWER")
if 'vlan_name_tlv' in command and command['vlan_name_tlv'] is not None:
if 'allowed_vlans' in command['vlan_name_tlv'] and command['vlan_name_tlv']['allowed_vlans'] is not None:
allowed_vlan = command['vlan_name_tlv']['allowed_vlans']
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although SONiC accepts an allowed_vlan argument specified this way, it silently fails on any ranges included in the string. (It accepts them with no error flagged, but doesn't delete them.)

A bug should be submitted against the SONiC code to fix this, but in the meantime, the Ansible implementation would need to break the deletion ranges into comma-separated lists of integer vlan values to make this work correctly.

Please change this logic accordingly. (It would also be worthwhile to submit a Jira bug against SONiC for this flaw.)

Copy link
Collaborator

@kerry-meyer kerry-meyer left a comment

Choose a reason for hiding this comment

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

Although most of the previous change requests have been addressed and are now resolved, I am posting some additional change requests (and a question, which I think is answered by comments on the UT "test..." file).

@@ -47,6 +47,25 @@ def tearDown(self):
self.mock_config_edit_config.stop()
self.mock_get_interface_naming_mode.stop()

def validate_config_requests(self):
lldp_path = 'data/openconfig-lldp:lldp/interfaces/interface=Ethernet{}/config/openconfig-lldp-ext:suppress-tlv-advertisement'
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like no input request will match this string, so this function will never invoke the parent "validate" function. (The '{}" will not match any value that could be in the request.) Also, there are requests that use paths other than "...suppress_tlv_advertisement" that aren't close to matching this. (e.g. "path: data/openconfig-lldp:lldp/interfaces/interface=Ethernet0/config/openconfig-lldp-ext:allowed-vlans and "path: data/openconfig-lldp:lldp/interfaces/interface=Ethernet0/config/openconfig-lldp-ext:vlan-name-tlv-count".) For those, the parent "validate_config_request method is not being invoked anyway because it's only inside the "if interface_number" block. But even the "...suppress-tlv-advertisment..." paths have additional path information that would cause a miscompare.I realize that a previous "Issue" for this instruction was resolved by replacing "1" with "{}", but how will that resolve the problem? A modified check for the sorting criteria is needed here, using a search for just the "suppress_tlv-advertisement" substring, and the parent "validate" function needs to be invoked for all cases.

More work is needed to make this overload function work as intended. for now, it is apparently just bypassing the validation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with Kerry, using an exact match check with this string will never match a valid path value. The curly braces are not wild cards.
You can try doing the interface check after a substring match if you want that information but I think this validation feature will need another rework.

lldp_path = 'data/openconfig-lldp:lldp/interfaces/interface=Ethernet{}/config/openconfig-lldp-ext:suppress-tlv-advertisement'
interface_number = None
for request in self.config_requests_valid:
if request['path'] == lldp_path:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if request['path'] == lldp_path:
if "openconfig-lldp-ext:suppress-tlv-advertisement" in request['path']:

I feel you should do a substring check here instead of a full exact match check. That should address Kerry's concern about the varieties of tlv suppression.

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

Successfully merging this pull request may close these issues.

4 participants