Skip to content
Closed
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
28 changes: 27 additions & 1 deletion cmake/CliFboss2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ add_library(fboss2_lib
fboss/cli/fboss2/commands/stop/pcap/CmdStopPcap.h
fboss/cli/fboss2/CmdSubcommands.cpp
fboss/cli/fboss2/oss/CmdGlobalOptions.cpp
fboss/cli/fboss2/oss/CmdList.cpp
fboss/cli/fboss2/utils/CmdUtils.cpp
fboss/cli/fboss2/utils/CLIParserUtils.cpp
fboss/cli/fboss2/utils/CmdClientUtils.cpp
Expand Down Expand Up @@ -559,6 +558,7 @@ target_link_libraries(fboss2_lib

add_executable(fboss2
fboss/cli/fboss2/Main.cpp
fboss/cli/fboss2/oss/CmdList.cpp
)

target_link_libraries(fboss2
Expand All @@ -567,3 +567,29 @@ target_link_libraries(fboss2
)

install(TARGETS fboss2)

# Config commands library for fboss2-dev
add_library(fboss2_config_lib
fboss/cli/fboss2/commands/config/CmdConfigReload.h
fboss/cli/fboss2/commands/config/CmdConfigReload.cpp
fboss/cli/fboss2/CmdListConfig.cpp
fboss/cli/fboss2/CmdHandlerImplConfig.cpp
)

target_link_libraries(fboss2_config_lib
fboss2_lib
agent_dir_util
)

add_executable(fboss2-dev
fboss/cli/fboss2/Main.cpp
fboss/cli/fboss2/oss/CmdListConfig.cpp
)

target_link_libraries(fboss2-dev
fboss2_config_lib
fboss2_lib
Folly::folly
)

install(TARGETS fboss2-dev)
2 changes: 2 additions & 0 deletions cmake/CliFboss2Test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# cmd_test - Command tests from BUCK file
add_executable(fboss2_cmd_test
fboss/cli/fboss2/test/TestMain.cpp
fboss/cli/fboss2/test/CmdConfigReloadTest.cpp
fboss/cli/fboss2/test/CmdSetPortStateTest.cpp
fboss/cli/fboss2/test/CmdShowAclTest.cpp
fboss/cli/fboss2/test/CmdShowAgentSslTest.cpp
Expand Down Expand Up @@ -39,6 +40,7 @@ add_executable(fboss2_cmd_test

target_link_libraries(fboss2_cmd_test
fboss2_lib
fboss2_config_lib
${GTEST}
${LIBGMOCK_LIBRARIES}
Folly::folly
Expand Down
40 changes: 40 additions & 0 deletions fboss/cli/fboss2/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,46 @@ auto_tab_complete(
src = ":fboss2",
)

# Config commands are in a separate library/binary for now.
cpp_library(
name = "fboss2-config-lib",
srcs = [
"CmdHandlerImplConfig.cpp",
"CmdListConfig.cpp",
"commands/config/CmdConfigReload.cpp",
],
headers = [
"commands/config/CmdConfigReload.h",
],
exported_deps = [
":cmd-handler",
":cmd-list-header",
":fboss2-lib",
"//fboss/agent:agent_dir_util",
],
)

cpp_binary(
name = "fboss2-dev",
srcs = [
"Main.cpp",
"oss/CmdListConfig.cpp",
],
deps = [
":cmd-common-utils",
":cmd-global-options",
":cmd-subcommands",
":fboss2-config-lib",
":fboss2-lib", # @manual
"//folly/init:init",
"//folly/logging:init",
"//folly/logging:logging",
],
external_deps = [
"CLI11",
],
)

cpp_binary(
name = "fboss2-routing-protocol",
srcs = [
Expand Down
19 changes: 19 additions & 0 deletions fboss/cli/fboss2/CmdHandlerImplConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* 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 "fboss/cli/fboss2/CmdHandler.cpp"

#include "fboss/cli/fboss2/commands/config/CmdConfigReload.h"

namespace facebook::fboss {

template void CmdHandler<CmdConfigReload, CmdConfigReloadTraits>::run();

} // namespace facebook::fboss
30 changes: 30 additions & 0 deletions fboss/cli/fboss2/CmdListConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* 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 "fboss/cli/fboss2/CmdList.h"

#include "fboss/cli/fboss2/CmdHandler.h"
#include "fboss/cli/fboss2/commands/config/CmdConfigReload.h"

namespace facebook::fboss {

const CommandTree& kConfigCommandTree() {
static CommandTree root = {
{"config",
"reload",
"Reload agent configuration",
commandHandler<CmdConfigReload>,
argTypeHandler<CmdConfigReloadTraits>},
};
sort(root.begin(), root.end());
return root;
}

} // namespace facebook::fboss
2 changes: 2 additions & 0 deletions fboss/cli/fboss2/CmdSubcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const std::map<std::string, std::string>& kSupportedVerbs() {
{"stop", "Stop event"},
{"get", "Get object"},
{"reload", "Reload object"},
// Only implemented in fboss2-dev for now.
{"config", "Configuration commands"},
};

return supportedVerbs;
Expand Down
32 changes: 32 additions & 0 deletions fboss/cli/fboss2/commands/config/CmdConfigReload.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* 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 "fboss/cli/fboss2/commands/config/CmdConfigReload.h"

namespace facebook::fboss {

CmdConfigReloadTraits::RetType CmdConfigReload::queryClient(
const HostInfo& hostInfo) {
auto client =
utils::createClient<facebook::fboss::FbossCtrlAsyncClient>(hostInfo);

Comment on lines +17 to +19
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now this config can only reload agent config.
But eventually if we need to reload qsfp/platform/bgp configs in the future,
we might have to support an option to reload specific service config.

For now, I'm okay to land this but please allow flexibility to load specific config in your future diff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah we can easily add a subcommand later that specifies what agent to reload specifically.

try {
client->sync_reloadConfig();
return "Config reloaded successfully";
} catch (const std::exception& ex) {
return "Failed to reload config: " + std::string(ex.what());
}
}

void CmdConfigReload::printOutput(const RetType& logMsg) {
std::cout << logMsg << std::endl;
}

} // namespace facebook::fboss
39 changes: 39 additions & 0 deletions fboss/cli/fboss2/commands/config/CmdConfigReload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* 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.
*
*/

#pragma once

#include <folly/Conv.h>
#include <iostream>
#include "fboss/cli/fboss2/CmdHandler.h"
#include "fboss/cli/fboss2/utils/CmdClientUtils.h"
#include "fboss/cli/fboss2/utils/CmdUtils.h"

namespace facebook::fboss {

struct CmdConfigReloadTraits : public WriteCommandTraits {
static constexpr utils::ObjectArgTypeId ObjectArgTypeId =
utils::ObjectArgTypeId::OBJECT_ARG_TYPE_ID_NONE;
using ObjectArgType = std::monostate;
using RetType = std::string;
};

class CmdConfigReload
: public CmdHandler<CmdConfigReload, CmdConfigReloadTraits> {
public:
using ObjectArgType = CmdConfigReloadTraits::ObjectArgType;
using RetType = CmdConfigReloadTraits::RetType;

RetType queryClient(const HostInfo& hostInfo);

void printOutput(const RetType& logMsg);
};

} // namespace facebook::fboss
27 changes: 27 additions & 0 deletions fboss/cli/fboss2/oss/CmdListConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* 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 "fboss/cli/fboss2/CmdList.h"

namespace facebook::fboss {

// Defined in CmdListConfig.cpp
const CommandTree& kConfigCommandTree();

const CommandTree& kAdditionalCommandTree() {
return kConfigCommandTree();
}

const std::vector<Command>& kSpecialCommands() {
static const std::vector<Command> cmds = {};
return cmds;
}

} // namespace facebook::fboss
1 change: 1 addition & 0 deletions fboss/cli/fboss2/test/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ cpp_unittest(
cpp_unittest(
name = "cmd_test",
srcs = [
"CmdConfigReloadTest.cpp",
"CmdGetPcapTest.cpp",
"CmdSetPortStateTest.cpp",
"CmdShowAclTest.cpp",
Expand Down
56 changes: 56 additions & 0 deletions fboss/cli/fboss2/test/CmdConfigReloadTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// (c) Facebook, Inc. and its affiliates. Confidential and proprietary.

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

#include "fboss/cli/fboss2/commands/config/CmdConfigReload.h"

using namespace ::testing;

namespace facebook::fboss {

class CmdConfigReloadTestFixture : public ::testing::Test {
public:
void SetUp() override {}
};

TEST_F(CmdConfigReloadTestFixture, printOutput) {
auto cmd = CmdConfigReload();
std::string successMessage = "Config reloaded successfully";

// Redirect cout to capture output
std::stringstream buffer;
std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());

cmd.printOutput(successMessage);

// Restore cout
std::cout.rdbuf(old);

std::string output = buffer.str();
std::string expectedOutput = "Config reloaded successfully\n";

EXPECT_EQ(output, expectedOutput);
}

TEST_F(CmdConfigReloadTestFixture, printOutputCustomMessage) {
auto cmd = CmdConfigReload();
std::string customMessage = "Custom test message";

// Redirect cout to capture output
std::stringstream buffer;
std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());

cmd.printOutput(customMessage);

// Restore cout
std::cout.rdbuf(old);

std::string output = buffer.str();
std::string expectedOutput = "Custom test message\n";

EXPECT_EQ(output, expectedOutput);
}

} // namespace facebook::fboss
Loading