Skip to content

Commit

Permalink
Update test_ro_disk.py (#12913)
Browse files Browse the repository at this point in the history
Fix ro disk test case generate garbled syslog and break loganalyzer issue.

#### Why I did it
Log rotate during ro disk may cause syslog file contains garbled characters.
These characters will break loganalyzer, to fix this issue, rotate again to cleanup syslog file.

#### How I did it
log rotate again after ro disk test case finish,

#### How to verify it
Pass all test case.

#### Description for the changelog
Fix ro disk test case generate garbled syslog and break loganalyzer issue.
  • Loading branch information
liuh-80 authored May 21, 2024
1 parent a121843 commit 86bf8c5
Showing 1 changed file with 16 additions and 8 deletions.
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)

0 comments on commit 86bf8c5

Please sign in to comment.