-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2932) What I did 202205 cherry-pick for [teamd]: Clean teamd process if LAG creation fails #2888 During LAG creation, if the teamd process fails for any reason, cleanup any leftover teamd processes for the LAG alias Call kill directly in removeLag instead of using teamd -k Why I did it If the teamd process times out for any reason, subsequent attempts to create a LAG may fail if there is an orphaned process left running As detailed in Removal of LAG with no members takes around 1 sec on 202012 sonic-buildimage#8071, team -k may block for some time. Signed-off-by: Lawrence Lee <[email protected]>
- Loading branch information
1 parent
8b280d8
commit dc0e29b
Showing
5 changed files
with
154 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,15 +1,25 @@ | ||
#include <string> | ||
#include <vector> | ||
|
||
/* Override this pointer for custom behavior */ | ||
int (*callback)(const std::string &cmd, std::string &stdout) = nullptr; | ||
|
||
int mockCmdReturn = 0; | ||
std::string mockCmdStdcout = ""; | ||
std::vector<std::string> mockCallArgs; | ||
|
||
namespace swss { | ||
int exec(const std::string &cmd, std::string &stdout) | ||
{ | ||
mockCallArgs.push_back(cmd); | ||
stdout = mockCmdStdcout; | ||
return mockCmdReturn; | ||
if (callback != nullptr) | ||
{ | ||
return callback(cmd, stdout); | ||
} | ||
else | ||
{ | ||
mockCallArgs.push_back(cmd); | ||
stdout = mockCmdStdcout; | ||
return mockCmdReturn; | ||
} | ||
} | ||
} | ||
} |
This file contains 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,78 @@ | ||
#include "gtest/gtest.h" | ||
#include "../mock_table.h" | ||
#include "teammgr.h" | ||
|
||
extern int (*callback)(const std::string &cmd, std::string &stdout); | ||
extern std::vector<std::string> mockCallArgs; | ||
|
||
int cb(const std::string &cmd, std::string &stdout) | ||
{ | ||
mockCallArgs.push_back(cmd); | ||
if (cmd.find("/usr/bin/teamd -r -t PortChannel1") != std::string::npos) | ||
{ | ||
return 1; | ||
} | ||
else if (cmd.find("cat \"/var/run/teamd/PortChannel1.pid\"") != std::string::npos) | ||
{ | ||
stdout = "1234"; | ||
return 0; | ||
} | ||
return 0; | ||
} | ||
|
||
namespace teammgr_ut | ||
{ | ||
struct TeamMgrTest : public ::testing::Test | ||
{ | ||
std::shared_ptr<swss::DBConnector> m_config_db; | ||
std::shared_ptr<swss::DBConnector> m_app_db; | ||
std::shared_ptr<swss::DBConnector> m_state_db; | ||
std::vector<TableConnector> cfg_lag_tables; | ||
|
||
virtual void SetUp() override | ||
{ | ||
testing_db::reset(); | ||
m_config_db = std::make_shared<swss::DBConnector>("CONFIG_DB", 0); | ||
m_app_db = std::make_shared<swss::DBConnector>("APPL_DB", 0); | ||
m_state_db = std::make_shared<swss::DBConnector>("STATE_DB", 0); | ||
|
||
swss::Table metadata_table = swss::Table(m_config_db.get(), CFG_DEVICE_METADATA_TABLE_NAME); | ||
std::vector<swss::FieldValueTuple> vec; | ||
vec.emplace_back("mac", "01:23:45:67:89:ab"); | ||
metadata_table.set("localhost", vec); | ||
|
||
TableConnector conf_lag_table(m_config_db.get(), CFG_LAG_TABLE_NAME); | ||
TableConnector conf_lag_member_table(m_config_db.get(), CFG_LAG_MEMBER_TABLE_NAME); | ||
TableConnector state_port_table(m_state_db.get(), STATE_PORT_TABLE_NAME); | ||
|
||
std::vector<TableConnector> tables = { | ||
conf_lag_table, | ||
conf_lag_member_table, | ||
state_port_table | ||
}; | ||
|
||
cfg_lag_tables = tables; | ||
mockCallArgs.clear(); | ||
callback = cb; | ||
} | ||
}; | ||
|
||
TEST_F(TeamMgrTest, testProcessKilledAfterAddLagFailure) | ||
{ | ||
swss::TeamMgr teammgr(m_config_db.get(), m_app_db.get(), m_state_db.get(), cfg_lag_tables); | ||
swss::Table cfg_lag_table = swss::Table(m_config_db.get(), CFG_LAG_TABLE_NAME); | ||
cfg_lag_table.set("PortChannel1", { { "admin_status", "up" }, | ||
{ "mtu", "9100" }, | ||
{ "lacp_key", "auto" }, | ||
{ "min_links", "2" } }); | ||
teammgr.addExistingData(&cfg_lag_table); | ||
teammgr.doTask(); | ||
int kill_cmd_called = 0; | ||
for (auto cmd : mockCallArgs){ | ||
if (cmd.find("kill -TERM 1234") != std::string::npos){ | ||
kill_cmd_called++; | ||
} | ||
} | ||
ASSERT_EQ(kill_cmd_called, 1); | ||
} | ||
} |