Skip to content

LldpAdminStatus: Remove Display and FromStr impls#10010

Merged
jgallagher merged 3 commits intomainfrom
john/lldp-admin-status-stringify
Mar 10, 2026
Merged

LldpAdminStatus: Remove Display and FromStr impls#10010
jgallagher merged 3 commits intomainfrom
john/lldp-admin-status-stringify

Conversation

@jgallagher
Copy link
Copy Markdown
Contributor

This is another bit on the yak stack of #9832. A handful of these low-level networking types implement Display and FromStr, and I don't think they should. They don't have a natural representation the way a string, number, or IP address does. This PR removes those impls from LldpAdminStatus and I think is a good example of this. There were no consumers of the FromStr implementation, and there were 3 consumers of the Display impl, but really they want 3 different things:

  • sled-agent needs to set this status as an SMF property on lldpd (the most reasonable use of Display, but I think it's clearer to make this an explicitly named method)
  • wicket wants to display a string to the user (I changed this to be an inline match: there's no reason we have to reuse the same representation lldpd wants, and arguably we can make it look nicer by at least putting spaces in the "tx only" / "rx only" variants - feedback welcome here)
  • wicket also wants to emit this value as part of a config-rss.toml - this use was actually incorrect, and should have been going through serde serialization for the correct value. This didn't cause any problems in practice because our Display impl happened to use the same representation as serde, but this is the kind of happy coincidence that can easily break.

LldpAdminStatus::Enabled => "enabled",
LldpAdminStatus::Disabled => "disabled",
LldpAdminStatus::RxOnly => "rx only",
LldpAdminStatus::TxOnly => "tx only",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bikeshedding welcome on these. Capitalize TX/RX? Get rid of the space? This is displayed in a bulleted list, so I don't think it really needs to match what's in the config file, but if folks disagree we could make this go through serde serialization to match.

Copy link
Copy Markdown
Collaborator

@smklein smklein left a comment

Choose a reason for hiding this comment

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

lgtm, I refuse to be baited into bikeshedding! I think your decisions are fine!

@internet-diglett
Copy link
Copy Markdown
Contributor

wicket wants to display a string to the user (I changed this to be an inline match: there's no reason we have to reuse the same representation lldpd wants, and arguably we can make it look nicer by at least putting spaces in the "tx only" / "rx only" variants - feedback welcome here)

This justification seems sound to me!

@jgallagher jgallagher merged commit fa7ce0e into main Mar 10, 2026
16 checks passed
@jgallagher jgallagher deleted the john/lldp-admin-status-stringify branch March 10, 2026 14:52
jgallagher added a commit that referenced this pull request Mar 10, 2026
Followup to #10010, and pretty similar:

* There was only one consumer of `FromStr`; it was a test and was not
using the majority of the parsing complexity (which handled both the
special string `"link-local"` and optional VLANs, neither of which the
test used). The test now goes through a new constructor (which may
itself be overkill; I'll revisit it as a part of #9832).
* There was only two consumers of `Display` - `sled-agent` and
`wicketd`, both setting SMF properties - and those now use an
explicitly-named method so we don't assume an `UplinkAddressConfig` can
generally be converted to a `String`.
jgallagher added a commit that referenced this pull request Mar 12, 2026
Reasoning here is similar to #10010: this isn't really a
naturally-displayable type, and in this case we were previously abusing
this to stringify it both in the db (fixed by #9984) and the external
API (fixed by #10014, on which this PR is based).

Maybe worth noting: I expected this to be entirely futureproofing, but
by doing this I found a few external API types that I'd missed in an
earlier draft of #10014 (types where we stringified `SwitchSlot`s for
_output_ but never parsed them as _input_).

All our remaining uses of the display impl are either for logging or
constructing internal error messages; I changed all of these to use
`Debug`, and added a manual `Debug` implementation that matches the old
`Display` implementation. This should keep the error messages and logs
consistent while not leading us to the pit of sadness of assuming we can
format and parse these values as strings without consideration.
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