diff --git a/.gitignore b/.gitignore index 001db00e4b..a0c8c5ac82 100644 --- a/.gitignore +++ b/.gitignore @@ -77,7 +77,6 @@ tests/tests tests/mock_tests/tests_response_publisher tests/mock_tests/tests_fpmsyncd tests/mock_tests/tests_intfmgrd -tests/mock_tests/tests_teammgrd tests/mock_tests/tests_portsyncd diff --git a/cfgmgr/teammgr.cpp b/cfgmgr/teammgr.cpp index 36c9d134e1..40eca9d921 100644 --- a/cfgmgr/teammgr.cpp +++ b/cfgmgr/teammgr.cpp @@ -307,8 +307,6 @@ void TeamMgr::doLagTask(Consumer &consumer) { if (addLag(alias, min_links, fallback, fast_rate) == task_need_retry) { - // If LAG creation fails, we need to clean up any potentially orphaned teamd processes - removeLag(alias); it++; continue; } @@ -629,7 +627,7 @@ task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fal SWSS_LOG_INFO("Port channel %s teamd configuration: %s", alias.c_str(), conf.str().c_str()); - string warmstart_flag = WarmStart::isWarmStart() ? " -w -o" : " -r"; + string warmstart_flag = WarmStart::isWarmStart() ? " -w -o " : " -r "; cmd << TEAMD_CMD << warmstart_flag @@ -656,42 +654,9 @@ bool TeamMgr::removeLag(const string &alias) stringstream cmd; string res; - pid_t pid; - try - { - std::stringstream cmd; - cmd << "cat " << shellquote("/var/run/teamd/" + alias + ".pid"); - EXEC_WITH_ERROR_THROW(cmd.str(), res); - } - catch (const std::exception &e) - { - SWSS_LOG_NOTICE("Failed to remove non-existent port channel %s pid...", alias.c_str()); - return false; - } - - try - { - pid = static_cast(std::stoul(res, nullptr, 10)); - SWSS_LOG_INFO("Read port channel %s pid %d", alias.c_str(), pid); - } - catch (const std::exception &e) - { - SWSS_LOG_ERROR("Failed to read port channel %s pid: %s", alias.c_str(), e.what()); - return false; - } - - try - { - std::stringstream cmd; - cmd << "kill -TERM " << pid; - EXEC_WITH_ERROR_THROW(cmd.str(), res); - } - catch (const std::exception &e) - { - SWSS_LOG_ERROR("Failed to send SIGTERM to port channel %s pid %d: %s", alias.c_str(), pid, e.what()); - return false; - } + cmd << TEAMD_CMD << " -k -t " << shellquote(alias); + EXEC_WITH_ERROR_THROW(cmd.str(), res); SWSS_LOG_NOTICE("Stop port channel %s", alias.c_str()); diff --git a/tests/mock_tests/Makefile.am b/tests/mock_tests/Makefile.am index d62372c381..fd8982eae8 100644 --- a/tests/mock_tests/Makefile.am +++ b/tests/mock_tests/Makefile.am @@ -4,9 +4,9 @@ P4_ORCH_DIR = $(top_srcdir)/orchagent/p4orch CFLAGS_SAI = -I /usr/include/sai -TESTS = tests tests_intfmgrd tests_teammgrd tests_portsyncd tests_fpmsyncd tests_response_publisher +TESTS = tests tests_intfmgrd tests_portsyncd tests_fpmsyncd tests_response_publisher -noinst_PROGRAMS = tests tests_intfmgrd tests_teammgrd tests_portsyncd tests_fpmsyncd tests_response_publisher +noinst_PROGRAMS = tests tests_intfmgrd tests_portsyncd tests_fpmsyncd tests_response_publisher LDADD_SAI = -lsaimeta -lsaimetadata -lsaivs -lsairedis @@ -177,28 +177,6 @@ tests_intfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTE tests_intfmgrd_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis \ -lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread -lgmock -lgmock_main -## teammgrd unit tests - -tests_teammgrd_SOURCES = teammgrd/teammgr_ut.cpp \ - $(top_srcdir)/cfgmgr/teammgr.cpp \ - $(top_srcdir)/lib/subintf.cpp \ - $(top_srcdir)/lib/recorder.cpp \ - $(top_srcdir)/orchagent/orch.cpp \ - $(top_srcdir)/orchagent/request_parser.cpp \ - mock_orchagent_main.cpp \ - mock_dbconnector.cpp \ - mock_table.cpp \ - mock_hiredis.cpp \ - fake_response_publisher.cpp \ - mock_redisreply.cpp \ - common/mock_shell_command.cpp - -tests_teammgrd_INCLUDES = $(tests_INCLUDES) -I$(top_srcdir)/cfgmgr -I$(top_srcdir)/lib -tests_teammgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) -tests_teammgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(tests_teammgrd_INCLUDES) -tests_teammgrd_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis \ - -lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread -lgmock -lgmock_main - ## fpmsyncd unit tests tests_fpmsyncd_SOURCES = fpmsyncd/test_fpmlink.cpp \ diff --git a/tests/mock_tests/teammgrd/teammgr_ut.cpp b/tests/mock_tests/teammgrd/teammgr_ut.cpp deleted file mode 100644 index 32f064f552..0000000000 --- a/tests/mock_tests/teammgrd/teammgr_ut.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "gtest/gtest.h" -#include "../mock_table.h" -#include "teammgr.h" - -extern int (*callback)(const std::string &cmd, std::string &stdout); -extern std::vector 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 m_config_db; - std::shared_ptr m_app_db; - std::shared_ptr m_state_db; - std::vector cfg_lag_tables; - - virtual void SetUp() override - { - testing_db::reset(); - m_config_db = std::make_shared("CONFIG_DB", 0); - m_app_db = std::make_shared("APPL_DB", 0); - m_state_db = std::make_shared("STATE_DB", 0); - - swss::Table metadata_table = swss::Table(m_config_db.get(), CFG_DEVICE_METADATA_TABLE_NAME); - std::vector 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 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); - } -} \ No newline at end of file