Skip to content

Commit 317f43a

Browse files
EdenGriStormLiangMS
authored andcommitted
Fixed set admin_status for deleted subintf due to late notification (#2659)
* Fixed set admin_status for deleted subintf due to late notification
1 parent c949517 commit 317f43a

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

cfgmgr/intfmgr.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,24 @@ void IntfMgr::updateSubIntfAdminStatus(const string &alias, const string &admin)
491491
std::string IntfMgr::setHostSubIntfAdminStatus(const string &alias, const string &admin_status, const string &parent_admin_status)
492492
{
493493
stringstream cmd;
494-
string res;
494+
string res, cmd_str;
495495

496496
if (parent_admin_status == "up" || admin_status == "down")
497497
{
498498
SWSS_LOG_INFO("subintf %s admin_status: %s", alias.c_str(), admin_status.c_str());
499499
cmd << IP_CMD " link set " << shellquote(alias) << " " << shellquote(admin_status);
500-
EXEC_WITH_ERROR_THROW(cmd.str(), res);
500+
cmd_str = cmd.str();
501+
int ret = swss::exec(cmd_str, res);
502+
if (ret && !isIntfStateOk(alias))
503+
{
504+
// Can happen when a DEL notification is sent by portmgrd immediately followed by a new SET notification
505+
SWSS_LOG_WARN("Setting admin_status to %s netdev failed with cmd:%s, rc:%d, error:%s",
506+
alias.c_str(), cmd_str.c_str(), ret, res.c_str());
507+
}
508+
else if (ret)
509+
{
510+
throw runtime_error(cmd_str + " : " + res);
511+
}
501512
return admin_status;
502513
}
503514
else

tests/mock_tests/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ tests_portsyncd_LDADD = $(LDADD_GTEST) -lnl-genl-3 -lhiredis -lhiredis \
155155

156156
## intfmgrd unit tests
157157

158-
tests_intfmgrd_SOURCES = intfmgrd/add_ipv6_prefix_ut.cpp \
158+
tests_intfmgrd_SOURCES = intfmgrd/intfmgr_ut.cpp \
159159
$(top_srcdir)/cfgmgr/intfmgr.cpp \
160160
$(top_srcdir)/lib/subintf.cpp \
161161
$(top_srcdir)/orchagent/orch.cpp \

tests/mock_tests/intfmgrd/add_ipv6_prefix_ut.cpp renamed to tests/mock_tests/intfmgrd/intfmgr_ut.cpp

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "gtest/gtest.h"
22
#include <iostream>
3-
#include <fstream>
3+
#include <fstream>
44
#include <unistd.h>
55
#include <sys/stat.h>
66
#include "../mock_table.h"
@@ -20,29 +20,32 @@ int cb(const std::string &cmd, std::string &stdout){
2020
else if (cmd.find("/sbin/ip -6 address \"add\"") == 0) {
2121
return Ethernet0IPv6Set ? 0 : 2;
2222
}
23+
else if (cmd == "/sbin/ip link set \"Ethernet64.10\" \"up\""){
24+
return 1;
25+
}
2326
else {
2427
return 0;
2528
}
2629
return 0;
2730
}
2831

2932
// Test Fixture
30-
namespace add_ipv6_prefix_ut
33+
namespace intfmgr_ut
3134
{
3235
struct IntfMgrTest : public ::testing::Test
3336
{
3437
std::shared_ptr<swss::DBConnector> m_config_db;
3538
std::shared_ptr<swss::DBConnector> m_app_db;
3639
std::shared_ptr<swss::DBConnector> m_state_db;
3740
std::vector<std::string> cfg_intf_tables;
38-
41+
3942
virtual void SetUp() override
40-
{
43+
{
4144
testing_db::reset();
4245
m_config_db = std::make_shared<swss::DBConnector>("CONFIG_DB", 0);
4346
m_app_db = std::make_shared<swss::DBConnector>("APPL_DB", 0);
4447
m_state_db = std::make_shared<swss::DBConnector>("STATE_DB", 0);
45-
48+
4649
swss::WarmStart::initialize("intfmgrd", "swss");
4750

4851
std::vector<std::string> tables = {
@@ -106,4 +109,22 @@ namespace add_ipv6_prefix_ut
106109
}
107110
ASSERT_EQ(ip_cmd_called, 1);
108111
}
112+
113+
//This test except no runtime error when the set admin status command failed
114+
//and the subinterface has not ok status (for example not existing subinterface)
115+
TEST_F(IntfMgrTest, testSetAdminStatusFailToNotOkSubInt){
116+
swss::IntfMgr intfmgr(m_config_db.get(), m_app_db.get(), m_state_db.get(), cfg_intf_tables);
117+
intfmgr.setHostSubIntfAdminStatus("Ethernet64.10", "up", "up");
118+
}
119+
120+
//This test except runtime error when the set admin status command failed
121+
//and the subinterface has ok status
122+
TEST_F(IntfMgrTest, testSetAdminStatusFailToOkSubInt){
123+
swss::IntfMgr intfmgr(m_config_db.get(), m_app_db.get(), m_state_db.get(), cfg_intf_tables);
124+
/* Set portStateTable */
125+
std::vector<swss::FieldValueTuple> values;
126+
values.emplace_back("state", "ok");
127+
intfmgr.m_statePortTable.set("Ethernet64.10", values, "SET", "");
128+
EXPECT_THROW(intfmgr.setHostSubIntfAdminStatus("Ethernet64.10", "up", "up"), std::runtime_error);
129+
}
109130
}

0 commit comments

Comments
 (0)