Skip to content

Commit 5c63670

Browse files
[intfmgrd] reach reconciled state at start when there are no interfaces configuration to process (sonic-net#1695)
* fix intfmgrd reconciliation when there are no interfaces in the system Signed-off-by: Stepan Blyschak <[email protected]>
1 parent 66e1aab commit 5c63670

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

cfgmgr/intfmgr.cpp

+18-10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
4444
{
4545
//Build the interface list to be replayed to Kernel
4646
buildIntfReplayList();
47+
if (m_pendingReplayIntfList.empty())
48+
{
49+
setWarmReplayDoneState();
50+
}
4751
}
4852
}
4953

@@ -191,16 +195,25 @@ void IntfMgr::buildIntfReplayList(void)
191195

192196
m_cfgLoopbackIntfTable.getKeys(intfList);
193197
std::copy( intfList.begin(), intfList.end(), std::inserter( m_pendingReplayIntfList, m_pendingReplayIntfList.end() ) );
194-
198+
195199
m_cfgVlanIntfTable.getKeys(intfList);
196200
std::copy( intfList.begin(), intfList.end(), std::inserter( m_pendingReplayIntfList, m_pendingReplayIntfList.end() ) );
197-
201+
198202
m_cfgLagIntfTable.getKeys(intfList);
199203
std::copy( intfList.begin(), intfList.end(), std::inserter( m_pendingReplayIntfList, m_pendingReplayIntfList.end() ) );
200204

201205
SWSS_LOG_INFO("Found %d Total Intfs to be replayed", (int)m_pendingReplayIntfList.size() );
202206
}
203207

208+
void IntfMgr::setWarmReplayDoneState()
209+
{
210+
m_replayDone = true;
211+
WarmStart::setWarmStartState("intfmgrd", WarmStart::REPLAYED);
212+
// There is no operation to be performed for intfmgr reconcillation
213+
// Hence mark it reconciled right away
214+
WarmStart::setWarmStartState("intfmgrd", WarmStart::RECONCILED);
215+
}
216+
204217
bool IntfMgr::isIntfCreated(const string &alias)
205218
{
206219
vector<FieldValueTuple> temp;
@@ -705,7 +718,6 @@ bool IntfMgr::doIntfAddrTask(const vector<string>& keys,
705718
void IntfMgr::doTask(Consumer &consumer)
706719
{
707720
SWSS_LOG_ENTER();
708-
static bool replayDone = false;
709721

710722
string table_name = consumer.getTableName();
711723

@@ -761,13 +773,9 @@ void IntfMgr::doTask(Consumer &consumer)
761773

762774
it = consumer.m_toSync.erase(it);
763775
}
764-
765-
if (!replayDone && WarmStart::isWarmStart() && m_pendingReplayIntfList.empty() )
776+
777+
if (!m_replayDone && WarmStart::isWarmStart() && m_pendingReplayIntfList.empty() )
766778
{
767-
replayDone = true;
768-
WarmStart::setWarmStartState("intfmgrd", WarmStart::REPLAYED);
769-
// There is no operation to be performed for intfmgr reconcillation
770-
// Hence mark it reconciled right away
771-
WarmStart::setWarmStartState("intfmgrd", WarmStart::RECONCILED);
779+
setWarmReplayDoneState();
772780
}
773781
}

cfgmgr/intfmgr.h

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class IntfMgr : public Orch
3939
bool isIntfChangeVrf(const std::string &alias, const std::string &vrfName);
4040
int getIntfIpCount(const std::string &alias);
4141
void buildIntfReplayList(void);
42+
void setWarmReplayDoneState();
4243

4344
void addLoopbackIntf(const std::string &alias);
4445
void delLoopbackIntf(const std::string &alias);
@@ -53,6 +54,8 @@ class IntfMgr : public Orch
5354

5455
bool setIntfProxyArp(const std::string &alias, const std::string &proxy_arp);
5556
bool setIntfGratArp(const std::string &alias, const std::string &grat_arp);
57+
58+
bool m_replayDone {false};
5659
};
5760

5861
}

tests/test_warm_reboot.py

+23
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def swss_app_check_RestoreCount_single(state_db, restore_count, name):
7777
assert int(fv[1]) == restore_count[key] + 1
7878
elif fv[0] == "state":
7979
assert fv[1] == "reconciled" or fv[1] == "disabled"
80+
return status, fvs
8081

8182
def swss_app_check_warmstart_state(state_db, name, state):
8283
warmtbl = swsscommon.Table(state_db, swsscommon.STATE_WARM_RESTART_TABLE_NAME)
@@ -445,6 +446,28 @@ def test_VlanMgrdWarmRestart(self, dvs, testlog):
445446
intf_tbl._del("Vlan20")
446447
time.sleep(2)
447448

449+
def test_IntfMgrdWarmRestartNoInterfaces(self, dvs, testlog):
450+
""" Tests that intfmgrd reaches reconciled state when
451+
there are no interfaces in configuration. """
452+
453+
state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0)
454+
restore_count = swss_get_RestoreCount(dvs, state_db)
455+
456+
dvs.runcmd("config warm_restart enable swss")
457+
dvs.runcmd("supervisorctl restart intfmgrd")
458+
459+
reached_desired_state = False
460+
retries = 10
461+
delay = 2
462+
for _ in range(retries):
463+
ok, fvs = swss_app_check_RestoreCount_single(state_db, restore_count, "intfmgrd")
464+
if ok and dict(fvs)["state"] == "reconciled":
465+
reached_desired_state = True
466+
break
467+
time.sleep(delay)
468+
469+
assert reached_desired_state, "intfmgrd haven't reached desired state 'reconciled', after {} sec it was {}".format(retries * delay, dict(fvs)["state"])
470+
448471
def test_swss_neighbor_syncup(self, dvs, testlog):
449472

450473
appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)

0 commit comments

Comments
 (0)