Skip to content

Commit

Permalink
[test_fdb_mac_move] Only output error level message into syslog if /v…
Browse files Browse the repository at this point in the history
…ar/log size limitation (sonic-net#12467)

What is the motivation for this PR?
Exception: start-LogAnalyzer-test_fdb_mac_move.2024-02-25-07:03:31 was not found in /var/log
Sometimes, the case failed because the log analyzer cannot locate the log.
The log analyzer records the timestamp at the beginning of the case and analyzes the syslogs to check any error message generated during the case process.
However, some devices with a small disk, have a limitation for the /var/log size.
So during the log rotation, the previous syslog would be deleted, leading to the log analyzer failed to locate the log and return error.

How did you do it?
In this case, the swss logs consume a large space of /var/log. However, the output messages are expected and necessary for debugging in production. and log flooding is typically not a common occurrence in production.
To fix this issue during the case, we need to modify the swss logs's location, but it needs image change.
Therefore the fix introduced in this PR's is a workaround, it check the /var/log available size before test, if no enough space, modify the rsyslog config to only output error messages during the case.

How did you verify/test it?
Run the case.
  • Loading branch information
lipxu authored and mssonicbld committed Jun 15, 2024
1 parent fb543a3 commit 3f0db4f
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion tests/fdb/test_fdb_mac_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,50 @@
]


def modify_rsyslog_severity_level(dut):
logger.info('Modify rsyslog severity level to error on dut: {}'.format(dut.hostname))
dut.shell("sudo mv /etc/rsyslog.d /etc/rsyslog.d.bak")
dut.shell("sudo mkdir /etc/rsyslog.d")
dut.shell("sudo echo '*.err /var/log/syslog' > /etc/rsyslog.d/50_debug.conf")
dut.shell("sudo systemctl restart rsyslog")
time.sleep(5)


def revert_rsyslog_severity_level(dut):
logger.info('Revert rsyslog severity level to error on dut: {}'.format(dut.hostname))
dut.shell("sudo rm -rf /etc/rsyslog.d")
dut.shell("sudo mv /etc/rsyslog.d.bak /etc/rsyslog.d")
dut.shell("sudo systemctl restart rsyslog")
time.sleep(5)


@pytest.fixture(scope="function")
def fixture_rsyslog_conf_setup_teardown(duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]

# workaround for small disk devices which also has limitation on /var/log size
cmd = "df -m"
cmd_response_lines = duthost.shell(cmd, module_ignore_errors=True).get('stdout_lines', [])
logger.debug("cmd {} rsp {}".format(cmd, cmd_response_lines))

available_size = 0
for line in cmd_response_lines:
if "/var/log" in line:
available_size = int(line.split()[3])
break

if available_size < 400:
modify_rsyslog_severity_level(duthost)
rsyslog_severity_level_modified = True
else:
rsyslog_severity_level_modified = False

yield

if rsyslog_severity_level_modified:
revert_rsyslog_severity_level(duthost)


def get_fdb_dict(ptfadapter, vlan_table, dummay_mac_count):
"""
:param ptfadapter: PTF adapter object
Expand Down Expand Up @@ -56,7 +100,8 @@ def get_fdb_dict(ptfadapter, vlan_table, dummay_mac_count):
return fdb


def test_fdb_mac_move(ptfadapter, duthosts, rand_one_dut_hostname, ptfhost, get_function_conpleteness_level):
def test_fdb_mac_move(ptfadapter, duthosts, rand_one_dut_hostname, ptfhost, get_function_conpleteness_level,
fixture_rsyslog_conf_setup_teardown):
# Perform FDB clean up before each test
fdb_cleanup(duthosts, rand_one_dut_hostname)

Expand Down

0 comments on commit 3f0db4f

Please sign in to comment.