Skip to content

Commit

Permalink
Update Pre Agent Executor for NetOS Native
Browse files Browse the repository at this point in the history
Summary:
Updating Pre Agent Executor To run correctly in the NetOS Environment.

1. Created a separate runNetOS for startup
- Removed all systemd references since the systemd units defined in the netOS container environment handles this.
- Temporarily Removed FBOSS Update Build Info since there is no plans on it. Task: T198905811

2. Added Command Line Args for ``--netos`` and ``--switch_index <int32>``` respectively
- both these need to be passed to run the new runNetOs flow.
- Only hw_agent_0 would ever run this and the hw_agent_1 would be no-op in this case and be skipped

Assumptions:
in NetOS: cpp_agent_wrapper and multi_switch are always enabled

Reviewed By: peygar

Differential Revision: D60749563

fbshipit-source-id: 31c7b09ea35a1bdd60126ca7a9a5a02821c359c7
  • Loading branch information
Kevin Malhotra authored and facebook-github-bot committed Aug 21, 2024
1 parent 009fd92 commit d12f0e4
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 83 deletions.
18 changes: 15 additions & 3 deletions fboss/agent/AgentPreStartExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

#include "fboss/agent/facebook/AgentPreStartConfig.h"

DEFINE_bool(netos, false, "Execute netos native environment");
DEFINE_int32(switch_index, 0, "Applicable for hardware agent, switch index");

namespace facebook::fboss {

void AgentPreStartExec::run() {
Expand All @@ -24,22 +27,31 @@ void AgentPreStartExec::run() {
std::make_unique<AgentNetWhoAmI>(),
dirUtil,
std::move(config),
cppWedgeAgentWrapper);
cppWedgeAgentWrapper,
FLAGS_netos,
FLAGS_switch_index);
}

void AgentPreStartExec::run(
AgentCommandExecutor* executor,
std::unique_ptr<AgentNetWhoAmI> whoami,
const AgentDirectoryUtil& dirUtil,
std::unique_ptr<AgentConfig> config,
bool cppWedgeAgentWrapper) {
bool cppWedgeAgentWrapper,
bool isNetOS,
int switchIndex) {
auto mode = config->getRunMode();

if (cppWedgeAgentWrapper) {
runAndRemoveScript(dirUtil.getPreStartShellScript());
AgentPreStartConfig preStartConfig(
std::move(whoami), config.get(), dirUtil);
preStartConfig.run(executor);
if (isNetOS && switchIndex == 0) {
// Only First Agent will execute Pre_Start
preStartConfig.runNetOs(executor);
} else if (!isNetOS) {
preStartConfig.run(executor);
}
}

if (mode != cfg::AgentRunMode::MULTI_SWITCH) {
Expand Down
4 changes: 3 additions & 1 deletion fboss/agent/AgentPreStartExec.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class AgentPreStartExec {
std::unique_ptr<AgentNetWhoAmI> whoami,
const AgentDirectoryUtil& dirUtil,
std::unique_ptr<AgentConfig> config,
bool cppWedgeAgentWrapper);
bool cppWedgeAgentWrapper,
bool isNetOS,
int switchIndex);
};

} // namespace facebook::fboss
205 changes: 126 additions & 79 deletions fboss/agent/test/AgentPreStartExecTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,49 @@ using ::testing::_;
namespace facebook::fboss {

namespace {
template <bool multiSwitch, bool cppRefactor, bool sai, bool brcm>
template <bool multiSwitch, bool cppRefactor, bool sai, bool brcm, bool netOS>
struct TestAttr {
static constexpr bool kMultiSwitch = multiSwitch;
static constexpr bool kCppRefactor = cppRefactor;
static constexpr bool kSai = sai;
static constexpr bool kBrcm = brcm;
static constexpr bool kNetOS = netOS;
};

#define TEST_ATTR(NAME, a, b, c, d) \
struct TestAttr##NAME : public TestAttr<a, b, c, d> {};

TEST_ATTR(NoMultiSwitchNoCppRefactorNoSaiBrcm, false, false, false, true);
TEST_ATTR(NoMultiSwitchNoCppRefactorSaiBrcm, false, false, true, true);
TEST_ATTR(NoMultiSwitchNoCppRefactorSaiNoBrcm, false, false, true, false);

TEST_ATTR(NoMultiSwitchCppRefactorNoSaiBrcm, false, true, false, true);
TEST_ATTR(NoMultiSwitchCppRefactorSaiBrcm, false, true, true, true);
TEST_ATTR(NoMultiSwitchCppRefactorSaiNoBrcm, false, true, true, false);

TEST_ATTR(MultiSwitchNoCppRefactorNoSaiBrcm, true, false, false, true);
TEST_ATTR(MultiSwitchNoCppRefactorSaiBrcm, true, false, true, true);
TEST_ATTR(MultiSwitchNoCppRefactorSaiNoBrcm, true, false, true, false);

TEST_ATTR(MultiSwitchCppRefactorNoSaiBrcm, true, true, false, true);
TEST_ATTR(MultiSwitchCppRefactorSaiBrcm, true, true, true, true);
TEST_ATTR(MultiSwitchCppRefactorSaiNoBrcm, true, true, true, false);
#define TEST_ATTR(NAME, a, b, c, d, e) \
struct TestAttr##NAME : public TestAttr<a, b, c, d, e> {};

TEST_ATTR(
NoMultiSwitchNoCppRefactorNoSaiBrcm,
false,
false,
false,
true,
false);
TEST_ATTR(NoMultiSwitchNoCppRefactorSaiBrcm, false, false, true, true, false);
TEST_ATTR(
NoMultiSwitchNoCppRefactorSaiNoBrcm,
false,
false,
true,
false,
false);

TEST_ATTR(NoMultiSwitchCppRefactorNoSaiBrcm, false, true, false, true, false);
TEST_ATTR(NoMultiSwitchCppRefactorSaiBrcm, false, true, true, true, false);
TEST_ATTR(NoMultiSwitchCppRefactorSaiNoBrcm, false, true, true, false, false);

TEST_ATTR(MultiSwitchNoCppRefactorNoSaiBrcm, true, false, false, true, false);
TEST_ATTR(MultiSwitchNoCppRefactorSaiBrcm, true, false, true, true, false);
TEST_ATTR(MultiSwitchNoCppRefactorSaiNoBrcm, true, false, true, false, false);

TEST_ATTR(MultiSwitchCppRefactorNoSaiBrcm, true, true, false, true, false);
TEST_ATTR(MultiSwitchCppRefactorSaiBrcm, true, true, true, true, false);
TEST_ATTR(MultiSwitchCppRefactorSaiNoBrcm, true, true, true, false, false);

TEST_ATTR(MultiSwitchCppRefactorNetOsNoSaiBrcm, true, true, false, true, true);
TEST_ATTR(MultiSwitchCppRefactorNetOsSaiBrcm, true, true, true, true, true);
TEST_ATTR(MultiSwitchCppRefactorNetOsSaiNoBrcm, true, true, true, false, true);
} // namespace

template <typename TestAttr>
Expand Down Expand Up @@ -150,80 +167,92 @@ class AgentPreStartExecTests : public ::testing::Test {
std::vector<std::string> installKmod{
kmodsInstaller, "install", "--sdk-upgrade", kmodVersion};
EXPECT_CALL(executor, runCommand(installKmod, true)).Times(1);
EXPECT_CALL(*netwhoami, isBcmSaiPlatform())
.WillOnce(Return(TestAttr::kSai && TestAttr::kBrcm));
if (!TestAttr::kNetOS) {
// wedge agent binaries not included in netOS
EXPECT_CALL(*netwhoami, isBcmSaiPlatform())
.WillOnce(Return(TestAttr::kSai && TestAttr::kBrcm));
}
if (TestAttr::kMultiSwitch) {
// once again for hw agent
EXPECT_CALL(*netwhoami, isBcmSaiPlatform())
.WillOnce(Return(TestAttr::kSai && TestAttr::kBrcm));
}
EXPECT_CALL(*netwhoami, isBcmVoqPlatform()).WillOnce(Return(voq));
if (TestAttr::kMultiSwitch) {
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"enable",
util_->getSwAgentServicePath()},
true));
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"enable",
util_->getHwAgentServiceInstance(0)},
true));

EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"enable",
util_->getHwAgentServiceInstance(1)},
true));
} else {
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl", "disable", "fboss_sw_agent"},
false));
if (voq) {
EXPECT_CALL(*netwhoami, isBcmSaiPlatform())
.WillOnce(Return(TestAttr::kSai && TestAttr::kBrcm));
}
if (!TestAttr::kNetOS) {
if (TestAttr::kMultiSwitch) {
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"enable",
util_->getSwAgentServicePath()},
true));
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"enable",
util_->getHwAgentServiceInstance(0)},
true));

EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"disable",
"[email protected]"},
false));
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"enable",
util_->getHwAgentServiceInstance(1)},
true));
} else {
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl", "disable", "fboss_sw_agent"},
false));

if (TestAttr::kMultiSwitch) {
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"disable",
"fboss_hw_agent@1.service"},
"fboss_hw_agent@0.service"},
false));

if (TestAttr::kMultiSwitch) {
EXPECT_CALL(
executor,
runCommand(
std::vector<std::string>{
"/usr/bin/systemctl",
"disable",
"[email protected]"},
false));
}
}

// update-buildinfo
EXPECT_CALL(
executor, runShellCommand("/usr/local/bin/fboss-build-info", false))
.Times(1);
}
// update-buildinfo
EXPECT_CALL(
executor, runShellCommand("/usr/local/bin/fboss-build-info", false))
.Times(1);
}

exec.run(
&executor,
std::move(netwhoami),
*util_,
std::make_unique<AgentConfig>(getConfig()),
TestAttr::kCppRefactor);
TestAttr::kCppRefactor,
TestAttr::kNetOS,
0);

if (TestAttr::kCppRefactor) {
auto verifySymLink = [&](const std::string& name,
Expand All @@ -234,14 +263,24 @@ class AgentPreStartExecTests : public ::testing::Test {
util_->getPackageDirectory() + "/" + sdk + "/" + name;
EXPECT_EQ(actualTarget.string(), expectedTarget);
};
verifySymLink(
"wedge_agent",
// sai + brcm has directories with sai sdk version
// non-sai + brcm and non-brcm has directories with asic sdk version
TestAttr::kSai && TestAttr::kBrcm
? getSaiSdkVersion(getSdkVersion())
: getAsicSdkVersion(getSdkVersion()));

if (!TestAttr::kNetOS) {
verifySymLink(
"wedge_agent",
// sai + brcm has directories with sai sdk version
// non-sai + brcm and non-brcm has directories with asic sdk version
TestAttr::kSai && TestAttr::kBrcm
? getSaiSdkVersion(getSdkVersion())
: getAsicSdkVersion(getSdkVersion()));
}
if (TestAttr::kMultiSwitch) {
verifySymLink(
"fboss_hw_agent",
// sai + brcm has directories with sai sdk version
// non-sai + brcm and non-brcm has directories with asic sdk version
TestAttr::kSai && TestAttr::kBrcm
? getSaiSdkVersion(getSdkVersion())
: getAsicSdkVersion(getSdkVersion()));
}
if (coldBoot) {
EXPECT_TRUE(checkFileExists(util_->getSwColdBootOnceFile()));
auto cfg = getConfig();
Expand Down Expand Up @@ -289,15 +328,19 @@ class AgentPreStartExecTests : public ::testing::Test {
std::move(netwhoami),
*util_,
std::make_unique<AgentConfig>(getConfig()),
TestAttr::kCppRefactor),
TestAttr::kCppRefactor,
TestAttr::kNetOS,
0),
FbossError);
} else {
exec.run(
&executor,
std::move(netwhoami),
*util_,
std::make_unique<AgentConfig>(getConfig()),
TestAttr::kCppRefactor);
TestAttr::kCppRefactor,
TestAttr::kNetOS,
0);
}
}

Expand Down Expand Up @@ -443,6 +486,10 @@ TestFixtureName(MultiSwitchCppRefactorNoSaiBrcm);
TestFixtureName(MultiSwitchCppRefactorSaiBrcm);
TestFixtureName(MultiSwitchCppRefactorSaiNoBrcm);

TestFixtureName(MultiSwitchCppRefactorNetOsNoSaiBrcm);
TestFixtureName(MultiSwitchCppRefactorNetOsSaiBrcm);
TestFixtureName(MultiSwitchCppRefactorNetOsSaiNoBrcm);

TestFixtureNameFdsw(NoMultiSwitchCppRefactorSaiBrcm);
TestFixtureNameFdsw(NoMultiSwitchCppRefactorNoSaiBrcm);
TestFixtureNameFdsw(NoMultiSwitchCppRefactorSaiNoBrcm);
Expand Down

0 comments on commit d12f0e4

Please sign in to comment.