Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cmp in acl_loader with operator.eq #2328

Merged
merged 3 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ipaddress
import json
import syslog
import operator

import openconfig_acl
import tabulate
Expand Down Expand Up @@ -758,7 +759,7 @@ def incremental_update(self):
namespace_configdb.mod_entry(self.ACL_RULE, key, None)

for key in existing_controlplane_rules:
if cmp(self.rules_info[key], self.rules_db_info[key]) != 0:
if not operator.eq(self.rules_info[key], self.rules_db_info[key]):
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
32 changes: 32 additions & 0 deletions tests/acl_input/incremental_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"acl": {
"acl-sets": {
"acl-set": {
"ntp-acl": {
"acl-entries": {
"acl-entry": {
"1": {
"ip": {
"config": {
"source-ip-address": "20.0.0.12/32"
}
},
"config": {
"sequence-id": 1
},
"actions": {
"config": {
"forwarding-action": "ACCEPT"
}
}
}
}
},
"config": {
"name": "ntp-acl"
}
}
}
}
}
}
32 changes: 32 additions & 0 deletions tests/acl_input/incremental_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"acl": {
"acl-sets": {
"acl-set": {
"ntp-acl": {
"acl-entries": {
"acl-entry": {
"1": {
"ip": {
"config": {
"source-ip-address": "20.0.0.12/32"
}
},
"config": {
"sequence-id": 1
},
"actions": {
"config": {
"forwarding-action": "DROP"
}
}
}
}
},
"config": {
"name": "ntp-acl"
}
}
}
}
}
}
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"