Skip to content

Commit f5efe89

Browse files
authored
[acl] Use a list instead of a comma-separated string for ACL port list (sonic-net#1519)
Signed-off-by: Danny Allen <daall@microsoft.com>
1 parent e296a69 commit f5efe89

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

config/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3339,15 +3339,15 @@ def parse_acl_table_info(table_name, table_type, description, ports, stage):
33393339
if ports:
33403340
for port in ports.split(","):
33413341
port_list += expand_vlan_ports(port)
3342-
port_list = set(port_list)
3342+
port_list = list(set(port_list)) # convert to set first to remove duplicate ifaces
33433343
else:
33443344
port_list = valid_acl_ports
33453345

33463346
for port in port_list:
33473347
if port not in valid_acl_ports:
33483348
raise ValueError("Cannot bind ACL to specified port {}".format(port))
33493349

3350-
table_info["ports@"] = ",".join(port_list)
3350+
table_info["ports"] = port_list
33513351

33523352
table_info["stage"] = stage
33533353

tests/acl_config_test.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def test_parse_table_with_vlan_expansion(self):
2525
assert table_info["type"] == "L3"
2626
assert table_info["policy_desc"] == "TEST"
2727
assert table_info["stage"] == "egress"
28-
29-
port_list = table_info["ports@"].split(",")
30-
assert set(port_list) == {"Ethernet4", "Ethernet8", "Ethernet12", "Ethernet16"}
28+
assert set(table_info["ports"]) == {"Ethernet4", "Ethernet8", "Ethernet12", "Ethernet16"}
3129

3230
def test_parse_table_with_vlan_and_duplicates(self):
3331
table_info = parse_acl_table_info("TEST", "L3", None, "Ethernet4,Vlan1000", "egress")
@@ -36,9 +34,9 @@ def test_parse_table_with_vlan_and_duplicates(self):
3634
assert table_info["stage"] == "egress"
3735

3836
# Since Ethernet4 is a member of Vlan1000 we should not include it twice in the output
39-
port_list = table_info["ports@"].split(",")
40-
assert len(port_list) == 4
41-
assert set(port_list) == {"Ethernet4", "Ethernet8", "Ethernet12", "Ethernet16"}
37+
port_set = set(table_info["ports"])
38+
assert len(port_set) == 4
39+
assert set(port_set) == {"Ethernet4", "Ethernet8", "Ethernet12", "Ethernet16"}
4240

4341
def test_parse_table_with_empty_vlan(self):
4442
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)