-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve show acl commands #2667
Merged
bingwang-ms
merged 7 commits into
sonic-net:master
from
bingwang-ms:improve_show_acl_commands
Mar 8, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9824529
Add status for ACL_TABLE and ACL_RULE in STATE_DB
bingwang-ms 5d14663
Fix key issue
bingwang-ms 363d359
Add UT
bingwang-ms 67a8950
Add empty line
bingwang-ms 989f1b6
Fix UT
bingwang-ms a213603
Fix UT
bingwang-ms ff954ab
Add empty line
bingwang-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space?