Skip to content

Commit

Permalink
[advance-reboot] Support log_analyzer support on small disk devices (s…
Browse files Browse the repository at this point in the history
…onic-net#5126)

Presently, test_advanced_reboot cases fail on small disk device since preboot logs are not retained and log_analyzer
fails to get start strings from the logs.
Fix this issue so that test_advanced_reboot cases can be executed on small disk devices.
How did you do it?
Steps:
1. Create a back of warm/fast-reboot script.
2. Before reboot - modify script and add step to copy logs from /var/log to /host before kexec.
3. After reboot - collect the backup logs from /host/ and restore the warm/fast-reboot script.
Tested on a physical testbed with small HD. Timing data for reboot analysis can be collected now.
  • Loading branch information
vaibhavhd authored Feb 12, 2022
1 parent e1667ef commit 7039ce0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/platform_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates")
FMT = "%b %d %H:%M:%S.%f"
FMT_SHORT = "%b %d %H:%M:%S"
SMALL_DISK_SKUS = [
"Arista-7060CX-32S-C32",
"Arista-7060CX-32S-Q32"
]


def _parse_timestamp(timestamp):
try:
Expand Down Expand Up @@ -330,6 +335,23 @@ def verify_mac_jumping(test_name, timing_data):
pytest.fail("Mac expiry detected during the window when FDB ageing was disabled")


def overwrite_script_to_backup_logs(duthost, reboot_type):
# find the fast/warm-reboot script path
reboot_script_path = duthost.shell('which {}'.format("{}-reboot".format(reboot_type)))['stdout']
# backup original script
duthost.shell("cp {} {}".format(reboot_script_path, reboot_script_path + ".orig"))
# find the anchor string inside fast/warm-reboot script
rebooting_log_line = "debug.*Rebooting with.*to.*"
# Create a backup log command to be inserted right after the anchor string defined above
backup_log_cmds ="cp /var/log/syslog /host/syslog.99;" +\
"cp /var/log/swss/sairedis.rec /host/sairedis.rec.99;" +\
"cp /var/log/swss/swss.rec /host/swss.rec.99;" +\
"cp /var/log/frr/bgpd.log /host/bgpd.log.99"
# Do find-and-replace on fast/warm-reboot script to insert the backup_log_cmds string
insert_backup_command = "sed -i '/{}/a {}' {}".format(rebooting_log_line, backup_log_cmds, reboot_script_path)
duthost.shell(insert_backup_command)


@pytest.fixture()
def advanceboot_loganalyzer(duthosts, rand_one_dut_hostname, request):
"""
Expand All @@ -356,6 +378,14 @@ def advanceboot_loganalyzer(duthosts, rand_one_dut_hostname, request):
if 'vs' not in device_marks:
pytest.skip('Testcase not supported for kvm')

hwsku = duthost.facts["hwsku"]
if hwsku in SMALL_DISK_SKUS:
# For small disk devices, /var/log in mounted in tmpfs.
# Hence, after reboot the preboot logs are lost.
# For log_analyzer to work, it needs logs from the shutdown path
# Below method inserts a step in reboot script to back up logs to /host/
overwrite_script_to_backup_logs(duthost, reboot_type)

loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix="test_advanced_reboot_{}".format(test_name),
additional_files={'/var/log/swss/sairedis.rec': 'recording on: /var/log/swss/sairedis.rec', '/var/log/frr/bgpd.log': ''})

Expand All @@ -375,6 +405,17 @@ def pre_reboot_analysis():
return marker

def post_reboot_analysis(marker, reboot_oper=None, log_dir=None):
if hwsku in SMALL_DISK_SKUS:
restore_backup = "mv /host/syslog.99 /var/log/; " +\
"mv /host/sairedis.rec.99 /var/log/swss/; " +\
"mv /host/swss.rec.99 /var/log/swss/; " +\
"mv /host/bgpd.log.99 /var/log/frr/"
# find the fast/warm-reboot script path
reboot_script_path = duthost.shell('which {}'.format("{}-reboot".format(reboot_type)))['stdout']
# restore original script
duthost.shell("mv {} {}".format(reboot_script_path + ".orig", reboot_script_path))
duthost.shell(restore_backup, module_ignore_errors=True)

result = loganalyzer.analyze(marker, fail=False)
analyze_result = {"time_span": dict(), "offset_from_kexec": dict()}
offset_from_kexec = dict()
Expand Down

0 comments on commit 7039ce0

Please sign in to comment.