Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/CliFboss2Test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ add_executable(fboss2_cmd_test
fboss/cli/fboss2/test/CmdShowBgpStreamSummaryTest.cpp
fboss/cli/fboss2/test/CmdShowBgpSummaryEgressTest.cpp
fboss/cli/fboss2/test/CmdShowBgpSummaryTest.cpp
fboss/cli/fboss2/test/CmdShowBgpVersionTest.cpp
fboss/cli/fboss2/test/CmdShowBgpTableCommunityTest.cpp
fboss/cli/fboss2/test/CmdShowBgpTableDetailTest.cpp
fboss/cli/fboss2/test/CmdShowBgpTableMoreSpecificsTest.cpp
Expand Down
18 changes: 13 additions & 5 deletions fboss/cli/fboss2/commands/show/bgp/CmdShowVersionBgp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "fboss/cli/fboss2/utils/CmdClientUtilsCommon.h" // NOLINT(misc-include-cleaner)
#include "fboss/cli/fboss2/utils/HostInfo.h"
#include "neteng/fboss/bgp/if/gen-cpp2/TBgpService.h" // NOLINT(misc-include-cleaner)
#include "thrift/lib/cpp/TApplicationException.h"

namespace facebook::fboss {

Expand All @@ -27,11 +28,18 @@ CmdShowVersionBgp::RetType CmdShowVersionBgp::queryClient(

client->sync_getRegexExportedValues(retVal, "build_.*");
#else
// OSS: getRegexExportedValues method not available in TBgpService
// This command requires Meta-internal fb303 extensions
throw std::runtime_error(
"BGP version command not supported in OSS build - "
"getRegexExportedValues method not available");
auto client = utils::createClient<apache::thrift::Client<
facebook::neteng::fboss::bgp::thrift::TBgpService>>(hostInfo);
try {
client->sync_getBuildInfo(retVal);
} catch (const apache::thrift::TApplicationException& ex) {
if (ex.getType() != apache::thrift::TApplicationException::UNKNOWN_METHOD) {
throw;
}
throw std::runtime_error(
"The running BGP daemon does not support getBuildInfo; upgrade the "
"BGP package and restart the service before using this command");
}
#endif

return retVal;
Expand Down
51 changes: 51 additions & 0 deletions fboss/cli/fboss2/test/CmdShowBgpVersionTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "fboss/cli/fboss2/commands/show/bgp/CmdShowVersionBgp.h"
#include "fboss/cli/fboss2/test/CmdHandlerTestBase.h"

using namespace ::testing;

namespace facebook::fboss {

class CmdShowBgpVersionTestFixture : public CmdHandlerTestBase {};

TEST_F(CmdShowBgpVersionTestFixture, QueryClientReturnsRunningBuildInfo) {
const CmdShowVersionBgp::RetType expected = {
{"build_package_name", "bgp"},
{"build_package_version", "0530bb98"},
{"build_revision", "0530bb98"},
};
setupMockedBgpServer();
EXPECT_CALL(getMockBgp(), getBuildInfo(_)).WillOnce(Invoke([&](auto& info) {
info = expected;
}));

EXPECT_EQ(CmdShowVersionBgp().queryClient(localhost()), expected);
}

TEST_F(CmdShowBgpVersionTestFixture, QueryClientRejectsOldDaemon) {
// Use a generated processor without getBuildInfo so Thrift emits the same
// UNKNOWN_METHOD response as a pre-API BGP daemon.
auto legacyBgpService = std::make_shared<MockFbossCtrlAgent>();
auto legacyBgpServer =
std::make_unique<apache::thrift::ScopedServerInterfaceThread>(
legacyBgpService, "::1", 0, createFastMockServerConfig());
CmdGlobalOptions::getInstance()->setBgpThriftPort(
legacyBgpServer->getAddress().getPort());

EXPECT_THROW(
CmdShowVersionBgp().queryClient(localhost()), std::runtime_error);
}

} // namespace facebook::fboss
1 change: 1 addition & 0 deletions fboss/cli/fboss2/test/bgp/MockBgpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using facebook::neteng::routing::policy::thrift::TPolicyStats;

class MockBgpClient : public apache::thrift::ServiceHandler<TBgpService> {
public:
MOCK_METHOD(void, getBuildInfo, ((std::map<std::string, std::string>&)));
MOCK_METHOD(void, getBgpSessions, (std::vector<TBgpSession>&));
MOCK_METHOD(void, getBgpLocalConfig, (TBgpLocalConfig&));
MOCK_METHOD(void, getDrainState, (TBgpDrainState&));
Expand Down
5 changes: 5 additions & 0 deletions neteng/fboss/bgp/if/bgp_thrift.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,11 @@ struct THealthReport {

// @lint-ignore THRIFTCHECKS facebook-service-deprecated existing service inheritance is out of scope for this API addition
service TBgpService extends fb303.FacebookService {
/**
* Return build metadata for the running BGP process.
*/
map<string, string> getBuildInfo();

/**
* [Logging]
*
Expand Down
Loading