Skip to content

Commit 80fcada

Browse files
JaredLiusprsunny
authored andcommitted
remove crm acl_counters when acl_table removed (#918)
* fix bad parameter for gCrmOrch->incCrmAclUsedCounter in qosorch * fix VS test failure for test_crm.py::test_CrmAcl FAILED * remove crm acl_counters when acl_table removed Signed-off-by: Jared.Liu <[email protected]> * add test case for remove crm acl_counters when acl_table removed #918
1 parent 5a33f89 commit 80fcada

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

orchagent/crmorch.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,28 @@ void CrmOrch::decCrmAclUsedCounter(CrmResourceType resource, sai_acl_stage_t sta
336336
{
337337
m_resourcesMap.at(resource).countersMap[getCrmAclKey(stage, point)].usedCounter--;
338338

339-
// Remove ACL table related counters
339+
// remove acl_entry and acl_counter in this acl table
340340
if (resource == CrmResourceType::CRM_ACL_TABLE)
341341
{
342-
auto & cntMap = m_resourcesMap.at(CrmResourceType::CRM_ACL_TABLE).countersMap;
343-
for (auto it = cntMap.begin(); it != cntMap.end();)
342+
for (auto &resourcesMap : m_resourcesMap)
344343
{
345-
if (it->second.id == oid)
344+
if ((resourcesMap.first == (CrmResourceType::CRM_ACL_ENTRY))
345+
|| (resourcesMap.first == (CrmResourceType::CRM_ACL_COUNTER)))
346346
{
347-
it = cntMap.erase(it);
348-
}
349-
else
350-
{
351-
++it;
347+
auto &cntMap = resourcesMap.second.countersMap;
348+
for (auto it = cntMap.begin(); it != cntMap.end(); ++it)
349+
{
350+
if (it->second.id == oid)
351+
{
352+
cntMap.erase(it);
353+
break;
354+
}
355+
}
352356
}
353357
}
358+
359+
// remove ACL_TABLE_STATS in crm database
360+
m_countersCrmTable->del(getCrmAclTableKey(oid));
354361
}
355362
}
356363
catch (...)

tests/test_crm.py

+5
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ def test_CrmAcl(dvs, testlog):
563563
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
564564

565565
dvs.runcmd("crm config polling interval 1")
566+
time.sleep(1)
566567

567568
bind_ports = ["Ethernet0", "Ethernet4"]
568569

@@ -615,3 +616,7 @@ def test_CrmAcl(dvs, testlog):
615616
table_used_counter = new_table_used_counter - old_table_used_counter
616617
assert table_used_counter == 0
617618

619+
counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0)
620+
crm_stats_table = swsscommon.Table(counters_db, 'CRM')
621+
keys = crm_stats_table.getKeys()
622+
assert key not in keys

0 commit comments

Comments
 (0)