-
Notifications
You must be signed in to change notification settings - Fork 372
[Nexthop][fboss2-dev] Add a simple fboss2 config reload command.
#753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
benoit-nexthop
wants to merge
1
commit into
facebook:main
from
nexthop-ai:fboss2-cli-prototype_part01
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.