Skip to content

Commit fd409d6

Browse files
authored
[portsorch] Fix HOSTIF oper status configuration on boot (#3794)
Fixes sonic-net/sonic-buildimage#23347 <!-- Please make sure you have read and understood the contribution guildlines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md 1. Make sure your commit includes a signature generted with `git commit -s` 2. Make sure your commit title follows the correct format: [component]: description 3. Make sure your commit message contains enough details about the change and related tests 4. Make sure your pull request adds related reviewers, asignees, labels Please also provide the following information in this pull request: --> **What I did** Fix an issue where m_oper_status is used uninitialized. **Why I did it** To fix hostif set down after warm-boot. **How I verified it** UT, need help from community to test on BRCM. **Details if related**
1 parent 9dbd983 commit fd409d6

File tree

2 files changed

+69
-12
lines changed

2 files changed

+69
-12
lines changed

orchagent/portsorch.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6167,18 +6167,6 @@ bool PortsOrch::initializePort(Port &port)
61676167
initializeSchedulerGroups(port);
61686168
}
61696169

6170-
/*
6171-
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
6172-
*/
6173-
bool isUp = port.m_oper_status == SAI_PORT_OPER_STATUS_UP;
6174-
6175-
/* Create host interface */
6176-
if (!addHostIntfs(port, port.m_alias, port.m_hif_id, isUp))
6177-
{
6178-
SWSS_LOG_ERROR("Failed to create host interface for port %s", port.m_alias.c_str());
6179-
return false;
6180-
}
6181-
61826170
/* Check warm start states */
61836171
vector<FieldValueTuple> tuples;
61846172
bool exist = m_portTable->get(port.m_alias, tuples);
@@ -6233,6 +6221,18 @@ bool PortsOrch::initializePort(Port &port)
62336221
}
62346222
}
62356223

6224+
/*
6225+
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
6226+
*/
6227+
bool isUp = port.m_oper_status == SAI_PORT_OPER_STATUS_UP;
6228+
6229+
/* Create host interface */
6230+
if (!addHostIntfs(port, port.m_alias, port.m_hif_id, isUp))
6231+
{
6232+
SWSS_LOG_ERROR("Failed to create host interface for port %s", port.m_alias.c_str());
6233+
return false;
6234+
}
6235+
62366236
/* initialize port admin status */
62376237
if (!getPortAdminStatus(port.m_port_id, port.m_admin_state_up))
62386238
{

tests/mock_tests/portsorch_ut.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,7 @@ namespace portsorch_test
27212721
for (const auto &it : ports)
27222722
{
27232723
portTable.set(it.first, it.second);
2724+
portTable.set(it.first, {{"oper_status", "up"}});
27242725
transceieverInfoTable.set(it.first, {});
27252726
}
27262727

@@ -2788,6 +2789,62 @@ namespace portsorch_test
27882789
ASSERT_EQ(status, SAI_STATUS_SUCCESS);
27892790
ASSERT_TRUE(attr.value.booldata);
27902791
}
2792+
2793+
// Verify host if configuration
2794+
for (const auto& iter: ports)
2795+
{
2796+
const auto& portName = iter.first;
2797+
2798+
Port port;
2799+
gPortsOrch->getPort(portName, port);
2800+
2801+
ASSERT_TRUE(port.m_oper_status == SAI_PORT_OPER_STATUS_UP);
2802+
2803+
attr.id = SAI_HOSTIF_ATTR_OPER_STATUS;
2804+
status = sai_hostif_api->get_hostif_attribute(port.m_hif_id, 1, &attr);
2805+
2806+
ASSERT_EQ(status, SAI_STATUS_SUCCESS);
2807+
ASSERT_TRUE(attr.value.booldata);
2808+
}
2809+
}
2810+
2811+
TEST_F(PortsOrchTest, PortHostIfCreateFailed)
2812+
{
2813+
Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME);
2814+
2815+
auto original_api = sai_hostif_api->create_hostif;
2816+
auto hostIfSpy = SpyOn<SAI_API_HOSTIF, SAI_OBJECT_TYPE_HOSTIF>(&sai_hostif_api->create_hostif);
2817+
hostIfSpy->callFake([&](sai_object_id_t*, sai_object_id_t, uint32_t, const sai_attribute_t*) -> sai_status_t {
2818+
return SAI_STATUS_INSUFFICIENT_RESOURCES;
2819+
}
2820+
);
2821+
2822+
// Get SAI default ports to populate DB
2823+
2824+
auto ports = ut_helper::getInitialSaiPorts();
2825+
2826+
// Populate pot table with SAI ports
2827+
for (const auto &it : ports)
2828+
{
2829+
portTable.set(it.first, it.second);
2830+
}
2831+
2832+
// Set PortConfigDone
2833+
portTable.set("PortConfigDone", { { "count", to_string(ports.size()) } });
2834+
2835+
gPortsOrch->addExistingData(&portTable);
2836+
2837+
// Apply configuration :
2838+
// create ports
2839+
2840+
static_cast<Orch *>(gPortsOrch)->doTask();
2841+
2842+
sai_hostif_api->create_hostif = original_api;
2843+
2844+
Port port;
2845+
gPortsOrch->getPort("Ethernet0", port);
2846+
2847+
ASSERT_FALSE(port.m_init);
27912848
}
27922849

27932850
TEST_F(PortsOrchTest, PfcDlrHandlerCallingDlrInitAttribute)

0 commit comments

Comments
 (0)