Skip to content

fix: use name of interface instead of relying on idx - #458

Open
AloizioMacedo wants to merge 3 commits into
canonical:masterfrom
AloizioMacedo:lp-2160526
Open

fix: use name of interface instead of relying on idx#458
AloizioMacedo wants to merge 3 commits into
canonical:masterfrom
AloizioMacedo:lp-2160526

Conversation

@AloizioMacedo

@AloizioMacedo AloizioMacedo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

When creating a machine, we do some song and dance with LXD and the interfaces that are specified seem to be retrieved in alphabetical order of their names, even though we assume same-order of the listing. This is likely an artifact of the fact that LXD is written in Go, and marshalling sorts keys.

We now store and use the name directly later, if available. It may not be available since that same code path is run for virsh as well.

Resolves: LP:2160526

@AloizioMacedo AloizioMacedo self-assigned this Jul 13, 2026
@AloizioMacedo
AloizioMacedo requested a review from a team July 13, 2026 22:31
@maas-lander

Copy link
Copy Markdown
Collaborator

Check where you would like a Mattermost message to be sent to when CI completes and this PR is merged

  • Direct message
  • ~maas

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[maas-code-reviewer review]

LLM-generated review from https://github.com/canonical/maas-code-reviewer.
Intended to assist a human reviewer, not replace one — suggestions may be
incorrect, please verify before acting.

The proposed fix correctly addresses the issue where LXD returns machine interfaces sorted alphabetically (likely due to map serialization in Go). By checking discovered_nic.name and falling back to the ordered interface_names for drivers like virsh, the code ensures network interfaces are accurately mapped to the configurations specified in constraints without breaking existing hypervisor support. The included unit test additions properly validate the changes. Good job!

Comment thread src/maasserver/models/bmc.py
Comment thread src/provisioningserver/drivers/pod/tests/test_lxd.py
Comment thread src/maasserver/models/bmc.py

elif device["type"] == "nic":
interfaces.append(
_get_discovered_interface(name, device, not interfaces)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just curious about this. we set boot.priority on the first requested NIC at compose time, but discovery marks boot from list order here. With custom names, would that still be the same NIC?

@tanzin8r tanzin8r left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

left a couple of comments.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants