From bb8059d9a89e142aae92cb378e08f78443edcbe4 Mon Sep 17 00:00:00 2001 From: xincunli-sonic Date: Tue, 9 Jan 2024 16:23:47 -0800 Subject: [PATCH 1/8] Add fsck check test case. --- tests/platform_tests/test_reboot.py | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index 13b0cf8c08..72607629af 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -277,3 +277,44 @@ def test_continuous_reboot(duthosts, enum_rand_one_per_hwsku_hostname, pytest_assert(ls_ending_out == ls_starting_out, "Console devices have changed: expected console devices: {}, got: {}" .format(", ".join(sorted(ls_starting_out)), ", ".join(sorted(ls_ending_out)))) + + +def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, + localhost, conn_graph_facts, xcvr_skip_list): # noqa F811 + """ + @summary: This test case is to perform check fsck will be repairing + the file system if it was in corruption state. + """ + duthost = duthosts[enum_rand_one_per_hwsku_hostname] + cmd = "sudo blkid --label SONiC-OS" + disk = duthost.command(cmd)["stdout"].replace('\x00', '') + logging.info("Checking '{}' file system state on '{}' by '{}'". + format(disk, duthost.hostname, cmd)) + + cmd = "sudo tune2fs -l {} | grep 'Filesystem state:'".format(disk) + state = duthost.shell(cmd, module_ignore_errors=True, + verbose=True)["stdout_lines"].split(":", 1)[1].strip() + + if "errors" not in state: + # Make the filesystem "dirty" (not clean) + duthost.shell("dd if={} of=superblock bs=1 count=2048".format(disk)) + duthost.shell("printf '\x02' | dd of=superblock bs=1 seek=1082 count=1 conv=notrunc &> /dev/null") + duthost.shell("dd of={} if=superblock bs=1 count=2048".format(disk)) + + state = duthost.shell(cmd, module_ignore_errors=True, + verbose=True)["stdout_lines"].split(":", 1)[1].strip() + + pytest_assert("errors" in state, + "Expecting the file system:{} changed to 'not clean with errors'" + .format(disk)) + + # Call reboot to run fsck for repair file system. + reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"][duthost.hostname], + xcvr_skip_list, reboot_type=REBOOT_TYPE_COLD, duthosts=duthosts) + + state = duthost.shell(cmd, module_ignore_errors=True, + verbose=True)["stdout_lines"].split(":", 1)[1].strip() + + pytest_assert("errors" not in state, + "Expecting the file system:{} has been repaired by fsck script." + .format(disk)) From 87da901a55ae7e91e4c95a8d80dbf2756bb0a5e8 Mon Sep 17 00:00:00 2001 From: xincunli-sonic Date: Thu, 21 Mar 2024 15:44:40 -0700 Subject: [PATCH 2/8] Change test case to checking syslog. --- tests/platform_tests/test_reboot.py | 31 ++++------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index 72607629af..b9a158b004 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -286,35 +286,12 @@ def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, the file system if it was in corruption state. """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] - cmd = "sudo blkid --label SONiC-OS" - disk = duthost.command(cmd)["stdout"].replace('\x00', '') - logging.info("Checking '{}' file system state on '{}' by '{}'". - format(disk, duthost.hostname, cmd)) - - cmd = "sudo tune2fs -l {} | grep 'Filesystem state:'".format(disk) - state = duthost.shell(cmd, module_ignore_errors=True, - verbose=True)["stdout_lines"].split(":", 1)[1].strip() - - if "errors" not in state: - # Make the filesystem "dirty" (not clean) - duthost.shell("dd if={} of=superblock bs=1 count=2048".format(disk)) - duthost.shell("printf '\x02' | dd of=superblock bs=1 seek=1082 count=1 conv=notrunc &> /dev/null") - duthost.shell("dd of={} if=superblock bs=1 count=2048".format(disk)) - - state = duthost.shell(cmd, module_ignore_errors=True, - verbose=True)["stdout_lines"].split(":", 1)[1].strip() - - pytest_assert("errors" in state, - "Expecting the file system:{} changed to 'not clean with errors'" - .format(disk)) # Call reboot to run fsck for repair file system. reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"][duthost.hostname], xcvr_skip_list, reboot_type=REBOOT_TYPE_COLD, duthosts=duthosts) - state = duthost.shell(cmd, module_ignore_errors=True, - verbose=True)["stdout_lines"].split(":", 1)[1].strip() - - pytest_assert("errors" not in state, - "Expecting the file system:{} has been repaired by fsck script." - .format(disk)) + # Check fsck ran by syslog entry. + cmd = "sudo find /var/log/syslog* -type f -mmin -5 -exec zgrep 'fsck' {} +" + result = duthost.shell(cmd, module_ignore_errors=True, verbose=True)['stdout'] + pytest_assert("fsck" in result, "The file system should be repaired by fsck script.") From a23dfd8fe49931c935349f4e655dae9334b0d30d Mon Sep 17 00:00:00 2001 From: Xincun Li <147451452+xincunli-sonic@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:32:23 -0700 Subject: [PATCH 3/8] Update test_reboot.py --- tests/platform_tests/test_reboot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index b9a158b004..33edaed43e 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -280,10 +280,10 @@ def test_continuous_reboot(duthosts, enum_rand_one_per_hwsku_hostname, def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, - localhost, conn_graph_facts, xcvr_skip_list): # noqa F811 + localhost, conn_graph_facts, xcvr_skip_list): """ - @summary: This test case is to perform check fsck will be repairing - the file system if it was in corruption state. + @summary: This test case is checking syslog to verify fsck script has run for checking and + repairing the file system when boot in initramfs stage. """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] From a334552e35091f5ef2ef2d08de50d9ac6154740e Mon Sep 17 00:00:00 2001 From: Xincun Li <147451452+xincunli-sonic@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:55:07 -0700 Subject: [PATCH 4/8] Update test_reboot.py --- tests/platform_tests/test_reboot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index 33edaed43e..de2ca36f0b 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -280,7 +280,7 @@ def test_continuous_reboot(duthosts, enum_rand_one_per_hwsku_hostname, def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, - localhost, conn_graph_facts, xcvr_skip_list): + localhost, conn_graph_facts, xcvr_skip_list): # noqa F811 """ @summary: This test case is checking syslog to verify fsck script has run for checking and repairing the file system when boot in initramfs stage. From e8dcf113c3ffb3cf0eead9a36adb7604114b9242 Mon Sep 17 00:00:00 2001 From: Xincun Li <147451452+xincunli-sonic@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:04:22 -0700 Subject: [PATCH 5/8] Update test_reboot.py --- tests/platform_tests/test_reboot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index de2ca36f0b..e38c910e98 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -282,8 +282,7 @@ def test_continuous_reboot(duthosts, enum_rand_one_per_hwsku_hostname, def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, localhost, conn_graph_facts, xcvr_skip_list): # noqa F811 """ - @summary: This test case is checking syslog to verify fsck script has run for checking and - repairing the file system when boot in initramfs stage. + @summary: This test case is checking syslog to verify fsck script has run for checking and repairing the file system when boot in initramfs stage. """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] @@ -295,3 +294,4 @@ def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, cmd = "sudo find /var/log/syslog* -type f -mmin -5 -exec zgrep 'fsck' {} +" result = duthost.shell(cmd, module_ignore_errors=True, verbose=True)['stdout'] pytest_assert("fsck" in result, "The file system should be repaired by fsck script.") + From 8aa90c7dc0dfa2a03c6b3f1082e510b61a3eba65 Mon Sep 17 00:00:00 2001 From: xincunli-sonic Date: Thu, 28 Mar 2024 17:32:39 -0700 Subject: [PATCH 6/8] fix format --- tests/platform_tests/test_reboot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index e38c910e98..decf44638c 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -294,4 +294,3 @@ def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, cmd = "sudo find /var/log/syslog* -type f -mmin -5 -exec zgrep 'fsck' {} +" result = duthost.shell(cmd, module_ignore_errors=True, verbose=True)['stdout'] pytest_assert("fsck" in result, "The file system should be repaired by fsck script.") - From 3b9dd14d35d83903a381a9f7c9646585b535fff2 Mon Sep 17 00:00:00 2001 From: xincunli-sonic Date: Thu, 28 Mar 2024 17:36:09 -0700 Subject: [PATCH 7/8] Fix E501 --- tests/platform_tests/test_reboot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index decf44638c..32964e9d02 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -282,7 +282,8 @@ def test_continuous_reboot(duthosts, enum_rand_one_per_hwsku_hostname, def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, localhost, conn_graph_facts, xcvr_skip_list): # noqa F811 """ - @summary: This test case is checking syslog to verify fsck script has run for checking and repairing the file system when boot in initramfs stage. + @summary: This test case is checking syslog to verify fsck script has run for + checking and repairing the file system when boot in initramfs stage. """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] From 361a7a8d5806eb77a52e567604c55db2b18bd631 Mon Sep 17 00:00:00 2001 From: Xincun Li <147451452+xincunli-sonic@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:52:33 -0700 Subject: [PATCH 8/8] Update test_reboot.py --- tests/platform_tests/test_reboot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index 32964e9d02..6fbb2c5f9f 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -292,6 +292,6 @@ def test_fsck_after_reboot(duthosts, enum_rand_one_per_hwsku_hostname, xcvr_skip_list, reboot_type=REBOOT_TYPE_COLD, duthosts=duthosts) # Check fsck ran by syslog entry. - cmd = "sudo find /var/log/syslog* -type f -mmin -5 -exec zgrep 'fsck' {} +" + cmd = "sudo journalctl --since '5 minutes ago' | grep 'fsck'" result = duthost.shell(cmd, module_ignore_errors=True, verbose=True)['stdout'] pytest_assert("fsck" in result, "The file system should be repaired by fsck script.")