diff --git a/tests/common/fixtures/duthost_utils.py b/tests/common/fixtures/duthost_utils.py index 683d57c78cb..0546ade5328 100644 --- a/tests/common/fixtures/duthost_utils.py +++ b/tests/common/fixtures/duthost_utils.py @@ -1,5 +1,6 @@ import pytest import logging +from jinja2 import Template logger = logging.getLogger(__name__) @@ -72,3 +73,41 @@ def disable_route_checker_module(duthosts, rand_one_dut_hostname): duthost = duthosts[rand_one_dut_hostname] for func in _disable_route_checker(duthost): yield func + +@pytest.fixture(scope='module') +def disable_fdb_aging(duthost): + """ + Disable fdb aging by swssconfig. + The original config will be recovered after running test. + """ + switch_config = """[ + { + "SWITCH_TABLE:switch": { + "ecmp_hash_seed": "0", + "lag_hash_seed": "0", + "fdb_aging_time": "{{ aging_time }}" + }, + "OP": "SET" + } + ]""" + TMP_SWITCH_CONFIG_FILE = "/tmp/switch_config.json" + DST_SWITCH_CONFIG_FILE = "/switch_config.json" + switch_config_template = Template(switch_config) + duthost.copy(content=switch_config_template.render(aging_time=0), + dest=TMP_SWITCH_CONFIG_FILE) + # Generate and load config with swssconfig + cmds = [ + "docker cp {} swss:{}".format(TMP_SWITCH_CONFIG_FILE, DST_SWITCH_CONFIG_FILE), + "docker exec -i swss swssconfig {}".format(DST_SWITCH_CONFIG_FILE) + ] + duthost.shell_cmds(cmds=cmds) + + yield + # Recover default aging time + DEFAULT_SWITCH_CONFIG_FILE = "/etc/swss/config.d/switch.json" + cmds = [ + "docker exec -i swss rm {}".format(DST_SWITCH_CONFIG_FILE), + "docker exec -i swss swssconfig {}".format(DEFAULT_SWITCH_CONFIG_FILE) + ] + duthost.shell_cmds(cmds=cmds) + duthost.file(path=TMP_SWITCH_CONFIG_FILE, state="absent") diff --git a/tests/fdb/test_fdb.py b/tests/fdb/test_fdb.py index 1c69c176615..ebf15836d7a 100644 --- a/tests/fdb/test_fdb.py +++ b/tests/fdb/test_fdb.py @@ -9,9 +9,11 @@ from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] from tests.common.fixtures.ptfhost_utils import remove_ip_addresses # lgtm[py/unused-import] +from tests.common.fixtures.duthost_utils import disable_fdb_aging pytestmark = [ - pytest.mark.topology('t0') + pytest.mark.topology('t0'), + pytest.mark.usefixtures('disable_fdb_aging') ] DEFAULT_FDB_ETHERNET_TYPE = 0x1234 @@ -51,7 +53,7 @@ def send_arp_request(ptfadapter, source_port, source_mac, dest_mac): :return: """ pkt = testutils.simple_arp_packet(pktlen=60, - eth_dst='ff:ff:ff:ff:ff:ff', + eth_dst=dest_mac, eth_src=source_mac, vlan_vid=0, vlan_pcp=0, @@ -146,7 +148,8 @@ def setup_fdb(ptfadapter, vlan_table, router_mac, pkt_type): fdb[member].update(dummy_macs) time.sleep(FDB_POPULATE_SLEEP_TIMEOUT) - + # Flush dataplane + ptfadapter.dataplane.flush() return fdb