From 3187ef7f9914c3b79c758424f0d3649acd62094c Mon Sep 17 00:00:00 2001 From: Hillol Chakraborty Date: Mon, 16 Nov 2026 05:17:20 +0000 Subject: [PATCH] [fboss2-dev] Warn instead of rejecting a profile the transceiver does not support `fboss2-dev config interface profile

` rejected any profile missing from qsfp_service's transceiver-filtered list for the port. The agent has no such check: it applies whatever platform-supported profile its config carries. A port could therefore be running a profile that the CLI refused to set, including re-applying the one it already runs. One case is a passive copper cable on a port configured with an OPTICAL profile: the link is up, but once the port is moved to a COPPER profile the CLI cannot move it back. Make the transceiver list advisory in the command layer. The platform mapping still decides what is accepted; a profile missing from a port's non-empty transceiver list is applied and reported as a warning after the success line. When qsfp_service cannot be reached the command says the profile was not checked. utility::applyPortProfileChanges keeps its behaviour; the CLI no longer passes it the transceiver list. --- .../config/interface/CmdConfigInterface.cpp | 64 ++++++-- .../config/interface/CmdConfigInterface.h | 5 +- .../test/config/CmdConfigInterfaceTest.cpp | 143 ++++++++++++++++-- fboss/cli/fboss2/test/integration_test/BUCK | 1 + .../ConfigInterfaceProfileTest.cpp | 88 +++++++++++ fboss/lib/config/agent/PortConfigUtils.h | 3 +- 6 files changed, 280 insertions(+), 24 deletions(-) diff --git a/fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.cpp b/fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.cpp index 562563f5ac6..71fb5050fa0 100644 --- a/fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.cpp +++ b/fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -189,7 +190,8 @@ std::string applyProfileImpl( const utility::PortProfileSupportMap& qsfpSupportedProfiles, const utils::InterfaceList& interfaces, const std::string& value, - cli::ConfigActionLevel* actionLevel) { + cli::ConfigActionLevel* actionLevel, + std::vector* warnings) { // Parse once (throws std::invalid_argument on a bad string) and thread the // enum through the rest of the flow. const cfg::PortProfileID requestedProfile = parsePortProfile(value); @@ -222,12 +224,40 @@ std::string applyProfileImpl( utility::PortProfileChangeResult result; try { - result = utility::applyPortProfileChanges( - swConfig, platformMapping, requests, qsfpSupportedProfiles); + result = + utility::applyPortProfileChanges(swConfig, platformMapping, requests); } catch (const FbossError& error) { throw std::invalid_argument(error.what()); } + // The agent applies any platform-supported profile from its config whatever + // the transceiver, so a transceiver mismatch only warns here. + if (warnings != nullptr) { + for (const auto& request : result.requestedPorts) { + const auto qsfpProfiles = qsfpSupportedProfiles.find(request.portName); + if (qsfpProfiles == qsfpSupportedProfiles.end() || + qsfpProfiles->second.empty() || + std::find( + qsfpProfiles->second.begin(), + qsfpProfiles->second.end(), + requestedProfile) != qsfpProfiles->second.end()) { + continue; + } + std::vector supportedNames; + supportedNames.reserve(qsfpProfiles->second.size()); + for (const auto profileID : qsfpProfiles->second) { + supportedNames.push_back(apache::thrift::util::enumNameSafe(profileID)); + } + warnings->push_back( + fmt::format( + "Warning: profile '{}' is not supported by the transceiver on " + "port {}. Supported profiles: [{}]", + apache::thrift::util::enumNameSafe(requestedProfile), + request.portName, + folly::join(", ", supportedNames))); + } + } + const auto profileSpeed = result.requestedPorts.empty() ? cfg::PortSpeed::DEFAULT : result.requestedPorts.front().speed; @@ -275,7 +305,8 @@ std::string applyProfile( const HostInfo& hostInfo, const utils::InterfaceList& interfaces, const std::string& value, - cli::ConfigActionLevel* actionLevel = nullptr) { + cli::ConfigActionLevel* actionLevel = nullptr, + std::vector* warnings = nullptr) { cfg::PlatformMapping platformMappingConfig; auto agentClient = utils::createClient>(hostInfo); @@ -286,9 +317,14 @@ std::string applyProfile( auto qsfpClient = utils::createClient>(hostInfo); qsfpClient->sync_getAllPortSupportedProfiles(qsfpSupportedProfiles, true); - } catch (const std::exception&) { - // QsfpService unavailable; applyPortProfileChanges falls back to platform - // mapping support. + } catch (const std::exception& ex) { + XLOG(WARN) << "Unable to query qsfp_service for supported profiles: " + << ex.what(); + if (warnings != nullptr) { + warnings->emplace_back( + "Warning: qsfp_service is unreachable, so the profile was not " + "checked against the transceiver"); + } } const PlatformMapping platformMapping(platformMappingConfig); @@ -298,7 +334,8 @@ std::string applyProfile( qsfpSupportedProfiles, interfaces, value, - actionLevel); + actionLevel, + warnings); } // Creates the virtual loopback interface for `index`, plus its backing VLAN @@ -723,9 +760,10 @@ CmdConfigInterfaceTraits::RetType CmdConfigInterface::queryClient( // (LookupClassRouteUpdater dereferences the removed port's now-absent // interface). See T281221621. cli::ConfigActionLevel actionLevel = cli::ConfigActionLevel::HITLESS; + std::vector warnings; if (profileValue.has_value()) { - results.push_back( - applyProfile(hostInfo, interfaces, *profileValue, &actionLevel)); + results.push_back(applyProfile( + hostInfo, interfaces, *profileValue, &actionLevel, &warnings)); changed = true; ConfigSession::getInstance().rebuildPortMap(); } @@ -873,8 +911,12 @@ CmdConfigInterfaceTraits::RetType CmdConfigInterface::queryClient( std::string interfaceList = folly::join(", ", interfaces.getNames()); std::string attrList = folly::join(", ", results); - return fmt::format( + auto out = fmt::format( "Successfully configured interface(s) {}: {}", interfaceList, attrList); + for (const auto& warning : warnings) { + out += "\n" + warning; + } + return out; } void CmdConfigInterface::printOutput(const RetType& logMsg) { diff --git a/fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.h b/fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.h index 4603d28f340..6d4130e0a7b 100644 --- a/fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.h +++ b/fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.h @@ -88,12 +88,15 @@ class CmdConfigInterface // warmboot/coldboot can escalate it too. cfg::PortProfileID parsePortProfile(const std::string& profile); +// `qsfpSupportedProfiles` is advisory: a requested profile missing from a +// port's non-empty entry is still applied, and reported in `warnings`. std::string applyProfileImpl( cfg::SwitchConfig& swConfig, const PlatformMapping& platformMapping, const utility::PortProfileSupportMap& qsfpSupportedProfiles, const utils::InterfaceList& interfaces, const std::string& value, - cli::ConfigActionLevel* actionLevel = nullptr); + cli::ConfigActionLevel* actionLevel = nullptr, + std::vector* warnings = nullptr); } // namespace facebook::fboss diff --git a/fboss/cli/fboss2/test/config/CmdConfigInterfaceTest.cpp b/fboss/cli/fboss2/test/config/CmdConfigInterfaceTest.cpp index 074efcc2f6a..636c695de4b 100644 --- a/fboss/cli/fboss2/test/config/CmdConfigInterfaceTest.cpp +++ b/fboss/cli/fboss2/test/config/CmdConfigInterfaceTest.cpp @@ -1876,6 +1876,37 @@ TEST_F(ApplyProfileSubsumeTestFixture, subsumeEscalatesToColdboot) { EXPECT_EQ(actionLevel, cli::ConfigActionLevel::DISRUPTIVE_SERVICE_RESTART); } +TEST_F(ApplyProfileSubsumeTestFixture, warnsOnExistingPortUnsupportedByQsfp) { + setupTestableConfigSession( + "config interface", "eth1/1/1 profile PROFILE_400G_8_PAM4_RS544X2N"); + auto platformMapping = makeSubsumePlatformMapping(); + auto& swConfig = *ConfigSession::getInstance().getAgentConfig().sw(); + utils::InterfaceList interfaces({"eth1/1/1"}); + const utility::PortProfileSupportMap qsfpSupportedProfiles{ + {"eth1/1/1", {cfg::PortProfileID::PROFILE_100G_4_NRZ_CL91}}}; + std::vector warnings; + + applyProfileImpl( + swConfig, + platformMapping, + qsfpSupportedProfiles, + interfaces, + "PROFILE_400G_8_PAM4_RS544X2N", + nullptr, + &warnings); + + ASSERT_EQ(swConfig.ports()->size(), 1u); + EXPECT_EQ( + *swConfig.ports()->front().profileID(), + cfg::PortProfileID::PROFILE_400G_8_PAM4_RS544X2N); + ASSERT_EQ(warnings.size(), 1u); + EXPECT_EQ( + warnings[0], + "Warning: profile 'PROFILE_400G_8_PAM4_RS544X2N' is not supported by the " + "transceiver on port eth1/1/1. Supported profiles: " + "[PROFILE_100G_4_NRZ_CL91]"); +} + // ============================================================================ // applyProfileImpl pending-port (creation) tests // ============================================================================ @@ -1969,24 +2000,114 @@ TEST_F(CreatePendingInterfacePortsTestFixture, createsSupportedInterfacePort) { TEST_F( CreatePendingInterfacePortsTestFixture, - rejectsProfileUnsupportedByQsfp) { + warnsOnlyForPortsUnsupportedByQsfp) { setupTestableConfigSession(); auto platformMapping = makePendingMapping(); cfg::SwitchConfig config; utils::InterfaceList interfaces( - std::vector{"eth1/1/1"}, /*allowMissing*/ true); + std::vector{"eth1/1/1", "eth1/1/2"}, /*allowMissing*/ true); const utility::PortProfileSupportMap qsfpSupportedProfiles{ + {"eth1/1/1", {cfg::PortProfileID::PROFILE_100G_4_NRZ_CL91}}, + {"eth1/1/2", {cfg::PortProfileID::PROFILE_400G_8_PAM4_RS544X2N}}}; + std::vector warnings; + + applyProfileImpl( + config, + platformMapping, + qsfpSupportedProfiles, + interfaces, + "PROFILE_100G_4_NRZ_CL91", + nullptr, + &warnings); + + ASSERT_EQ(config.ports()->size(), 2u); + for (const auto& port : *config.ports()) { + EXPECT_EQ(*port.profileID(), cfg::PortProfileID::PROFILE_100G_4_NRZ_CL91); + } + ASSERT_EQ(warnings.size(), 1u); + EXPECT_EQ( + warnings[0], + "Warning: profile 'PROFILE_100G_4_NRZ_CL91' is not supported by the " + "transceiver on port eth1/1/2. Supported profiles: " + "[PROFILE_400G_8_PAM4_RS544X2N]"); +} + +TEST_F( + CreatePendingInterfacePortsTestFixture, + noWarningWhenQsfpSupportsOrDoesNotReportPort) { + setupTestableConfigSession(); + auto platformMapping = makePendingMapping(); + utils::InterfaceList interfaces( + std::vector{"eth1/1/1"}, /*allowMissing*/ true); + for (const auto& qsfpSupportedProfiles : + {utility::PortProfileSupportMap{ + {"eth1/1/1", {cfg::PortProfileID::PROFILE_100G_4_NRZ_CL91}}}, + utility::PortProfileSupportMap{{"eth1/1/1", {}}}, + utility::PortProfileSupportMap{}}) { + cfg::SwitchConfig config; + std::vector warnings; + applyProfileImpl( + config, + platformMapping, + qsfpSupportedProfiles, + interfaces, + "PROFILE_100G_4_NRZ_CL91", + nullptr, + &warnings); + EXPECT_EQ(config.ports()->size(), 1u); + EXPECT_TRUE(warnings.empty()); + } +} + +TEST_F( + CreatePendingInterfacePortsTestFixture, + queryClientPrintsQsfpWarningAfterSuccess) { + setupTestableConfigSession(); + EXPECT_CALL(getMockAgent(), getPlatformMapping(_)) + .WillRepeatedly( + DoAll(SetArgReferee<0>(makePendingPlatformMapping()), Return())); + const std::map> qsfpProfiles{ {"eth1/1/1", {cfg::PortProfileID::PROFILE_400G_8_PAM4_RS544X2N}}}; + EXPECT_CALL(getQsfpService(), getAllPortSupportedProfiles(_, _)) + .WillRepeatedly(DoAll(SetArgReferee<0>(qsfpProfiles), Return())); - EXPECT_THROW( - applyProfileImpl( - config, - platformMapping, - qsfpSupportedProfiles, - interfaces, - "PROFILE_100G_4_NRZ_CL91"), - std::invalid_argument); - EXPECT_TRUE(config.ports()->empty()); + InterfacesConfig config( + {"eth1/1/1", "profile", "PROFILE_100G_4_NRZ_CL91", "mtu", "9000"}); + auto result = CmdConfigInterface().queryClient(localhost(), config); + + EXPECT_THAT( + result, StartsWith("Successfully configured interface(s) eth1/1/1: ")); + EXPECT_THAT( + result, + EndsWith( + "mtu=9000\nWarning: profile 'PROFILE_100G_4_NRZ_CL91' is not " + "supported by the transceiver on port eth1/1/1. Supported profiles: " + "[PROFILE_400G_8_PAM4_RS544X2N]")); +} + +TEST_F( + CreatePendingInterfacePortsTestFixture, + queryClientReportsUnreachableQsfpService) { + setupTestableConfigSession(); + EXPECT_CALL(getMockAgent(), getPlatformMapping(_)) + .WillRepeatedly( + DoAll(SetArgReferee<0>(makePendingPlatformMapping()), Return())); + EXPECT_CALL(getQsfpService(), getAllPortSupportedProfiles(_, _)) + .WillRepeatedly(Throw(std::runtime_error("qsfp_service down"))); + + InterfacesConfig config({"eth1/1/1", "profile", "PROFILE_100G_4_NRZ_CL91"}); + auto result = CmdConfigInterface().queryClient(localhost(), config); + + EXPECT_THAT( + result, StartsWith("Successfully configured interface(s) eth1/1/1: ")); + EXPECT_THAT( + result, + EndsWith( + "\nWarning: qsfp_service is unreachable, so the profile was not " + "checked against the transceiver")); + EXPECT_THAT(result, Not(HasSubstr("is not supported by the transceiver"))); + ASSERT_EQ( + ConfigSession::getInstance().getAgentConfig().sw()->ports()->size(), 1u); } // Creating a port removes nothing, so the action level stays HITLESS (no diff --git a/fboss/cli/fboss2/test/integration_test/BUCK b/fboss/cli/fboss2/test/integration_test/BUCK index b79498059f7..cce9bdcfed4 100644 --- a/fboss/cli/fboss2/test/integration_test/BUCK +++ b/fboss/cli/fboss2/test/integration_test/BUCK @@ -128,6 +128,7 @@ cpp_binary( "//fboss/cli/fboss2:fboss2-config-lib", # @manual "//fboss/cli/fboss2:fboss2-lib", # @manual "//fboss/lib/config:fboss_config_utils", + "//fboss/qsfp_service/if:qsfp-cpp2-services", "//neteng/fboss/bgp/if:bgp_thrift-cpp2-services", "//neteng/fboss/bgp/public_tld/configerator/structs/neteng/fboss/bgp:bgp_config_oss-cpp2-types", "//thrift/lib/cpp/transport:transport-core", diff --git a/fboss/cli/fboss2/test/integration_test/ConfigInterfaceProfileTest.cpp b/fboss/cli/fboss2/test/integration_test/ConfigInterfaceProfileTest.cpp index 327e4c61606..60469398c26 100644 --- a/fboss/cli/fboss2/test/integration_test/ConfigInterfaceProfileTest.cpp +++ b/fboss/cli/fboss2/test/integration_test/ConfigInterfaceProfileTest.cpp @@ -41,7 +41,10 @@ #include "fboss/agent/platforms/common/PlatformMapping.h" #include "fboss/agent/types.h" #include "fboss/cli/fboss2/test/integration_test/Fboss2IntegrationTest.h" +#include "fboss/cli/fboss2/utils/CmdClientUtilsCommon.h" +#include "fboss/cli/fboss2/utils/HostInfo.h" #include "fboss/lib/config/PlatformConfigUtils.h" +#include "fboss/qsfp_service/if/gen-cpp2/QsfpService.h" using namespace facebook::fboss; @@ -159,6 +162,54 @@ class ConfigInterfaceProfileTest : public Fboss2IntegrationTest { return std::nullopt; } + // A present, self-controlling port + a profile it supports that its + // transceiver does not. A profile other than the running one that subsumes + // nothing is preferred, so committing it changes the port; the running + // profile (e.g. an OPTICAL profile on a passive copper cable) is the + // fallback. + std::optional findOpticsUnsupportedCandidate() const { + std::map> optics; + try { + HostInfo hostInfo("localhost"); + auto client = + utils::createClient>(hostInfo); + client->sync_getAllPortSupportedProfiles(optics, /*checkOptics=*/true); + } catch (const std::exception& ex) { + XLOG(WARN) << "qsfp_service unavailable: " << ex.what(); + return std::nullopt; + } + auto mapping = fetchPlatformMapping(); + auto present = fetchPresentPorts(); + auto groups = utility::getSubsidiaryPortIDs(mapping.getPlatformPorts()); + std::optional running; + for (const auto& [controlling, unused] : groups) { + auto cid = static_cast(controlling); + auto pit = present.find(cid); + auto oit = + pit == present.end() ? optics.end() : optics.find(pit->second.name); + if (oit == optics.end() || oit->second.empty()) { + continue; + } + const auto& entry = mapping.getPlatformPort(cid); + for (const auto& [profileId, unused2] : *entry.supportedProfiles()) { + if (std::find(oit->second.begin(), oit->second.end(), profileId) != + oit->second.end()) { + continue; + } + auto name = apache::thrift::util::enumNameSafe(profileId); + Candidate cand{pit->second.name, pit->second.profileId, name, {}}; + if (name == pit->second.profileId) { + if (!running) { + running = std::move(cand); + } + } else if (mapping.getSubsumedPorts(controlling, profileId).empty()) { + return cand; + } + } + } + return running; + } + // A present, self-controlling port + a supported profile (!= current) // that subsumes nothing. std::optional findNonSubsumingCandidate() const { @@ -298,6 +349,43 @@ TEST_F(ConfigInterfaceProfileTest, ChangeProfileWithoutSubsumingSucceeds) { XLOG(INFO) << "TEST PASSED"; } +// A platform-supported profile the installed optics do not support is accepted +// with a warning, and the agent applies it on commit. +TEST_F(ConfigInterfaceProfileTest, ProfileUnsupportedByOpticsWarns) { + auto cand = findOpticsUnsupportedCandidate(); + if (!cand) { + GTEST_SKIP() << "No present port with a supported profile its transceiver " + "does not support"; + } + XLOG(INFO) << "port=" << cand->portName << " " << cand->currentProfile + << " -> " << cand->targetProfile; + + auto result = setInterfaceProfile(cand->portName, cand->targetProfile); + ASSERT_EQ(result.exitCode, 0) << result.stderr; + EXPECT_THAT( + result.stdout, + ::testing::HasSubstr( + "Warning: profile '" + cand->targetProfile + + "' is not supported by the transceiver on port " + cand->portName)); + + auto after = + waitForPortRunningInfo(cand->portName, [&cand](const auto& info) { + return info.profileId == cand->targetProfile; + }); + EXPECT_EQ(after.profileId, cand->targetProfile); + + if (cand->targetProfile != cand->currentProfile) { + auto restore = setInterfaceProfile(cand->portName, cand->currentProfile); + EXPECT_EQ(restore.exitCode, 0) << restore.stderr; + auto restored = + waitForPortRunningInfo(cand->portName, [&cand](const auto& info) { + return info.profileId == cand->currentProfile; + }); + EXPECT_EQ(restored.profileId, cand->currentProfile); + } + XLOG(INFO) << "TEST PASSED"; +} + // Case 3: Changing a controlling port to a supported profile that subsumes a // currently-present port succeeds, and the subsumed port is removed from the // config (verified via the agent). diff --git a/fboss/lib/config/agent/PortConfigUtils.h b/fboss/lib/config/agent/PortConfigUtils.h index 0104c43fa6c..19222ad9499 100644 --- a/fboss/lib/config/agent/PortConfigUtils.h +++ b/fboss/lib/config/agent/PortConfigUtils.h @@ -153,7 +153,8 @@ struct PortProfileChangeResult { // Every requested profile must be supported by the platform mapping. A // non-empty entry in qsfpSupportedProfiles additionally constrains that port // to profiles supported by its transceiver; absent or empty entries fall back -// to platform-only validation. +// to platform-only validation. The constraint is opt-in: fboss2-dev does not +// pass it and reports a transceiver mismatch as a warning instead. PortProfileChangeResult applyPortProfileChanges( cfg::SwitchConfig& config, const PlatformMapping& platformMapping,