Skip to content

[Nexthop][fboss2-dev] Add fboss2-dev config hostname CLI#1343

Open
vybhav-nexthop wants to merge 2 commits into
facebook:mainfrom
nexthop-ai:nos-7154-hostname-config
Open

[Nexthop][fboss2-dev] Add fboss2-dev config hostname CLI#1343
vybhav-nexthop wants to merge 2 commits into
facebook:mainfrom
nexthop-ai:nos-7154-hostname-config

Conversation

@vybhav-nexthop

@vybhav-nexthop vybhav-nexthop commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

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

Adds fboss2-dev config hostname <name>, which sets the optional
sw.hostname field in the agent switch config.

  • Action level: HITLESS — applied via
    ThriftConfigApplier::updateSwitchSettings
    (newSwitchSettings->setHostname); no SAI ChangeProhibited guard.
  • Upsert: if hostname is already set to the requested value, the
    command is a no-op.
  • Validation: the hostname argument is validated against RFC 952/1123
    using RE2 (alphanumeric plus hyphens, max 63 chars per label, total max
    253 chars).
  • Field: switch_config.thrift:SwitchConfig.hostname (optional string)
    — "Overrides the system hostname, useful in ICMP responses."

Test Plan

  • Unit tests (CmdConfigHostnameTestFixture): argument validation (valid
    simple/FQDN, empty args, empty string, too-many args), set-new hostname,
    already-set no-op.
  • End-to-end integration test (ConfigHostnameTest) that sets, verifies,
    and restores the hostname. The integration test reads the initial
    hostname with a "" default so setup tolerates platforms where the
    optional hostname field is unset and therefore omitted from the running
    config.
Unit tests (2026-06-15)
$ bazel build //fboss/cli/fboss2/test/config:cmd_config_test
INFO: Build completed successfully, 1549 total actions

$ ./bazel-bin/fboss/cli/fboss2/test/config/cmd_config_test --gtest_filter="*ConfigHostname*"
[==========] Running 3 tests from 1 test suite.
[ RUN      ] CmdConfigHostnameTestFixture.argValidation
[       OK ] CmdConfigHostnameTestFixture.argValidation (60 ms)
[ RUN      ] CmdConfigHostnameTestFixture.setNewHostname
[       OK ] CmdConfigHostnameTestFixture.setNewHostname (83 ms)
[ RUN      ] CmdConfigHostnameTestFixture.alreadySet
[       OK ] CmdConfigHostnameTestFixture.alreadySet (56 ms)
[==========] 3 tests from 1 test suite ran.
[  PASSED  ] 3 tests.

Full cmd_config_test suite (no regressions):

[==========] 274 tests from 25 test suites ran. (16065 ms total)
[  PASSED  ] 274 tests.

Review Findings

Pre-publication review (single-pass automated reviewer). One item raised —
unchecked *config.sw() dereference in CmdConfigHostname.cpp — reviewed
and dismissed: it is the established pattern across all fboss2 config
commands (e.g. CmdConfigArp.cpp, CmdConfigCopp.cpp); sw is reliably
present for a loaded agent config. No issues above threshold.

Presubmission Checks

  • clang-format (--style=file --dry-run --Werror): pass on all added/modified C++ sources.
  • pre-commit: pass (no violations on changed files).
@vybhav-nexthop vybhav-nexthop requested review from a team as code owners June 29, 2026 07:44
@meta-cla meta-cla Bot added the CLA Signed label Jun 29, 2026
Adds 'fboss2-dev config hostname <name>' command to set the switch
hostname via the FBOSS agent thrift config session.

Also refactors Fboss2IntegrationTest::getSwConfigField to delegate to
a private getSwConfigFieldOpt<T> helper, and adds a two-argument
overload getSwConfigField<T>(field, default) for optional config fields
(used by ConfigHostnameTest to handle platforms where hostname is unset).
@vybhav-nexthop vybhav-nexthop force-pushed the nos-7154-hostname-config branch from 9fb36c7 to 1f79a62 Compare June 29, 2026 09:35

@joseph5wu joseph5wu 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.

Consider to use CmdConfigSwitch to manage individual Switch Settings

// hostname is an optional thrift field; on platforms (e.g. sim) where it is
// unset, it is omitted from the running config. Default to "" so SetUp's
// initial read does not throw before any hostname has been set.
return getSwConfigField<std::string>("hostname", "");

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.

Please consider to use switch_state to verify the config result:
https://github.com/facebook/fboss/blob/main/fboss/agent/switch_state.thrift#L478

fboss2_integration_test already has the following utility function:
https://github.com/facebook/fboss/blob/main/fboss/cli/fboss2/test/integration_test/Fboss2IntegrationTest.h#L131

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.

the issue with these fields is that they are optional, therefore we pass a default as the second argument , so if the config field is not present in the agent.conf, we return the default in our tests . Similar modifications were done in these PRs -> (#1297,
#1268).

std::string findIpv6OnIntf(int intfId) const;

private:
template <typename T>

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.

Please use https://github.com/facebook/fboss/blob/main/fboss/cli/fboss2/test/integration_test/Fboss2IntegrationTest.h#L131 to verify rather than introducing the new getSwConfigFieldOpt() function

…state

- Introduce CmdConfigSwitch parent command (config switch)
- Move `config hostname <name>` → `config switch hostname <name>` as a
  subcommand of CmdConfigSwitch, per reviewer's recommendation to use
  CmdConfigSwitch for Switch Settings
- Integration test: verify hostname via getSwitchSettingsField/
  verifySwitchSettingsField (switch_state) instead of getSwConfigField
  (switch_config), as requested by reviewer
- Remove getSwConfigField{Opt}() helpers added to Fboss2IntegrationTest.h
  — use the pre-existing getSwitchSettingsField instead
- Update BUCK to include CmdConfigSwitch.cpp / .h

@vybhav-nexthop vybhav-nexthop left a comment

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.

Thanks for the review. Addressed all three points in the latest commit:

  1. CmdConfigSwitch: Introduced CmdConfigSwitch as a new parent command and moved hostname under it as config switch hostname.
  2. switch_state verification: Integration test now uses getSwitchSettingsField/verifySwitchSettingsField (reading from switchSettingsMap in switch_state) instead of reading from switch_config.
  3. Removed getSwConfigFieldOpt: Dropped the getSwConfigField{Opt}() helpers from Fboss2IntegrationTest.h entirely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants