Skip to content

Commit

Permalink
Remove golden config file and revert config when load golden config f…
Browse files Browse the repository at this point in the history
…ailed. (sonic-net#16373)

Remove golden config file and revert config when load golden config failed.

Why I did it
Fix bug sonic-net#16338
TACACS test case reload golden config failed, and golden config not remove because a code bug, then all test case failed after that because login failed.

How I did it
add try finally to make sure golden config always remove after reload config.

How to verify it
Pass all test case.

Description for the changelog
Remove golden config file and revert config when load golden config failed.
  • Loading branch information
liuh-80 authored Jan 7, 2025
1 parent cb3ca11 commit 5932b47
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
8 changes: 5 additions & 3 deletions tests/common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,9 +1320,11 @@ def reload_minigraph_with_golden_config(duthost, json_data, safe_reload=True):
from tests.common.config_reload import config_reload
golden_config = "/etc/sonic/golden_config_db.json"
duthost.copy(content=json.dumps(json_data, indent=4), dest=golden_config)
config_reload(duthost, config_source="minigraph", safe_reload=safe_reload, override_config=True)
# Cleanup golden config because some other test or device recover may reload config with golden config
duthost.command('mv {} {}_backup'.format(golden_config, golden_config))
try:
config_reload(duthost, config_source="minigraph", safe_reload=safe_reload, override_config=True)
finally:
# Cleanup golden config because some other test or device recover may reload config with golden config
duthost.command('mv {} {}_backup'.format(golden_config, golden_config))


def file_exists_on_dut(duthost, filename):
Expand Down
23 changes: 12 additions & 11 deletions tests/tacacs/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,17 +650,18 @@ def test_fallback_to_local_authorization_with_config_reload(
tacacs_server_ip: {"priority": "60", "tcp_port": "59", "timeout": "2"}
}
}
reload_minigraph_with_golden_config(duthost, override_config)

# Shutdown tacacs server to simulate network unreachable because BGP shutdown
stop_tacacs_server(ptfhost)
try:
reload_minigraph_with_golden_config(duthost, override_config)

# Test "sudo config save -y" can success after reload minigraph
exit_code, stdout, stderr = ssh_run_command(remote_rw_user_client, "sudo config save -y")
pytest_assert(exit_code == 0)
# Shutdown tacacs server to simulate network unreachable because BGP shutdown
stop_tacacs_server(ptfhost)

# Cleanup UT.
start_tacacs_server(ptfhost)
# Test "sudo config save -y" can success after reload minigraph
exit_code, stdout, stderr = ssh_run_command(remote_rw_user_client, "sudo config save -y")
pytest_assert(exit_code == 0)

# Restore config after test finish
restore_config(duthost, CONFIG_DB, CONFIG_DB_BACKUP)
# Cleanup UT.
start_tacacs_server(ptfhost)
finally:
# Restore config after test finish
restore_config(duthost, CONFIG_DB, CONFIG_DB_BACKUP)

0 comments on commit 5932b47

Please sign in to comment.