Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions tests/show_techsupport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ _user parameters:_

**logs_since** - number of minutes to pass to 'show techsupport' command.
If nothing specified, a random number of minutes will be raffled between 1 and 60.


### Test - test_techsupport_on_dpu (This case is running only on dpu, for other switch it will be skipped)

#### Test Objectives

- Generate dump file by " show techsupport -r --since 'xx xxx xxx' " ( select 1-5 minutes ago randomly)
- Validate that the dump file contains platform-dump.tar.gz archive
- Validate that platform-dump.tar.gz includes the following files:
sysfs_tree, sys_version, dmesg, dmidecode, lsmod, lspci, top, bin/platform-dump.sh
- Validate that the dump file contains sai_sdk_dump folder
- Validate that sai_sdk_dump is not empty folder
111 changes: 105 additions & 6 deletions tests/show_techsupport/test_techsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import time
import logging
import allure
import tech_support_cmds as cmds
from random import randint
from collections import defaultdict
Expand Down Expand Up @@ -49,6 +50,9 @@
'queue': "0"
}

DPU_PLATFORM_DUMP_FILES = ["sysfs_tree", "sys_version", "dmesg",
"dmidecode", "lsmod", "lspci", "top", "bin/platform-dump.sh"]


# ACL PART #

Expand Down Expand Up @@ -294,12 +298,7 @@ def test_techsupport(request, config, duthosts, enum_rand_one_per_hwsku_frontend
logger.debug("Loop_range is {} and loop_delay is {}".format(loop_range, loop_delay))

for i in range(loop_range):
logger.debug("Running show techsupport ... ")
wait_until(300, 20, 0, execute_command, duthost, str(since))
tar_file = [j for j in pytest.tar_stdout.split('\n') if j != ''][-1]
duthost.command("tar -xf {} -C /tmp/".format(tar_file))
extracted_dump_folder_name = tar_file.lstrip('/var/dump/').split('.')[0]
extracted_dump_folder_path = '/tmp/{}'.format(extracted_dump_folder_name)
tar_file, extracted_dump_folder_name, extracted_dump_folder_path = gen_dump_file(duthost, since)
try:
validate_dump_file_content(duthost, extracted_dump_folder_path)
except AssertionError as err:
Expand Down Expand Up @@ -511,3 +510,103 @@ def test_techsupport_commands(
)

pytest_assert(len(cmd_not_found) == 0, cmd_not_found)


def test_techsupport_on_dpu(duthosts, enum_rand_one_per_hwsku_frontend_hostname):
"""
This test is to check some files exist or not in the dump file generated by show techsupport on DPU
1. Generate dump file by " show techsupport -r --since 'xx xxx xxx' " ( select 1-5 minutes ago randomly)
2. Validate that the dump file contains platform-dump.tar.gz archive
3. Validate that platform-dump.tar.gz includes the following files:
sysfs_tree, sys_version, dmesg, dmidecode, lsmod, lspci, top, bin/platform-dump.sh
4. Validate that the dump file contains sai_sdk_dump folder
5. Validate that sai_sdk_dump is not empty folder
:param duthosts: DUT host
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts']
if config_facts['DEVICE_METADATA']['localhost'].get('switch_type', '') != 'dpu':
pytest.skip("Skip the test, as it is supported only on DPU.")

since = str(randint(1, 5)) + " minute ago"
platform_dump_name = "platform-dump.tar.gz"
sai_sdk_dump_folder_name = "sai_sdk_dump"
platform_dump_folder_name = "platform-dump"

tar_file, extracted_dump_folder_name, extracted_dump_folder_path = gen_dump_file(duthost, since)

try:
with allure.step('Validate that the dump file contains {} archive'.format(platform_dump_name)):
is_platform_dump_tar_gz_exist= duthost.shell("ls {}/{}/{}".format(
extracted_dump_folder_path, platform_dump_folder_name,platform_dump_name))["stdout_lines"]
assert is_platform_dump_tar_gz_exist, \
"{} doesn't exsit in {}".format(platform_dump_name, extracted_dump_folder_name)

with allure.step('validate that {} includes the expected files'.format(platform_dump_name)):
validate_platform_dump_files(duthost, extracted_dump_folder_path, platform_dump_folder_name,platform_dump_name)

with allure.step('Validate that the dump file contains sai_sdk_dump folder'):
is_existing_sai_sdk_dump_folder = duthost.shell(
"find {} -maxdepth 1 -type d -name {}".format(
extracted_dump_folder_path, sai_sdk_dump_folder_name))["stdout_lines"]
assert is_existing_sai_sdk_dump_folder, \
"Folder {} doesn't exist in dump archive".format(sai_sdk_dump_folder_name)

with allure.step('Validate sai_sdk_dump is not empty folder'):
sai_sdk_dump = duthost.shell("ls {}/sai_sdk_dump/".format(extracted_dump_folder_path))["stdout_lines"]
assert len(sai_sdk_dump), \
"Folder {} in dump archive is empty. Expected not an empty folder".format(sai_sdk_dump_folder_name)
except AssertionError as err:
raise AssertionError(err)
finally:
duthost.command("rm -rf {}".format(tar_file))
duthost.command("rm -rf {}".format(extracted_dump_folder_path))


def validate_platform_dump_files(duthost, dump_folder_path, platform_dump_folder_name, platform_dump_name):
"""
Validate platform-dump.tar.gz includes the following files:
sysfs_tree, sys_version, dmesg, dmidecode, lsmod, lspci, top, bin/platform-dump.sh
:param duthost: duthost object
:param dump_folder_path: path to folder which has extracted dump file content
:return: AssertionError in case of failure, else None
"""
platform_dump_path = '{}/{}/'.format(dump_folder_path, platform_dump_folder_name)

logger.info("extract {}".format(platform_dump_name))
duthost.shell("tar -xf {}{} -C {} ".format(platform_dump_path, platform_dump_name, platform_dump_path))

platform_dump_files_list = []
print_last_column = "awk '{print $NF}'"
cmd_list_file_name = "ls -l {folder_path} | grep '^{file_type}' | {print_last_column}"
platform_dump_folders = duthost.shell(cmd_list_file_name.format(
folder_path=platform_dump_path, file_type='d', print_last_column=print_last_column))["stdout_lines"]

def collect_platform_dump_files(folder_name):
temp_dump_folder_path = os.path.join(platform_dump_path, folder_name) if folder_name else platform_dump_path
platform_dump_files = duthost.shell(cmd_list_file_name.format(
folder_path=temp_dump_folder_path, file_type='-', print_last_column=print_last_column))["stdout_lines"]
for file in platform_dump_files:
dump_file_name = file.strip() if not folder_name else "{}/{}".format(folder_name, file.strip())
platform_dump_files_list.append(dump_file_name)

logger.info("Collect dump file name for {}".format(platform_dump_path))
collect_platform_dump_files('')

for folder_name in platform_dump_folders:
logger.info("Collect dump file name for {}/{}".format(platform_dump_path, folder_name))
collect_platform_dump_files(folder_name.strip())

for dump_file in DPU_PLATFORM_DUMP_FILES:
assert dump_file in platform_dump_files_list, "dump file {} doesn't exist in {}".format(
dump_file, platform_dump_files_list)


def gen_dump_file(duthost, since):
logger.debug("Running show techsupport ... ")
wait_until(300, 20, 0, execute_command, duthost, str(since))
tar_file = [j for j in pytest.tar_stdout.split('\n') if j != ''][-1]
duthost.command("tar -xf {} -C /tmp/".format(tar_file))
extracted_dump_folder_name = tar_file.lstrip('/var/dump/').split('.')[0]
extracted_dump_folder_path = '/tmp/{}'.format(extracted_dump_folder_name)
return tar_file, extracted_dump_folder_name, extracted_dump_folder_path