Skip to content

Commit

Permalink
Added test case to verify ebtables rules. (#2944)
Browse files Browse the repository at this point in the history
- 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
abdosi authored Feb 6, 2021
1 parent d22b971 commit 2221744
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/cacl/test_ebtables_application.py
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)))
1 change: 1 addition & 0 deletions tests/kvmtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ test_t0() {
bgp/test_bgp_fact.py \
bgp/test_bgp_gr_helper.py \
bgp/test_bgp_speaker.py \
cacl/test_ebtables_application.py \
cacl/test_cacl_application.py \
cacl/test_cacl_function.py \
dhcp_relay/test_dhcp_relay.py \
Expand Down

0 comments on commit 2221744

Please sign in to comment.