Skip to content

Commit

Permalink
[warmboot] use config_db connector to update mux mode config instead …
Browse files Browse the repository at this point in the history
…of CLI (#223)

Description of PR
Summary:
Fixes # (issue)

This PR is to fix handleWarmRestartReconciliationTimeout, for failing configuring mux port back to auto mode.

Issue logs:

Dec  3 20:22:23.715483  NOTICE mux#linkmgrd: MuxManager.cpp:570 handleWarmRestartReconciliationTimeout: Reconciliation timed out after warm restart, set service to reconciled now.
Dec  3 20:22:23.717051  NOTICE mux#linkmgrd: MuxManager.cpp:574 handleWarmRestartReconciliationTimeout: config mux mode back to auto completed with return code 32512
Dec  3 20:22:23.717427  INFO mux#supervisord: linkmgrd sh: 1: sudo: not found
Dec  3 20:22:23.717427  NOTICE mux#linkmgrd: :- setWarmStartState: linkmgrd warm start state changed to reconciled

sign-off: Jing Zhang [email protected]
  • Loading branch information
zjswhhh authored and liushilongbuaa committed Jan 4, 2024
1 parent b9d33d5 commit c33f458
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/DbInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,46 @@ void DbInterface::getSoCIpAddress(std::shared_ptr<swss::DBConnector> configDbCon
processSoCIpAddress(entries);
}

//
// ---> getMuxModeConfig();
//
// retrieve MUX mode configuration
//
std::map<std::string, std::string> DbInterface::getMuxModeConfig()
{
MUXLOGINFO("Reading MUX mode configuration");
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
swss::Table configDbMuxCableTable(configDbPtr.get(), CFG_MUX_CABLE_TABLE_NAME);
std::vector<swss::KeyOpFieldsValuesTuple> entries;
std::map<std::string, std::string> PortToMuxModeConfigMapping;

configDbMuxCableTable.getContent(entries);

for (auto &entry: entries) {
std::string portName = kfvKey(entry);
std::vector<swss::FieldValueTuple> fieldValues = kfvFieldsValues(entry);

std::vector<swss::FieldValueTuple>::const_iterator cit = std::find_if(
fieldValues.cbegin(),
fieldValues.cend(),
[] (const swss::FieldValueTuple &fv) {return fvField(fv) == "state";}
);

if (cit != fieldValues.cend()) {
const std::string f = cit->first;
std::string muxMode = cit->second;

MUXLOGDEBUG(boost::format("port: %s, mode mux %s = %s") % portName % f % muxMode);

PortToMuxModeConfigMapping[portName] = muxMode;
} else {
MUXLOGERROR(boost::format("port: %s, mode mux is not found in %s table") % portName % CFG_MUX_CABLE_TABLE_NAME);
}
}

return PortToMuxModeConfigMapping;
}

// ---> warmRestartReconciliation(const std::string &portName);
//
// port warm restart reconciliation procedure
Expand Down
9 changes: 9 additions & 0 deletions src/DbInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ class DbInterface
*/
virtual void setWarmStartStateReconciled(){swss::WarmStart::setWarmStartState("linkmgrd", swss::WarmStart::RECONCILED);};

/**
*@method getMuxModeConfig
*
*@brief retrieve mux mode config
*
*@return port to mux mode map
*/
virtual std::map<std::string, std::string> getMuxModeConfig();

private:
friend class test::MuxManagerTest;

Expand Down
11 changes: 9 additions & 2 deletions src/MuxManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,15 @@ void MuxManager::handleWarmRestartReconciliationTimeout(const boost::system::err
MUXLOGWARNING("Reconciliation timed out after warm restart, set service to reconciled now.");
}

int rc = system("sudo config muxcable mode auto all");
MUXLOGWARNING(boost::format("config mux mode back to auto completed with return code %d") % rc);
std::map<std::string, std::string> muxModeMap = mDbInterfacePtr->getMuxModeConfig();
for (auto it = muxModeMap.begin(); it != muxModeMap.end(); ++it) {
if (it->second == "auto") {
continue;
}

MUXLOGWARNING(boost::format("config mux mode back to auto for %s") % it->first);
mDbInterfacePtr->setMuxMode(it->first, "auto");
}

mDbInterfacePtr->setWarmStartStateReconciled();
}
Expand Down
9 changes: 9 additions & 0 deletions test/FakeDbInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ void FakeDbInterface::postSwitchCause(
mLastPostedSwitchCause = cause;
}

std::map<std::string, std::string> FakeDbInterface::getMuxModeConfig()
{
mGetMuxModeConfigInvokeCount++;

std::map<std::string, std::string> muxModeConfig;
muxModeConfig["Ethernet0"] = "manual";
return muxModeConfig;
}

} /* namespace test */
2 changes: 2 additions & 0 deletions test/FakeDbInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FakeDbInterface: public mux::DbInterface
virtual void handleSetMuxState(const std::string portName, mux_state::MuxState::Label label) override;
virtual void handleSetPeerMuxState(const std::string portName, mux_state::MuxState::Label label) override;
virtual void getMuxState(const std::string &portName) override;
virtual std::map<std::string, std::string> getMuxModeConfig() override;
virtual void probeMuxState(const std::string &portName) override;
virtual void handleProbeForwardingState(const std::string portName) override;
virtual void setMuxLinkmgrState(
Expand Down Expand Up @@ -95,6 +96,7 @@ class FakeDbInterface: public mux::DbInterface
uint32_t mSetMuxModeInvokeCount = 0;
uint32_t mSetWarmStartStateReconciledInvokeCount = 0;
uint32_t mPostSwitchCauseInvokeCount = 0;
uint32_t mGetMuxModeConfigInvokeCount = 0;

link_manager::ActiveStandbyStateMachine::SwitchCause mLastPostedSwitchCause;

Expand Down

0 comments on commit c33f458

Please sign in to comment.