Skip to content

Commit

Permalink
Use common function to recover configuration after tests. (sonic-net#…
Browse files Browse the repository at this point in the history
…8915)

Description of PR
Some modules may add running config entries when running, which will cause inconsistent and unnecessary reload. We need to abstract a function to delete config.

What is the motivation for this PR?
Some modules may add running config entries when running, which will cause inconsistent and unnecessary reload. We need to abstract a function to delete config.

How did you do it?
Abstract a function to delete config.

How did you verify/test it?
By running testcases.

Signed-off-by: Yutong Zhang <yutongzhang@microsoft.com>
  • Loading branch information
yutongzhang-microsoft authored Jul 12, 2023
1 parent 23dfaa8 commit 3859d71
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 36 deletions.
3 changes: 0 additions & 3 deletions tests/bgp/templates/del_bgp_bbr_config.json

This file was deleted.

3 changes: 0 additions & 3 deletions tests/bgp/templates/del_warm_restart_config.json

This file was deleted.

6 changes: 3 additions & 3 deletions tests/bgp/test_bgp_bbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from tests.common.helpers.constants import DEFAULT_NAMESPACE
from tests.common.helpers.parallel import reset_ansible_local_tmp
from tests.common.helpers.parallel import parallel_run
from tests.common.utilities import wait_until
from tests.common.utilities import wait_until, delete_running_config


pytestmark = [
Expand Down Expand Up @@ -50,8 +50,8 @@ def prepare_bbr_config_files(duthosts, rand_one_dut_hostname):

yield

duthost.copy(src="./bgp/templates/del_bgp_bbr_config.json", dest='/tmp/del_bgp_bbr_config.json')
duthost.shell("configlet -d -j {}".format("/tmp/del_bgp_bbr_config.json"))
del_bbr_json = [{"BGP_BBR": {}}]
delete_running_config(del_bbr_json, duthost)


@pytest.fixture(scope='module')
Expand Down
7 changes: 3 additions & 4 deletions tests/bgp/test_bgp_slb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests.common.helpers.bgp import BGPNeighbor
from tests.common.dualtor.mux_simulator_control import mux_server_url # noqa F401
from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor # noqa F401
from tests.common.utilities import wait_until
from tests.common.utilities import wait_until, delete_running_config


pytestmark = [
Expand Down Expand Up @@ -84,6 +84,5 @@ def verify_bgp_session(duthost, bgp_neighbor):
pytest.fail("dynamic BGP session is not established after %s" % reboot_type)
finally:
neighbor.stop_session()
duthost.copy(src="bgp/templates/del_warm_restart_config.json", dest="/tmp/del_warm_restart_config.json")
duthost.shell("configlet -d -j {}".format("/tmp/del_warm_restart_config.json"))
duthost.shell("rm -f {}".format("/tmp/del_warm_restart_config.json"))
delete_slb_json = [{"WARM_RESTART": {}}]
delete_running_config(delete_slb_json, duthost)
2 changes: 1 addition & 1 deletion tests/common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,6 @@ def delete_running_config(config_entry, duthost, is_json=True):
if is_json:
duthost.copy(content=json.dumps(config_entry, indent=4), dest="/tmp/del_config_entry.json")
else:
duthost.copy(scr=config_entry, dest="/tmp/del_config_entry.json")
duthost.copy(src=config_entry, dest="/tmp/del_config_entry.json")
duthost.shell("configlet -d -j {}".format("/tmp/del_config_entry.json"))
duthost.shell("rm -f {}".format("/tmp/del_config_entry.json"))
6 changes: 0 additions & 6 deletions tests/show_techsupport/templates/del_keys.json

This file was deleted.

6 changes: 3 additions & 3 deletions tests/show_techsupport/test_techsupport_no_secret.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import logging
from tests.common.helpers.assertions import pytest_assert
from tests.common.utilities import skip_release
from tests.common.utilities import skip_release, delete_running_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -34,8 +34,8 @@ def setup_password(duthosts, enum_rand_one_per_hwsku_hostname, creds_all_duts):
duthost.shell("sudo config radius default passkey")

# Remove TACACS/Radius keys
duthost.copy(src="./show_techsupport/templates/del_keys.json", dest='/tmp/del_keys.json')
duthost.shell("configlet -d -j {}".format("/tmp/del_keys.json"))
delete_keys_json = [{"RADIUS": {}}, {"TACPLUS": {}}]
delete_running_config(delete_keys_json, duthost)


def check_no_result(duthost, command):
Expand Down
6 changes: 0 additions & 6 deletions tests/tacacs/templates/del_tacacs_config.json

This file was deleted.

6 changes: 3 additions & 3 deletions tests/tacacs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import binascii

from tests.common.errors import RunAnsibleModuleFail
from tests.common.utilities import wait_until, check_skip_release
from tests.common.utilities import wait_until, check_skip_release, delete_running_config
from tests.common.helpers.assertions import pytest_assert

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -124,8 +124,8 @@ def restore_tacacs_servers(duthost):
cmds.append("config tacacs timeout %s" % cfg)

# Cleanup AAA and TACPLUS config
duthost.copy(src="./tacacs/templates/del_tacacs_config.json", dest='/tmp/del_tacacs_config.json')
duthost.shell("configlet -d -j {}".format("/tmp/del_tacacs_config.json"))
delete_tacacs_json = [{"AAA": {}}, {"TACPLUS": {}}]
delete_running_config(delete_tacacs_json, duthost)

# Restore AAA and TACPLUS config
duthost.shell_cmds(cmds=cmds)
Expand Down
6 changes: 2 additions & 4 deletions tests/vlan/test_host_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from tests.common.dualtor.mux_simulator_control import mux_server_url # noqa F401
from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor # noqa F401
from tests.common.utilities import is_ipv4_address
from tests.common.utilities import wait_until
from tests.common.utilities import wait_until, delete_running_config
from tests.common.utilities import skip_release


Expand Down Expand Up @@ -107,9 +107,7 @@ def setup_host_vlan_intf_mac(duthosts, rand_one_dut_hostname, testbed_params, ve
}
}]
""" % (vlan_intf["attachto"], dut_vlan_mac))
duthost.copy(content=json.dumps(del_vlan_json, indent=4), dest='/tmp/del_vlan_mac.json')
duthost.shell("configlet -d -j {}".format("/tmp/del_vlan_mac.json"))
duthost.shell("rm -rf /tmp/del_vlan_mac.json")
delete_running_config(del_vlan_json, duthost)

wait_until(10, 2, 2, lambda: duthost.get_dut_iface_mac(vlan_intf["attachto"]) == dut_vlan_mac)

Expand Down

0 comments on commit 3859d71

Please sign in to comment.