-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case to verify ebtables rules. (#2944)
- Added testcase to verify ebtable rules. To verify changes done as part of sonic-net/sonic-buildimage#6542 - Added to T0 kvmtest.sh - Will enhance for multi-asic in another PR. Signed-off-by: Abhishek Dosi <[email protected]>
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
from tests.common.helpers.assertions import pytest_assert | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
pytestmark = [ | ||
pytest.mark.disable_loganalyzer, # disable automatic loganalyzer globally | ||
pytest.mark.topology('any') | ||
] | ||
|
||
def generate_expected_rules(duthost): | ||
ebtables_rules = [] | ||
# Default policies | ||
ebtables_rules.append("-d BGA -j DROP") | ||
ebtables_rules.append("-p ARP -j DROP") | ||
ebtables_rules.append("-p 802_1Q --vlan-encap ARP -j DROP") | ||
return ebtables_rules | ||
|
||
|
||
def test_ebtables_application(duthosts, rand_one_dut_hostname): | ||
""" | ||
Test case to ensure ebtables rules are applied are corectly on DUT during init | ||
This is done by generating our own set of expected ebtables | ||
rules based on the DuT's configuration and comparing them against the | ||
actual ebtables rules on the DuT. | ||
""" | ||
duthost = duthosts[rand_one_dut_hostname] | ||
expected_ebtables_rules = generate_expected_rules(duthost) | ||
|
||
stdout = duthost.shell("sudo ebtables -L FORWARD")["stdout"] | ||
ebtables_rules = stdout.strip().split("\n") | ||
actual_ebtables_rules = [rule.strip().replace("0806","ARP") for rule in ebtables_rules if rule.startswith('-')] | ||
|
||
# Ensure all expected ebtables rules are present on the DuT | ||
missing_ebtables_rules = set(expected_ebtables_rules) - set(actual_ebtables_rules) | ||
pytest_assert(len(missing_ebtables_rules) == 0, "Missing expected ebtables rules: {}".format(repr(missing_ebtables_rules))) | ||
|
||
# Ensure there are no unexpected ebtables rules present on the DuT | ||
unexpected_ebtables_rules = set(actual_ebtables_rules) - set(expected_ebtables_rules) | ||
pytest_assert(len(unexpected_ebtables_rules) == 0, "Unexpected ebtables rules: {}".format(repr(unexpected_ebtables_rules))) |
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