Skip to content

Conversation

@benoit-nexthop
Copy link
Contributor

@benoit-nexthop benoit-nexthop commented Dec 18, 2025

Pre-submission checklist

  • I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running pip install -r requirements-dev.txt && pre-commit install
  • pre-commit run

Summary

This is a small helper class used to lookup ports and interfaces in a consistent fashion in CLI commands.

Note: this change is part of a series, the previous one is #754, the next one is #756.

Test Plan

Unit tests.

@meta-cla meta-cla bot added the CLA Signed label Dec 18, 2025
@benoit-nexthop benoit-nexthop marked this pull request as ready for review December 18, 2025 00:36
@benoit-nexthop benoit-nexthop force-pushed the fboss2-cli-prototype_part03 branch from 04bd218 to ab2a9fb Compare December 19, 2025 23:32
Copy link
Contributor

@joseph5wu joseph5wu left a comment

Choose a reason for hiding this comment

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

Overall it looks pretty good to me. Please address the two main comments:

  • Removing vlog
  • Use fboss strong type for the ids

@benoit-nexthop benoit-nexthop force-pushed the fboss2-cli-prototype_part03 branch from ab2a9fb to 1e8d134 Compare December 23, 2025 21:38
@benoit-nexthop benoit-nexthop force-pushed the fboss2-cli-prototype_part03 branch 4 times, most recently from 7a586bc to 4102813 Compare December 25, 2025 22:00
meta-codesync bot pushed a commit that referenced this pull request Dec 29, 2025
Summary:
**Pre-submission checklist**
- [x] I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running `pip install -r requirements-dev.txt && pre-commit install`
- [x] `pre-commit run`

Sample output:
```
Config Applied Information:
===========================
Last Applied Time: 2025-10-11 09:29:36.589
Last Coldboot Applied Time: 2025-10-11 06:44:36.741
```

Note: this change is part of a series, the previous one is #753, the next one is #755.

Pull Request resolved: #754

Test Plan: Unit tests.

Reviewed By: KevinYakar

Differential Revision: D89894234

Pulled By: joseph5wu

fbshipit-source-id: 97c71bc011882b0cb19b5e9d947c50d8bc3edef2
@meta-codesync
Copy link

meta-codesync bot commented Dec 29, 2025

@joseph5wu has imported this pull request. If you are a Meta employee, you can view this in D89903145.

Copy link
Contributor

@joseph5wu joseph5wu left a comment

Choose a reason for hiding this comment

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

Please adjust the two main comments I added.
Besides, I noticed there're some missing dependency issues on buck:

❯❯❯ sl diff
diff --git a/fbcode/fboss/cli/fboss2/BUCK b/fbcode/fboss/cli/fboss2/BUCK
--- a/fbcode/fboss/cli/fboss2/BUCK
+++ b/fbcode/fboss/cli/fboss2/BUCK
@@ -776,8 +776,14 @@
     exported_deps = [
         ":cmd-handler",
         ":fboss2-lib",
+        "//fboss/agent:agent_config-cpp2-types",
+        "//fboss/agent:fboss-types",
+        "//fboss/agent/if:ctrl-cpp2-types",
         "//folly:conv",
     ],
+    exported_external_deps = [
+        "glog",
+    ],
 )

 cpp_binary(
diff --git a/fbcode/fboss/cli/fboss2/test/BUCK b/fbcode/fboss/cli/fboss2/test/BUCK
--- a/fbcode/fboss/cli/fboss2/test/BUCK
+++ b/fbcode/fboss/cli/fboss2/test/BUCK
@@ -89,6 +89,9 @@
         "CmdStopPcapTest.cpp",
         "PortMapTest.cpp",
     ],
+    # Required for parameterized tests (TEST_P) - static listing doesn't support them
+    # See: https://fburl.com/parameterized-test-not-supported
+    supports_static_listing = False,
     deps = [
         "fbsource//third-party/googletest:gmock",
         ":cmd_test_utils",
@@ -122,9 +125,11 @@
         "//fboss/cli/fboss2/commands/show/route:model-cpp2-types",
         "//fboss/cli/fboss2/commands/show/teflow:model-cpp2-types",
         "//fboss/cli/fboss2/commands/show/transceiver:model-cpp2-types",
+        "//folly:file_util",
         "//folly:network_address",
         "//folly/json:dynamic",
         "//neteng/fboss/bgp/if:bgp_thrift-cpp2-services",
+        "//thrift/lib/cpp2/protocol:protocol",
         "//thrift/lib/cpp2/reflection:testing",
     ],
     external_deps = [("boost", None, "boost_algorithm")],

Besides the missing dependency, supports_static_listing = False, is needed because you're using INSTANTIATE_TEST_SUITE_P in PortMapTest.cpp. Once you address the two major comments, please make sure to include the above buck fixes in the PR

// Helper function to get all config files from the link_test_configs directory
std::vector<std::string> getAllConfigFiles() {
std::vector<std::string> configFiles;
std::string configDir = "/var/FBOSS/fboss/fboss/oss/link_test_configs/";
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately we can't guarantee the lint_test_configs in the exact directory when running the unit test.
Most of the time, we run our unit tests either on our dev servers or a remote machine just build the test binary and run it on a test virtual environment.
I'd suggest to not keep these tests as unit tests if we expect certain configs only exist in some fixed directory.
We can consider to have these tests in end-to-end tests, which we can setup test environment before running tests.

✗ Fail: fbcode//fboss/cli/fboss2/test:cmd_test - PortMapTest.MontblancVlanMapping (0.8s)
Note: Google Test filter = PortMapTest.MontblancVlanMapping
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from PortMapTest
[ RUN      ] PortMapTest.MontblancVlanMapping

Warning: Could not read config directory: filesystem error: directory iterator cannot open directory: No such file or directory [/var/FBOSS/fboss/fboss/oss/link_test_configs/]
terminate called after throwing an instance of 'std::runtime_error'
  what():  Failed to read config file: /var/FBOSS/fboss/fboss/oss/link_test_configs/montblanc.materialized_JSON
*** Aborted at 1767051882 (Unix time, try 'date -d @1767051882') ***
*** Signal 6 (SIGABRT) (0x1cc25001be8db) received by PID 1829083 (pthread TID 0x7fc95ad8e240) (linux TID 1829083) (maybe from PID 1829083, UID 117797) (code: -6), stack trace: ***
==1829083==WARNING: ASan doesn't fully support makecontext/swapcontext functions and may produce false positives in some cases!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did some more research and it seems that we can add a BUCK file in fboss/oss/link_test_configs and then define a filegroup that we can use to be able to reference those files during unit tests. I'll send something to that effect and you can try it out and let me know if it works or if at least it's closer to having something working.

Copy link
Contributor

@joseph5wu joseph5wu left a comment

Choose a reason for hiding this comment

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

Add some linter issues

}

std::optional<std::string> PortMap::getPortNameForInterface(
InterfaceID interfaceId) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

linter:

the parameter 'interfaceId' is copied for each invocation but only used as a const reference; consider making it a const reference
Lint code: CLANGTIDY
Lint name: performance-unnecessary-value-param

-    InterfaceID interfaceId) const {
+    const InterfaceID& interfaceId) const {

Copy link
Contributor Author

@benoit-nexthop benoit-nexthop Dec 30, 2025

Choose a reason for hiding this comment

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

I don't mind making this change but clang-tidy is wrong here, InterfaceID is defined in types.h as just a uint32_t using FBOSS_STRONG_TYPE, which calls BOOST_STRONG_TYPEDEF, which creates a struct containing just a uint32_t. So InterfaceID has the memory representation of uint32_t, it's just 4 bytes. Passing it by value here is more efficient/cheaper, the value just goes into a register when the method is called. Using a const reference adds a 64-byte pointer indirection that doesn't buy us anything. I suppose clang-tidy can't see through the #define etc so this leads to a false positive. The OSS repo has no .clang-tidy config file, maybe you could open source yours so we could make sure that the OSS build checks those things too, and we could configure performance-unnecessary-value-param.AllowedTypes to tell it that all those types defined with FBOSS_STRONG_TYPE are OK to pass by value?

Copy link
Contributor

@joseph5wu joseph5wu Dec 30, 2025

Choose a reason for hiding this comment

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

Unfortunately we can't open source the .clang-tidy as there're lots "facebook-" internal linters which I don't know whether it could be available on OSS.
And you're absolutely right about the efficiency of not using const ref. In that case, I think it's safe to ignore the linter. I'm adding the following ignore linter comment to bypass such linter check when importing your PR:

// @lint-ignore CLANGTIDY performance-unnecessary-value-param
std::optional<std::string> PortMap::getPortNameForInterface(
    InterfaceID interfaceId) const {

@benoit-nexthop benoit-nexthop force-pushed the fboss2-cli-prototype_part03 branch from 2da98c7 to b53678a Compare December 30, 2025 11:11
@facebook-github-bot
Copy link
Contributor

@benoit-nexthop has updated the pull request. You must reimport the pull request before landing.

@benoit-nexthop benoit-nexthop force-pushed the fboss2-cli-prototype_part03 branch from b53678a to 0073161 Compare December 30, 2025 15:47
@facebook-github-bot
Copy link
Contributor

@benoit-nexthop has updated the pull request. You must reimport the pull request before landing.

@meta-codesync
Copy link

meta-codesync bot commented Dec 31, 2025

@joseph5wu merged this pull request in befd0e0.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants