[Nexthop][fboss2-dev] sort show interface status and transceiver by numeric interface ID - #1422
Open
benoit-nexthop wants to merge 1 commit into
Open
[Nexthop][fboss2-dev] sort show interface status and transceiver by numeric interface ID#1422benoit-nexthop wants to merge 1 commit into
benoit-nexthop wants to merge 1 commit into
Conversation
…terface ID # Summary `show interface status` and `show transceiver` ordered interfaces by a plain lexicographic comparison of the interface name, so ports came out as: ``` eth1/1/1 eth1/10/1 eth1/100/1 eth1/101/1 eth1/2/1 ``` `show port` doesn't have this problem because it sorts with `utils::comparePortName`, which parses the `moduleNum/port/subport` components and compares them numerically. This PR points the other two commands at the same comparator so all three sort consistently: ``` eth1/1/1 eth1/2/1 eth1/10/1 eth1/100/1 eth1/101/1 ``` - **`show interface status`** (`CmdShowInterfaceStatus.cpp`): the model is already a sorted `std::vector`; swapped the `a.name() < b.name()` lambda for `utils::comparePortName`. - **`show transceiver`** (`CmdShowTransceiver.cpp`): the ordering came from its `map<string, TransceiverDetail>` model key, so there was no explicit sort to change. The rows are now sorted in `printOutput` before being emitted. `comparePortName` throws on names that don't match the `moduleNum/port/subport` pattern, so it's wrapped to fall back to lexicographic order for bypass modules whose interface names may not match — preserving today's behavior for those rather than crashing the command. # Test Plan Added unit tests: - `CmdShowInterfaceStatusTest.createModelNaturalSort` — feeds `eth1/2/1, eth1/10/1, eth1/1/1, eth1/100/1, eth2/1/1` and asserts the model comes out in numeric order. - `CmdShowTransceiverTest.printOutputNaturalSort` — injects `eth1/10/1` (which sorts between `eth1/1/1` and `eth1/2/1` as a string) and asserts it is printed after `eth1/8/1`. Existing `createModel`/`printOutput` tests are unchanged since their fixtures use single-digit ports that already sort identically both ways.
Contributor
|
@joseph5wu has imported this pull request. If you are a Meta employee, you can view this in D113812048. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
show interface statusandshow transceiverordered interfaces by a plain lexicographic comparison of the interface name, so ports came out as:show portdoesn't have this problem because it sorts withutils::comparePortName, which parses themoduleNum/port/subportcomponents and compares them numerically. This PR points the other two commands at the same comparator so all three sort consistently:show interface status(CmdShowInterfaceStatus.cpp): the model is already a sortedstd::vector; swapped thea.name() < b.name()lambda forutils::comparePortName.show transceiver(CmdShowTransceiver.cpp): the ordering came from itsmap<string, TransceiverDetail>model key, so there was no explicit sort to change. The rows are now sorted inprintOutputbefore being emitted.comparePortNamethrows on names that don't match themoduleNum/port/subportpattern, so it's wrapped to fall back to lexicographic order for bypass modules whose interface names may not match — preserving today's behavior for those rather than crashing the command.Test Plan
Added unit tests:
CmdShowInterfaceStatusTest.createModelNaturalSort— feedseth1/2/1, eth1/10/1, eth1/1/1, eth1/100/1, eth2/1/1and asserts the model comes out in numeric order.CmdShowTransceiverTest.printOutputNaturalSort— injectseth1/10/1(which sorts betweeneth1/1/1andeth1/2/1as a string) and asserts it is printed aftereth1/8/1.Existing
createModel/printOutputtests are unchanged since their fixtures use single-digit ports that already sort identically both ways.