diff --git a/fboss/agent/AgentPreStartExec.cpp b/fboss/agent/AgentPreStartExec.cpp index fadbb81a99a74..ca68a849ef638 100644 --- a/fboss/agent/AgentPreStartExec.cpp +++ b/fboss/agent/AgentPreStartExec.cpp @@ -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() { @@ -24,7 +27,9 @@ void AgentPreStartExec::run() { std::make_unique(), dirUtil, std::move(config), - cppWedgeAgentWrapper); + cppWedgeAgentWrapper, + FLAGS_netos, + FLAGS_switch_index); } void AgentPreStartExec::run( @@ -32,14 +37,21 @@ void AgentPreStartExec::run( std::unique_ptr whoami, const AgentDirectoryUtil& dirUtil, std::unique_ptr 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) { diff --git a/fboss/agent/AgentPreStartExec.h b/fboss/agent/AgentPreStartExec.h index 24e35f0e9e262..b58e1ad02e386 100644 --- a/fboss/agent/AgentPreStartExec.h +++ b/fboss/agent/AgentPreStartExec.h @@ -20,7 +20,9 @@ class AgentPreStartExec { std::unique_ptr whoami, const AgentDirectoryUtil& dirUtil, std::unique_ptr config, - bool cppWedgeAgentWrapper); + bool cppWedgeAgentWrapper, + bool isNetOS, + int switchIndex); }; } // namespace facebook::fboss diff --git a/fboss/agent/test/AgentPreStartExecTests.cpp b/fboss/agent/test/AgentPreStartExecTests.cpp index 7acb1cbc55d90..fd9da260cb2d8 100644 --- a/fboss/agent/test/AgentPreStartExecTests.cpp +++ b/fboss/agent/test/AgentPreStartExecTests.cpp @@ -21,32 +21,49 @@ using ::testing::_; namespace facebook::fboss { namespace { -template +template 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 {}; - -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 {}; + +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 @@ -150,72 +167,82 @@ class AgentPreStartExecTests : public ::testing::Test { std::vector 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{ - "/usr/bin/systemctl", - "enable", - util_->getSwAgentServicePath()}, - true)); - EXPECT_CALL( - executor, - runCommand( - std::vector{ - "/usr/bin/systemctl", - "enable", - util_->getHwAgentServiceInstance(0)}, - true)); - - EXPECT_CALL( - executor, - runCommand( - std::vector{ - "/usr/bin/systemctl", - "enable", - util_->getHwAgentServiceInstance(1)}, - true)); - } else { - EXPECT_CALL( - executor, - runCommand( - std::vector{ - "/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{ + "/usr/bin/systemctl", + "enable", + util_->getSwAgentServicePath()}, + true)); + EXPECT_CALL( + executor, + runCommand( + std::vector{ + "/usr/bin/systemctl", + "enable", + util_->getHwAgentServiceInstance(0)}, + true)); - EXPECT_CALL( - executor, - runCommand( - std::vector{ - "/usr/bin/systemctl", - "disable", - "fboss_hw_agent@0.service"}, - false)); + EXPECT_CALL( + executor, + runCommand( + std::vector{ + "/usr/bin/systemctl", + "enable", + util_->getHwAgentServiceInstance(1)}, + true)); + } else { + EXPECT_CALL( + executor, + runCommand( + std::vector{ + "/usr/bin/systemctl", "disable", "fboss_sw_agent"}, + false)); - if (TestAttr::kMultiSwitch) { EXPECT_CALL( executor, runCommand( std::vector{ "/usr/bin/systemctl", "disable", - "fboss_hw_agent@1.service"}, + "fboss_hw_agent@0.service"}, false)); + + if (TestAttr::kMultiSwitch) { + EXPECT_CALL( + executor, + runCommand( + std::vector{ + "/usr/bin/systemctl", + "disable", + "fboss_hw_agent@1.service"}, + 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( @@ -223,7 +250,9 @@ class AgentPreStartExecTests : public ::testing::Test { std::move(netwhoami), *util_, std::make_unique(getConfig()), - TestAttr::kCppRefactor); + TestAttr::kCppRefactor, + TestAttr::kNetOS, + 0); if (TestAttr::kCppRefactor) { auto verifySymLink = [&](const std::string& name, @@ -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(); @@ -289,7 +328,9 @@ class AgentPreStartExecTests : public ::testing::Test { std::move(netwhoami), *util_, std::make_unique(getConfig()), - TestAttr::kCppRefactor), + TestAttr::kCppRefactor, + TestAttr::kNetOS, + 0), FbossError); } else { exec.run( @@ -297,7 +338,9 @@ class AgentPreStartExecTests : public ::testing::Test { std::move(netwhoami), *util_, std::make_unique(getConfig()), - TestAttr::kCppRefactor); + TestAttr::kCppRefactor, + TestAttr::kNetOS, + 0); } } @@ -443,6 +486,10 @@ TestFixtureName(MultiSwitchCppRefactorNoSaiBrcm); TestFixtureName(MultiSwitchCppRefactorSaiBrcm); TestFixtureName(MultiSwitchCppRefactorSaiNoBrcm); +TestFixtureName(MultiSwitchCppRefactorNetOsNoSaiBrcm); +TestFixtureName(MultiSwitchCppRefactorNetOsSaiBrcm); +TestFixtureName(MultiSwitchCppRefactorNetOsSaiNoBrcm); + TestFixtureNameFdsw(NoMultiSwitchCppRefactorSaiBrcm); TestFixtureNameFdsw(NoMultiSwitchCppRefactorNoSaiBrcm); TestFixtureNameFdsw(NoMultiSwitchCppRefactorSaiNoBrcm);