Skip to content

Commit 59334be

Browse files
zjswhhhyxieca
authored andcommitted
Remove exception throwing when initializing missing loopback interface (#90)
### Description of PR Summary: Fixes # (issue) This PR is to avoid throwing exception when linkmgrd initializing without CONFIG DB loopback interface entry. sign-off: Jing Zhang [email protected] ### Type of change - [x] Bug fix ### Approach #### What is the motivation for this PR? Avoid unnecessary process exits. #### How did you do it? Log a fatal message instead of exiting the process. #### How did you verify/test it? Tested on dual testbeds. Met all expected behavior below: 1. Remove loopback interface live (when linkmgrd is running): No linkmgrd crash. `show mux status` reported `unhealthy` as no IP interface to receive heartbeat packets. 2. Start mux service when missing loopback interface: No linkmgrd crash. Saw fatal log below in syslog. `show mux status` report `unhealthy`. 3. Add back loopback interface CONFIG DB entry live: `show mux status` reported `healthy`.
1 parent d6518dd commit 59334be

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/DbInterface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void DbInterface::processLoopback2InterfaceInfo(std::vector<std::string> &loopba
577577
}
578578

579579
if (!loopback2IPv4Found) {
580-
throw MUX_ERROR(ConfigNotFound, "Loopback2 IPv4 address missing");
580+
MUXLOGFATAL(boost::format("Config not found: Loopback2 IPv4 address missing, using default value %s ") % mMuxManagerPtr->getLoopbackIpv4Address().to_string());
581581
}
582582
}
583583

src/MuxManager.h

+9
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ class MuxManager
193193
*/
194194
void setUseWellKnownMacActiveActive(bool useWellKnownMac);
195195

196+
/**
197+
* @method getLoopbackIpv4Address
198+
*
199+
* @brief getter for loop back ipv4 address
200+
*
201+
* @return IPv4 address
202+
*/
203+
inline boost::asio::ip::address getLoopbackIpv4Address() {return mMuxConfig.getLoopbackIpv4Address();};
204+
196205
/**
197206
*@method initialize
198207
*

test/MuxManagerTest.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ TEST_F(MuxManagerTest, Loopback2Address)
440440
processLoopback2InterfaceInfo(loopbackIntfs);
441441

442442
EXPECT_TRUE(getLoopbackIpv4Address(port).to_string() == ipAddress);
443+
EXPECT_TRUE(mMuxManagerPtr->getLoopbackIpv4Address() == getLoopbackIpv4Address(port));
443444
}
444445

445446
TEST_F(MuxManagerTest, Loopback2AddressException)
@@ -448,13 +449,14 @@ TEST_F(MuxManagerTest, Loopback2AddressException)
448449

449450
createPort(port);
450451

452+
std::string defaultAddress = "10.212.64.0";
451453
std::vector<std::string> loopbackIntfs = {
452454
"Loopback2|2603:10e1:100:d::1/128",
453455
"Loopback2|250.260.270.280/32",
454456
"Loopback2"
455457
};
456458

457-
EXPECT_THROW(processLoopback2InterfaceInfo(loopbackIntfs), common::ConfigNotFoundException);
459+
EXPECT_TRUE(getLoopbackIpv4Address(port).to_string() == defaultAddress);
458460
}
459461

460462
TEST_F(MuxManagerTest, ToRMacAddress)

0 commit comments

Comments
 (0)