Skip to content
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

Disable BGP when running test_neighbor_mac_noptf #3369

Merged
merged 4 commits into from
May 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions tests/arp/test_neighbor_mac_noptf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
import time

from tests.common.utilities import wait_until
from tests.common.helpers.assertions import pytest_assert
from tests.common.config_reload import config_reload

Expand All @@ -10,7 +11,11 @@
pytestmark = [
pytest.mark.topology('any')
]

REDIS_NEIGH_ENTRY_MAC_ATTR ="SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS"
ROUTE_TABLE_NAME = 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY'
DEFAULT_ROUTE_NUM = 2

class TestNeighborMacNoPtf:
"""
Test handling of neighbor MAC in SONiC switch
Expand All @@ -23,12 +28,28 @@ class TestNeighborMacNoPtf:
TEST_INTF = {
4: {"intfIp": "29.0.0.1/24", "NeighborIp": "29.0.0.2"},
6: {"intfIp": "fe00::1/64", "NeighborIp": "fe00::2"},
}
}

def count_routes(self, host, prefix):
# Counts routes in ASIC_DB with a given prefix
num = host.shell(
'sonic-db-cli ASIC_DB eval "return #redis.call(\'keys\', \'{}:{{\\"dest\\":\\"{}*\')" 0'.format(ROUTE_TABLE_NAME, prefix),
module_ignore_errors=True, verbose=True)['stdout']
return int(num)

def _check_no_bgp_routes(self, duthost):
# Checks that there are no routes installed by BGP in ASIC_DB by filtering out all local routes installed on testbeds
localv6 = self.count_routes(duthost, "fc") + self.count_routes(duthost, "fe")
localv4 = self.count_routes(duthost, "10.") + self.count_routes(duthost, "192.168.0.")
allroutes = self.count_routes(duthost, "")
bgproutes = allroutes - localv6 - localv4 - DEFAULT_ROUTE_NUM

return bgproutes == 0

@pytest.fixture(scope="module", autouse=True)
def restoreDutConfig(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
def setupDutConfig(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
"""
Restores DUT configuration after test completes
Disabled BGP to reduce load on switch and restores DUT configuration after test completes
Args:
duthost (AnsibleHost): Device Under Test (DUT)
Expand All @@ -37,6 +58,10 @@ def restoreDutConfig(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
None
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
duthost.command("sudo config bgp shutdown all")
if not wait_until(120, 2.0, self._check_no_bgp_routes, duthost):
pytest.fail('BGP Shutdown Timeout: BGP route removal exceeded 120 seconds.')

yield

logger.info("Reload Config DB")
Expand Down