Skip to content

Commit

Permalink
Disable BGP when running test_neighbor_mac_noptf (sonic-net#3369)
Browse files Browse the repository at this point in the history
Disabled BGP during the execution of test_neighbor_mac_noptf to ensure the switch (swss) is not overloaded by BGP related route updates during the test as a result of the neighbor updates which may cause the test not to complete within the prescribed time of 2 seconds and thus fail.

Also, in the test, if it does not successfully register the update within two seconds, it automatically tears down the test possibly removing any evidence that the switch would have eventually processed the command once it completed all the route updates.

- How did you do it?
Edited the configuration test fixture method in the test to disable BGP on setup and enables it again on teardown. This is done similarly to other tests in sonic-mgmt.

Note: The 120 second delay seems to be necessary to allow all routes and neighbors to flush after BGP comes down.
  • Loading branch information
alexrallen authored and vmittal-msft committed Sep 28, 2021
1 parent fb3a4d9 commit b83308b
Showing 1 changed file with 28 additions and 3 deletions.
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

0 comments on commit b83308b

Please sign in to comment.