Skip to content

Commit 8414a70

Browse files
authored
[chassis][multi asic] change acl_loader to use tcp socket for db communication (sonic-net#2525)
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan [email protected] Microsoft ADO 24363637 What I did Currently on multi asic platform the acl-loader script connects to all the db in the namespaces using unix sockets. This cause permission errors when executing show acl commands for user with RO privileges. To avoid this change the acl-loader to use tcp socket to connect to db in namespaces How I did it update acl-loader How to verify it UT Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <[email protected]>
1 parent 0b629ba commit 8414a70

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

acl_loader/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ def __init__(self):
156156

157157
namespaces = multi_asic.get_all_namespaces()
158158
for front_asic_namespaces in namespaces['front_ns']:
159-
self.per_npu_configdb[front_asic_namespaces] = ConfigDBConnector(use_unix_socket_path=True, namespace=front_asic_namespaces)
159+
self.per_npu_configdb[front_asic_namespaces] = ConfigDBConnector(namespace=front_asic_namespaces)
160160
self.per_npu_configdb[front_asic_namespaces].connect()
161-
self.per_npu_statedb[front_asic_namespaces] = SonicV2Connector(use_unix_socket_path=True, namespace=front_asic_namespaces)
161+
self.per_npu_statedb[front_asic_namespaces] = SonicV2Connector(namespace=front_asic_namespaces)
162162
self.per_npu_statedb[front_asic_namespaces].connect(self.per_npu_statedb[front_asic_namespaces].STATE_DB)
163163

164164
self.read_tables_info()

tests/acl_loader_test.py

+41
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib
12
import sys
23
import os
34
import pytest
@@ -269,3 +270,43 @@ def test_incremental_update(self, acl_loader):
269270
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/incremental_2.json'))
270271
acl_loader.incremental_update()
271272
assert acl_loader.rules_info[(('NTP_ACL', 'RULE_1'))]["PACKET_ACTION"] == "DROP"
273+
274+
275+
276+
class TestMasicAclLoader(object):
277+
278+
279+
@pytest.fixture(scope="class")
280+
def acl_loader(self):
281+
from .mock_tables import mock_multi_asic
282+
importlib.reload(mock_multi_asic)
283+
from .mock_tables import dbconnector
284+
dbconnector.load_namespace_config()
285+
286+
with mock.patch("sonic_py_common.multi_asic.get_all_namespaces",
287+
mock.MagicMock(return_value={'front_ns': ['asic0', 'asic1'], 'back_ns': '', 'fabric_ns': ''})):
288+
yield AclLoader()
289+
290+
# mock single asic to avoid affecting other tests
291+
from .mock_tables import mock_single_asic
292+
importlib.reload(mock_single_asic)
293+
294+
def test_check_npu_db(self, acl_loader):
295+
assert len(acl_loader.per_npu_configdb) == 2
296+
assert len(acl_loader.per_npu_statedb) == 2
297+
298+
def test_incremental_update(self, acl_loader):
299+
acl_loader.rules_info = {}
300+
acl_loader.tables_db_info['NTP_ACL'] = {
301+
"stage": "INGRESS",
302+
"type": "CTRLPLANE"
303+
}
304+
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/incremental_1.json'))
305+
acl_loader.rules_db_info = acl_loader.rules_info
306+
assert acl_loader.rules_info[(('NTP_ACL', 'RULE_1'))]["PACKET_ACTION"] == "ACCEPT"
307+
for configdb in acl_loader.per_npu_configdb.values():
308+
configdb.mod_entry = mock.MagicMock(return_value=True)
309+
configdb.set_entry = mock.MagicMock(return_value=True)
310+
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/incremental_2.json'))
311+
acl_loader.incremental_update()
312+
assert acl_loader.rules_info[(('NTP_ACL', 'RULE_1'))]["PACKET_ACTION"] == "DROP"

0 commit comments

Comments
 (0)