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

Fix ro disk test case generate garbled syslog and break loganalyzer issue. #12913

Merged
merged 1 commit into from
May 21, 2024
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
24 changes: 16 additions & 8 deletions tests/tacacs/test_ro_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ def fetch_into_file(localhost, remote_ip, rwuser, rwpass, src_file, dst_file):
logger.info("ret={} cmd={}".format(ret, scp_cmd))


def log_rotate(duthost):
try:
duthost.shell("logrotate --force /etc/logrotate.d/rsyslog")
except RunAnsibleModuleFail as e:
if "logrotate does not support parallel execution on the same set of logfiles" in e.message:
# command will failed when log already in rotating
logger.warning("logrotate command failed: {}".format(e))
else:
raise e


def test_ro_disk(localhost, ptfhost, duthosts, enum_rand_one_per_hwsku_hostname,
tacacs_creds, check_tacacs):
"""test tacacs rw user
Expand Down Expand Up @@ -180,14 +191,7 @@ def test_ro_disk(localhost, ptfhost, duthosts, enum_rand_one_per_hwsku_hostname,
duthost.copy(src=conf_path, dest="/etc/rsyslog.d/000-ro_disk.conf")

# To get file in decent size. Force a rotate
try:
duthost.shell("logrotate --force /etc/logrotate.d/rsyslog")
except RunAnsibleModuleFail as e:
if "logrotate does not support parallel execution on the same set of logfiles" in e.message:
# command will failed when log already in rotating
logger.warning("logrotate command failed: {}".format(e))
else:
raise e
log_rotate(duthost)

res = duthost.shell("systemctl restart rsyslog")
assert res["rc"] == 0, "failed to restart rsyslog"
Expand Down Expand Up @@ -239,3 +243,7 @@ def test_ro_disk(localhost, ptfhost, duthosts, enum_rand_one_per_hwsku_hostname,
do_reboot(duthost, localhost, duthosts)
logger.debug(" END: reboot {} to restore disk RW state".
format(enum_rand_one_per_hwsku_hostname))

# log rotate during ro disk may cause syslog file contains garbled content
# garbled content will break loganalyzer, rotate again to cleanup syslog file.
log_rotate(duthost)
Loading