Skip to content

Commit

Permalink
[acl] Use a list instead of a comma-separated string for ACL port list (
Browse files Browse the repository at this point in the history
sonic-net#1519)

Signed-off-by: Danny Allen <[email protected]>
  • Loading branch information
daall authored Apr 20, 2021
1 parent e296a69 commit f5efe89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3339,15 +3339,15 @@ def parse_acl_table_info(table_name, table_type, description, ports, stage):
if ports:
for port in ports.split(","):
port_list += expand_vlan_ports(port)
port_list = set(port_list)
port_list = list(set(port_list)) # convert to set first to remove duplicate ifaces
else:
port_list = valid_acl_ports

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

table_info["ports@"] = ",".join(port_list)
table_info["ports"] = port_list

table_info["stage"] = stage

Expand Down
10 changes: 4 additions & 6 deletions tests/acl_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def test_parse_table_with_vlan_expansion(self):
assert table_info["type"] == "L3"
assert table_info["policy_desc"] == "TEST"
assert table_info["stage"] == "egress"

port_list = table_info["ports@"].split(",")
assert set(port_list) == {"Ethernet4", "Ethernet8", "Ethernet12", "Ethernet16"}
assert set(table_info["ports"]) == {"Ethernet4", "Ethernet8", "Ethernet12", "Ethernet16"}

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

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

def test_parse_table_with_empty_vlan(self):
with pytest.raises(ValueError):
Expand Down

0 comments on commit f5efe89

Please sign in to comment.