Skip to content

Commit c24d7d6

Browse files
committed
Add feature check
Signed-off-by: Ze Gan <ganze718@gmail.com>
1 parent b26b305 commit c24d7d6

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

cfgmgr/teammgr.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ TeamMgr::TeamMgr(DBConnector *confDb, DBConnector *applDb, DBConnector *statDb,
3434
m_appLagTable(applDb, APP_LAG_TABLE_NAME),
3535
m_statePortTable(statDb, STATE_PORT_TABLE_NAME),
3636
m_stateLagTable(statDb, STATE_LAG_TABLE_NAME),
37-
m_stateMACsecPortTable(statDb, STATE_MACSEC_PORT_TABLE_NAME)
37+
m_stateMACsecPortTable(statDb, STATE_MACSEC_PORT_TABLE_NAME),
38+
m_stateFeatureTable(statDb, "FEATURE")
3839
{
3940
SWSS_LOG_ENTER();
4041

@@ -99,6 +100,27 @@ bool TeamMgr::isLagStateOk(const string &alias)
99100
return true;
100101
}
101102

103+
bool TeamMgr::isMACsecFeatureEnabled()
104+
{
105+
SWSS_LOG_ENTER();
106+
107+
vector<FieldValueTuple> temp;
108+
if (!m_stateFeatureTable.get("macsec", temp))
109+
{
110+
return false;
111+
}
112+
113+
auto opt = swss::fvsGetValue(temp, "state", true);
114+
115+
if (!opt || *opt != "enabled")
116+
{
117+
SWSS_LOG_INFO("MACsec feature isn't enabled");
118+
return false;
119+
}
120+
121+
return true;
122+
}
123+
102124
bool TeamMgr::isMACsecSetted(const std::string &port)
103125
{
104126
SWSS_LOG_ENTER();
@@ -348,10 +370,13 @@ void TeamMgr::doLagMemberTask(Consumer &consumer)
348370
continue;
349371
}
350372

351-
if (isMACsecSetted(member) && !isMACsecStateOk(member))
373+
if (isMACsecFeatureEnabled())
352374
{
353-
it++;
354-
continue;
375+
if (isMACsecSetted(member) && !isMACsecStateOk(member))
376+
{
377+
it++;
378+
continue;
379+
}
355380
}
356381

357382
if (addLagMember(lag, member) == task_need_retry)

cfgmgr/teammgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TeamMgr : public Orch
2828
Table m_statePortTable;
2929
Table m_stateLagTable;
3030
Table m_stateMACsecPortTable;
31+
Table m_stateFeatureTable;
3132

3233
ProducerStateTable m_appPortTable;
3334
ProducerStateTable m_appLagTable;
@@ -56,6 +57,7 @@ class TeamMgr : public Orch
5657
bool checkPortIffUp(const std::string &);
5758
bool isPortStateOk(const std::string&);
5859
bool isLagStateOk(const std::string&);
60+
bool isMACsecFeatureEnabled();
5961
bool isMACsecSetted(const std::string &);
6062
bool isMACsecStateOk(const std::string &);
6163
uint16_t generateLacpKey(const std::string&);

tests/test_macsec.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ def test_macsec_attribute_change(self, dvs: conftest.DockerVirtualSwitch, testlo
765765
def test_macsec_with_portchannel(self, dvs: conftest.DockerVirtualSwitch, testlog):
766766

767767
# Set MACsec enabled on Ethernet0
768-
ConfigTable(dvs, "PORT")["Ethernet0"] = {"macsec": "test"}
768+
ConfigTable(dvs, "PORT")["Ethernet0"] = {"macsec" : "test"}
769+
StateDBTable(dvs, "FEATURE")["macsec"] = {"state": "enabled"}
769770

770771
# Setup Port-channel
771772
ConfigTable(dvs, "PORTCHANNEL")["PortChannel001"] = {"admin": "up", "mtu": "9100", "oper_status": "up"}
@@ -831,6 +832,18 @@ def test_macsec_with_portchannel(self, dvs: conftest.DockerVirtualSwitch, testlo
831832
macsec_port_identifier,
832833
0)
833834

835+
# remove port channel member
836+
del ConfigTable(dvs, "PORTCHANNEL_INTERFACE")["PortChannel001"]
837+
del ConfigTable(dvs, "PORTCHANNEL_INTERFACE")["PortChannel001|40.0.0.0/31"]
838+
del ConfigTable(dvs, "PORTCHANNEL_MEMBER")["PortChannel001|Ethernet0"]
839+
840+
# remove port channel
841+
del ConfigTable(dvs, "PORTCHANNEL")["PortChannel001"]
842+
843+
# Clear MACsec enabled on Ethernet0
844+
ConfigTable(dvs, "PORT")["Ethernet0"] = {"macsec" : ""}
845+
846+
834847
# Add Dummy always-pass test at end as workaroud
835848
# for issue when Flaky fail on final test it invokes module tear-down
836849
# before retrying

0 commit comments

Comments
 (0)