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

lldp: Handling attributes that are defined multiple times #9657

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion plugins/modules/lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def gather_lldp(module):
for path_component in path_components:
current_dict[path_component] = current_dict.get(path_component, {})
current_dict = current_dict[path_component]
current_dict[final] = value
if final not in current_dict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is the right fix. The error was TypeError: 'str' object does not support item assignment, which means that current_dict was not a dictionary, but a string.

In that case, final not in current_dict will test whether final (if it happens to be a string) appears in the string final. (If final happens to be an integer, for example, this will cause another exception: TypeError: 'in <string>' requires string as left operand, not int.) I don't think this is what you intended.

Copy link
Author

Choose a reason for hiding this comment

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

The Idea of my fix was that when
lldp.eno1.unknown-tlvs.unknown-tlv=4A,5A,30,32,31,38,33,30,30,37,31,31 is processed it's not overwriting the dict at lldp['eno1']['unknown-tlvs']['unknown-tlv']. So current_dict never becomes a string in the first place if we prevent the overwriting behavior.

But indeed this is not the most robust fix. It would not prevent the problem if the lldp.eno1.unknown-tlvs.unknown-tlv=4A,5A,30,32,31,38,33,30,30,37,31,31 line is the first one in the output.

Let me comeback with a solution that covers more cases.

current_dict[final] = value
return output_dict


Expand Down