Skip to content

Commit 7435b1c

Browse files
authored
Fix show acl table for masic (#2937)
What I did Fixes sonic-net/sonic-buildimage#16012 The show acl table command currently get the ports from host config_db on multi asic platforms. This host config_db will not the phyiscal ports in the binding ports because the host doesnt have any front panel ports on the host. This causes the show acl table not to display the phyiscal ports in the output on multi asic devices/linecards. The test iface_namingmode/test_iface_namingmode.py::test_show_acl_table fails because of this issue.
1 parent 8cb7320 commit 7435b1c

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

acl_loader/main.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,31 @@ def read_tables_info(self):
173173
Read ACL_TABLE table from configuration database
174174
:return:
175175
"""
176-
self.tables_db_info = self.configdb.get_table(self.ACL_TABLE)
176+
# get the acl table info from host config_db
177+
host_acl_table = self.configdb.get_table(self.ACL_TABLE)
178+
# For multi asic get only the control plane acls from the host config_db
179+
if self.per_npu_configdb:
180+
for table, entry in host_acl_table.items():
181+
if entry.get('type', None) != self.ACL_TABLE_TYPE_CTRLPLANE:
182+
continue
183+
184+
self.tables_db_info[table] = entry
185+
else:
186+
self.tables_db_info.update(host_acl_table)
187+
188+
# for DATAACL, EVERFLOW acls.
189+
# update the ports from all the namespaces
190+
if self.per_npu_configdb:
191+
for ns, config_db in self.per_npu_configdb.items():
192+
acl_table = config_db.get_table(self.ACL_TABLE)
193+
for table, entry in acl_table.items():
194+
if entry.get('type', None) == self.ACL_TABLE_TYPE_CTRLPLANE:
195+
continue
196+
if table not in self.tables_db_info:
197+
self.tables_db_info[table] = entry
198+
else:
199+
self.tables_db_info[table]['ports'] += entry.get(
200+
'ports', [])
177201

178202
def get_tables_db_info(self):
179203
return self.tables_db_info

tests/mock_tables/asic2/config_db.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
},
133133
"ACL_TABLE|DATAACL_5": {
134134
"policy_desc": "DATAACL_5",
135-
"ports@": "Ethernet124",
135+
"ports@": "Ethernet20",
136136
"type": "L3",
137137
"stage": "ingress"
138138
}

tests/show_acl_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
modules_path = os.path.dirname(root_path)
1212
scripts_path = os.path.join(modules_path, "scripts")
1313

14+
MASIC_SHOW_ACL_OUTPUT = """Name Type Binding Description Stage Status
15+
--------- ------ ----------- ------------- ------- --------------------------------------
16+
DATAACL_5 L3 Ethernet20 DATAACL_5 ingress {'asic0': 'Active', 'asic2': 'Active'}
17+
Ethernet124
18+
"""
1419

1520
@pytest.fixture()
1621
def setup_teardown_single_asic():
@@ -74,10 +79,7 @@ def test_show_acl_table(self, setup_teardown_multi_asic):
7479
}
7580
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['table'], ['DATAACL_5'], obj=context)
7681
assert result.exit_code == 0
77-
# We only care about the third line, which contains the 'Active'
78-
result_top = result.output.split('\n')[2]
79-
expected_output = "DATAACL_5 L3 Ethernet124 DATAACL_5 ingress {'asic0': 'Active', 'asic2': 'Active'}"
80-
assert result_top == expected_output
82+
assert result.output == MASIC_SHOW_ACL_OUTPUT
8183

8284
def test_show_acl_rule(self, setup_teardown_multi_asic):
8385
runner = CliRunner()

0 commit comments

Comments
 (0)