Skip to content

Conversation

@mzbroch
Copy link
Contributor

@mzbroch mzbroch commented Nov 12, 2025

Summary

This PR is Stage 1 refactor before moving components out of onboarding app to nornir-nautobot.

PR refactors the netmiko_send_commands function to remove duplicated logic, improve readability, and make command filtering more maintainable — without changing any behavior..

Key Improvements
✅ Removed redundant loops and conditions
Consolidated repeated logic for handling commands as lists or dicts.

✅ Centralized skip logic
Introduced a single command_exclusions mapping instead of multiple scattered if not sync_* checks.

✅ Decoupled jobs from automation runner
Removed job and job inputs dependency in lower level methods, separating them from actual user input

✅ Improved readability
Clearer handling of the "pre_processor" section and command collection flow.

✅ Behavior preserved
All original skip rules, deduplication behavior, and flag-based filters remain identical.

✅ Safer and cleaner
Uses get("commands", []) and .extend() for simpler and more resilient logic.

@mzbroch mzbroch marked this pull request as draft November 13, 2025 13:16
@mzbroch mzbroch changed the title Simplify _get_commands_to_run method for clarity and maintainability Simplify netmiko_send_commands method for clarity and maintainability Nov 19, 2025
Copy link
Contributor

@jeffkala jeffkala left a comment

Choose a reason for hiding this comment

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

Looks good. Relying on the test quite a bit for the logic not changing but went through it slowly and I think this is a much cleaner and manage code base.

Just a few questions but otherwise I"m good with it.

if validation_result:
return validation_result

if connectivity_test and not _check_connectivity(task):
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, this is also already in nornir-nautobot as a dispatcher function. I understand this is step 1 of this revamp, but keeping here for awareness for future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes — I needed to simplify it initially so that I could more easily migrate to nornir-nautobot.


def _handle_netmiko_error(task, exception):
"""Handle connection/authentication errors gracefully."""
from netmiko.exceptions import NetmikoTimeoutException, NetmikoAuthenticationException
Copy link
Contributor

Choose a reason for hiding this comment

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

why here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's incorrect here.

Comment on lines +45 to +52
skip_list = [
"cables",
"interfaces__tagged_vlans",
"interfaces__untagged_vlan",
"interfaces__vrf",
"software_version",
"vlan_map",
],
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by this, mind explaining this a bit more?

Comment on lines +83 to +89
skip_list = [
"cables",
"interfaces__tagged_vlans",
"interfaces__untagged_vlan",
"software_version",
"vlan_map",
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming the explaination from the previous comment, maybe we should move this somehow into constants.py

)
},
defaults=Defaults(data={"sync_vlans": False, "sync_vrfs": False, "sync_cables": False}),
# defaults=Defaults(data={"sync_vlans": False, "sync_vrfs": False, "sync_cables": False}),
Copy link
Contributor

Choose a reason for hiding this comment

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

intentional?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants