Skip to content

Commit

Permalink
Fix judgement condition and add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
  • Loading branch information
ZhaohuiS committed Aug 29, 2022
1 parent 9fd47e0 commit 91d4932
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def incremental_update(self):
namespace_configdb.mod_entry(self.ACL_RULE, key, None)

for key in existing_controlplane_rules:
if operator.eq(self.rules_info[key], self.rules_db_info[key]) != 0:
if operator.eq(self.rules_info[key], self.rules_db_info[key]) == False:
self.configdb.set_entry(self.ACL_RULE, key, self.rules_info[key])
# Program for per-asic namespace corresponding to front asic also if present.
# For control plane ACL it's not needed but to keep all db in sync program everywhere
Expand Down
17 changes: 17 additions & 0 deletions tests/acl_loader_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import os
import pytest
from unittest import mock

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand Down Expand Up @@ -200,3 +201,19 @@ def test_icmp_fields_with_non_tcp_protocol(self, acl_loader):
acl_loader.rules_info = {}
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/tcp_bad_protocol_number.json'))
assert not acl_loader.rules_info.get("RULE_1")

def test_incremental_update(self, acl_loader):
acl_loader.rules_info = {}
acl_loader.tables_db_info['NTP_ACL'] = {
"stage": "INGRESS",
"type": "CTRLPLANE"
}
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/incremental_1.json'))
acl_loader.rules_db_info = acl_loader.rules_info
assert acl_loader.rules_info[(('NTP_ACL', 'RULE_1'))]["PACKET_ACTION"] == "ACCEPT"
acl_loader.per_npu_configdb = None
acl_loader.configdb.mod_entry = mock.MagicMock(return_value=True)
acl_loader.configdb.set_entry = mock.MagicMock(return_value=True)
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/incremental_2.json'))
acl_loader.incremental_update()
assert acl_loader.rules_info[(('NTP_ACL', 'RULE_1'))]["PACKET_ACTION"] == "DROP"

0 comments on commit 91d4932

Please sign in to comment.