Skip to content

fix: match interface names cut to the NetBox name length - #594

Open
tfoks wants to merge 2 commits into
bb-Ricardo:developmentfrom
tfoks:fix/interface-match-truncated-name
Open

tfoks wants to merge 2 commits into
bb-Ricardo:developmentfrom
tfoks:fix/interface-match-truncated-name

Conversation

@tfoks

@tfoks tfoks commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

netbox-sync cuts interface names to 64 characters when it creates them. The check_redfish source names a Lenovo XCC port after the manager model and its Redfish id, for example:

Lenovo XClarity Controller 2 (1:NIC:672cab626d845d56d397509738c8b03900c7d706)

That name is 77 characters long. map_object_interfaces_to_current_interfaces() compared the full discovered name with the cut name stored in NetBox, so the names never matched. If the MAC address didn't match either, the port was created again on every run, and NetBox rejected it:

ERROR: NetBox returned body: {'__all__': ['Interface with this Device and Name already exists.']}
ERROR: Unfortunately updated item assigned_object_id for object 10.44.100.66/22 could not be fully resolved: <NBInterface instance 'Lenovo XClarity Controller 2 (1:NIC:672cab626d845d56d397509738c8 (de-muc-vs-1001)' ...>

The XCC IP address and MAC address objects then couldn't be assigned either.

Changes:

  • module/sources/common/source_base.py: before the name match, cut the discovered name to the name length of the interface class (NBInterface or NBVMInterface). The cut is logged at debug level. If two discovered names share the same first 64 characters, a warning is logged, since only one of them can exist in NetBox under that name.
  • tests/test_interface_matching_truncated_name.py: tests that a long device interface name and a long VM interface name match the stored interface, that a long name stays unmatched when no such interface exists, and that colliding names are reported.

Tested against NetBox 4.7.2 with the check_redfish inventory files of Lenovo hosts: the XCC ports match their existing interfaces, and a dry-run logs no errors. pytest: 372 passed, 8 skipped (vcsim installed).

🤖 Generated with Claude Code

NetBox stores interface names cut to 64 characters. A Lenovo XCC port is named
after the manager model and its Redfish id, which is longer than that, so the
name match in map_object_interfaces_to_current_interfaces() never found the
stored interface. Without a MAC match the port was created again on every run
and NetBox rejected it with "Interface with this Device and Name already exists."

Cut the discovered name to the data model length before comparing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tfoks
tfoks requested review from bb-Ricardo and semx as code owners October 12, 2026 07:50

@semx semx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reproduced the duplicate: run 1 stores the name cut to 64 chars, run 2 compares the full name, finds nothing and creates the port again. Fixing it in the shared matcher is the right place.

  • The cutting is done by netbox-sync itself when it creates the object (object_classes.py, data_model["name"]), not by NetBox, please reword the comment.
  • If two discovered names share the first 64 chars, the first matches and the second is still created again on every run. A warning when a name gets cut, and when two names collide after the cut, would make that visible.
  • NBVMInterface has the same 64 limit, but disabling the cut for VMs still passes the whole suite; a VM test would cover it.

Small one: the example name is 77 chars, not 79.

Review follow-up:
- take the name length from the interface class (NBInterface or NBVMInterface)
  instead of an existing interface, so it is also known on the first run.
- log a warning if two discovered names share the same first 64 characters,
  only one of them can exist in NetBox. The cut itself is logged at debug level.
- fix the comment: netbox-sync cuts the name when it creates the object.
- add tests for a VM interface and for colliding names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tfoks

tfoks commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all addressed:

  • Comment reworded: netbox-sync cuts the name when it creates the object.
  • If two discovered names share the first 64 characters, a warning names both. I logged the cut itself at debug level rather than as a warning, since every Lenovo XCC port is cut on every run and would add one warning per host per run with nothing to act on. Happy to raise it if you prefer.
  • The limit now comes from the interface class (NBInterface or NBVMInterface) instead of an existing interface, so it's also known on the first run, when nothing exists yet.
  • Added a VM interface test. With the cut disabled for VMs, it now fails.
  • Fixed in the description: 77 characters.

@semx semx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good. I disabled the cut for VMs and dropped the collision warning, and your tests caught both. Fine with debug for the cut itself, a warning for every XCC port on every run would get old fast.

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.

2 participants