-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add status for ACL_TABLE and ACL_RULE in STATE_DB (#2749)
What I did This PR is to backport changes in PR #2667 into 202211 branch. HLD sonic-net/SONiC#1261 This PR is to enhance show acl table and show acl rule commands. Currently, show acl table and show acl rule commands read ACL table/rule configuration from CONFIG_DB directly. We don't know whether the ACL table or rule is created successfully. We improved swss to write the status of ACL table/rule into a STATE_DB table. In this PR, the show command is enhanced to read the status from STATE_DB table. How I did it Introduce two tables in STATE_DB orchgent writes the status to STATE_DB show commands read the status from STATE_DB. How to verify it Verified by copying the new script to a testbed, and check the output. Previous command output (if the output of a command-line utility has changed) $ show acl table DATAACL Name Type Binding Description Stage ------- ------ ----------- ------------- ------- DATAACL L3 Ethernet0 DATAACL ingress Ethernet4 Ethernet8 Ethernet12 show acl rule Table Rule Priority Action Match ------- ------------ ---------- -------- ------------------- DATAACL RULE_1 9999 DROP DST_IP: 9.5.9.3/32 ETHER_TYPE: 2048 DATAACL RULE_2 9998 FORWARD DST_IP: 10.2.1.2/32 ETHER_TYPE: 2048 IP_PROTOCOL: 6 L4_DST_PORT: 22 New command output (if the output of a command-line utility has changed) $ show acl table DATAACL Name Type Binding Description Stage Status ------- ------ ----------- ------------- ------- ------- DATAACL L3 Ethernet0 DATAACL ingress Active Ethernet4 Ethernet8 Ethernet12 show acl rule Table Rule Priority Action Match Status ------- ------------ ---------- -------- ------------------- -------- DATAACL RULE_1 9999 DROP DST_IP: 9.5.9.3/32 Active ETHER_TYPE: 2048 DATAACL RULE_2 9998 FORWARD DST_IP: 10.2.1.2/32 Active ETHER_TYPE: 2048 IP_PROTOCOL: 6 L4_DST_PORT: 22
- Loading branch information
1 parent
b03d0b9
commit 721e26f
Showing
9 changed files
with
213 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import os | ||
import pytest | ||
from click.testing import CliRunner | ||
|
||
import acl_loader.main as acl_loader_show | ||
from acl_loader import * | ||
from acl_loader.main import * | ||
from importlib import reload | ||
|
||
root_path = os.path.dirname(os.path.abspath(__file__)) | ||
modules_path = os.path.dirname(root_path) | ||
scripts_path = os.path.join(modules_path, "scripts") | ||
|
||
|
||
@pytest.fixture() | ||
def setup_teardown_single_asic(): | ||
os.environ["PATH"] += os.pathsep + scripts_path | ||
os.environ["UTILITIES_UNIT_TESTING"] = "2" | ||
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" | ||
yield | ||
os.environ["UTILITIES_UNIT_TESTING"] = "0" | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def setup_teardown_multi_asic(): | ||
os.environ["PATH"] += os.pathsep + scripts_path | ||
os.environ["UTILITIES_UNIT_TESTING"] = "2" | ||
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic" | ||
from .mock_tables import mock_multi_asic_3_asics | ||
reload(mock_multi_asic_3_asics) | ||
from .mock_tables import dbconnector | ||
dbconnector.load_namespace_config() | ||
yield | ||
os.environ["UTILITIES_UNIT_TESTING"] = "0" | ||
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" | ||
from .mock_tables import mock_single_asic | ||
reload(mock_single_asic) | ||
|
||
|
||
class TestShowACLSingleASIC(object): | ||
def test_show_acl_table(self, setup_teardown_single_asic): | ||
runner = CliRunner() | ||
aclloader = AclLoader() | ||
context = { | ||
"acl_loader": aclloader | ||
} | ||
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['table'], ['DATAACL_5'], obj=context) | ||
assert result.exit_code == 0 | ||
# We only care about the third line, which contains the 'Active' | ||
result_top = result.output.split('\n')[2] | ||
expected_output = "DATAACL_5 L3 Ethernet124 DATAACL_5 ingress Active" | ||
assert result_top == expected_output | ||
|
||
def test_show_acl_rule(self, setup_teardown_single_asic): | ||
runner = CliRunner() | ||
aclloader = AclLoader() | ||
context = { | ||
"acl_loader": aclloader | ||
} | ||
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['rule'], ['DATAACL_5'], obj=context) | ||
assert result.exit_code == 0 | ||
# We only care about the third line, which contains the 'Active' | ||
result_top = result.output.split('\n')[2] | ||
expected_output = "DATAACL_5 RULE_1 9999 FORWARD IP_PROTOCOL: 126 Active" | ||
assert result_top == expected_output | ||
|
||
|
||
class TestShowACLMultiASIC(object): | ||
def test_show_acl_table(self, setup_teardown_multi_asic): | ||
runner = CliRunner() | ||
aclloader = AclLoader() | ||
context = { | ||
"acl_loader": aclloader | ||
} | ||
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['table'], ['DATAACL_5'], obj=context) | ||
assert result.exit_code == 0 | ||
# We only care about the third line, which contains the 'Active' | ||
result_top = result.output.split('\n')[2] | ||
expected_output = "DATAACL_5 L3 Ethernet124 DATAACL_5 ingress {'asic0': 'Active', 'asic2': 'Active'}" | ||
assert result_top == expected_output | ||
|
||
def test_show_acl_rule(self, setup_teardown_multi_asic): | ||
runner = CliRunner() | ||
aclloader = AclLoader() | ||
context = { | ||
"acl_loader": aclloader | ||
} | ||
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['rule'], ['DATAACL_5'], obj=context) | ||
assert result.exit_code == 0 | ||
# We only care about the third line, which contains the 'Active' | ||
result_top = result.output.split('\n')[2] | ||
expected_output = "DATAACL_5 RULE_1 9999 FORWARD IP_PROTOCOL: 126 {'asic0': 'Active', 'asic2': 'Active'}" | ||
assert result_top == expected_output | ||
|
||
|