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

Adds mac, ip checks for getters #1560

Merged
merged 6 commits into from
Feb 13, 2022

Conversation

mundruid
Copy link
Contributor

@mundruid mundruid commented Feb 12, 2022

Adds mac / ip checks for:

get_lldp_neighbors
get_lldp_neighbors_detail
get_interfaces_ip
get_ntp_peers
traceroute
ping

Covers #451

Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

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

It feels great align everything! Two changes requested, then should be able to get this in.

napalm/ios/ios.py Outdated Show resolved Hide resolved
# format chassis_id for consistency, if it is a mac address
for entry in lldp_entries:
if re.search(
r"^(\d|\w){4}.(\d|\w){4}.(\d|\w){4}$", entry["remote_chassis_id"]
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing this regex check, I'd just apply the convert function instead, e.g.,

Suggested change
r"^(\d|\w){4}.(\d|\w){4}.(\d|\w){4}$", entry["remote_chassis_id"]
entry["remote_chassis_id"] = napalm.base.helpers.conver(napalm.base.helpers.mac, entry["remote_chassis_id"], entry["remote_chassis_id"])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the quick review and all the suggestions. Just checking: I agree with your suggestion, but if the chassis id cannot be converted, an empty chassis id will be returned. This is an example value from a chassis id from one of the tests:

In [75]: id = "hmbbkku-la"

In [76]: id = napalm.base.helpers.convert(napalm.base.helpers.mac, id)

In [77]: id
Out[77]: ''

Is that OK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have addressed the comment with the latest commit. Let me know what you think @mirceaulinic

Copy link
Member

Choose a reason for hiding this comment

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

Yes, there should be a third argument, with the default, notice in the suggestion above:

entry["remote_chassis_id"] = napalm.base.helpers.conver(napalm.base.helpers.mac, entry["remote_chassis_id"], entry["remote_chassis_id"])

When unable to convert to the normalised MAC format, it'd default to the extracted value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the help! Added.

Dr. X and others added 3 commits February 12, 2022 16:55
@mirceaulinic mirceaulinic merged commit 6a936b2 into napalm-automation:develop Feb 13, 2022
@mirceaulinic
Copy link
Member

Thank you @mundruid!

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

Successfully merging this pull request may close these issues.

2 participants