@@ -23,27 +23,55 @@ PortMgr::PortMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
23
23
bool PortMgr::setPortMtu (const string &alias, const string &mtu)
24
24
{
25
25
stringstream cmd;
26
- string res;
26
+ string res, cmd_str ;
27
27
28
28
// ip link set dev <port_name> mtu <mtu>
29
29
cmd << IP_CMD << " link set dev " << shellquote (alias) << " mtu " << shellquote (mtu);
30
- EXEC_WITH_ERROR_THROW (cmd.str (), res);
31
-
32
- // Set the port MTU in application database to update both
33
- // the port MTU and possibly the port based router interface MTU
34
- return writeConfigToAppDb (alias, " mtu" , mtu);
30
+ cmd_str = cmd.str ();
31
+ int ret = swss::exec (cmd_str, res);
32
+ if (!ret)
33
+ {
34
+ // Set the port MTU in application database to update both
35
+ // the port MTU and possibly the port based router interface MTU
36
+ return writeConfigToAppDb (alias, " mtu" , mtu);
37
+ }
38
+ else if (!isPortStateOk (alias))
39
+ {
40
+ // Can happen when a DEL notification is sent by portmgrd immediately followed by a new SET notif
41
+ SWSS_LOG_WARN (" Setting mtu to alias:%s netdev failed with cmd:%s, rc:%d, error:%s" , alias.c_str (), cmd_str.c_str (), ret, res.c_str ());
42
+ return false ;
43
+ }
44
+ else
45
+ {
46
+ throw runtime_error (cmd_str + " : " + res);
47
+ }
48
+ return true ;
35
49
}
36
50
37
51
bool PortMgr::setPortAdminStatus (const string &alias, const bool up)
38
52
{
39
53
stringstream cmd;
40
- string res;
54
+ string res, cmd_str ;
41
55
42
56
// ip link set dev <port_name> [up|down]
43
57
cmd << IP_CMD << " link set dev " << shellquote (alias) << (up ? " up" : " down" );
44
- EXEC_WITH_ERROR_THROW (cmd.str (), res);
45
-
46
- return writeConfigToAppDb (alias, " admin_status" , (up ? " up" : " down" ));
58
+ cmd_str = cmd.str ();
59
+ int ret = swss::exec (cmd_str, res);
60
+ if (!ret)
61
+ {
62
+ return writeConfigToAppDb (alias, " admin_status" , (up ? " up" : " down" ));
63
+ }
64
+ else if (!isPortStateOk (alias))
65
+ {
66
+ // Can happen when a DEL notification is sent by portmgrd immediately followed by a new SET notification
67
+ SWSS_LOG_WARN (" Setting admin_status to alias:%s netdev failed with cmd%s, rc:%d, error:%s" , alias.c_str (), cmd_str.c_str (), ret, res.c_str ());
68
+ return false ;
69
+ }
70
+ else
71
+ {
72
+ throw runtime_error (cmd_str + " : " + res);
73
+ }
74
+ return true ;
47
75
}
48
76
49
77
bool PortMgr::isPortStateOk (const string &alias)
@@ -124,10 +152,9 @@ void PortMgr::doTask(Consumer &consumer)
124
152
}
125
153
}
126
154
127
- for ( auto &entry : field_values)
155
+ if ( field_values. size () )
128
156
{
129
- writeConfigToAppDb (alias, fvField (entry), fvValue (entry));
130
- SWSS_LOG_NOTICE (" Configure %s %s to %s" , alias.c_str (), fvField (entry).c_str (), fvValue (entry).c_str ());
157
+ writeConfigToAppDb (alias, field_values);
131
158
}
132
159
133
160
if (!portOk)
@@ -136,6 +163,7 @@ void PortMgr::doTask(Consumer &consumer)
136
163
137
164
writeConfigToAppDb (alias, " mtu" , mtu);
138
165
writeConfigToAppDb (alias, " admin_status" , admin_status);
166
+ /* Retry setting these params after the netdev is created */
139
167
field_values.clear ();
140
168
field_values.emplace_back (" mtu" , mtu);
141
169
field_values.emplace_back (" admin_status" , admin_status);
@@ -176,3 +204,9 @@ bool PortMgr::writeConfigToAppDb(const std::string &alias, const std::string &fi
176
204
177
205
return true ;
178
206
}
207
+
208
+ bool PortMgr::writeConfigToAppDb (const std::string &alias, std::vector<FieldValueTuple> &field_values)
209
+ {
210
+ m_appPortTable.set (alias, field_values);
211
+ return true ;
212
+ }
0 commit comments